3 ms·
>"The standard does not guarantee that this gives you an array of double-float: it may (if the implementation provides them), otherwise you get an array of elem
by flavio81 9y ago
>"The standard does not guarantee that this gives you an array of double-float: it may (if the implementation provides them), otherwise you get an array of element type T."
Well, many Common Lisp implementations, which includes most of the famous ones like SBCL, CCL, and ABCL, will give you exactly...
... an array of double-float!!
So where is the problem?
>"However, this gets worse: while you can tell a function that operates on arrays that these arrays have element type double-float, you cannot dispatch on this, as Common Lisp does not have parametric types."
Well, there are many options. First, let me reiterate that an array of a certain element type, stays of that element type. Example:
CL-USER> (defparameter *a* (make-array 0 :element-type 'double-float ))
*A*
CL-USER> (type-of *a*)
(SIMPLE-ARRAY DOUBLE-FLOAT (0))
I'm going to give the simplest, quick&dirty options:
If you're using arrays of different element-types, option A is write your function and just use the ETYPECASE function to do the dispatch according to the element type, so you can ensure that you select the code correct to the element type. Use the DECLARE declaration specifier so the Lisp compiler knows which type is your array /array elements and thus the machine language code produced is optimal.
Option B is simple, just define classes or structs, one for each array type you intend to use; and then take advantage of CLOS dispatch so invoking the generic function dispatches to the correct code for each array.
These are two options which don't even need any macro solutions; there are many more options as well, i'm just proposing two.
Option C, more elegant, could be perhaps using Fare's "LIL" (Lisp Interface Library)?
https://common-lisp.net/~frideau/lil-ilc2012/lil-ilc2012.html https://common-lisp.net/~frideau/lil-ilc2012/lil-ilc2012.htm...
I really think Julia is a nicely designed language, and is a language I often tell people to take a look at. However, if the author already has a program in Common Lisp, and has good experience of Common Lisp (which, by the way, means the author might be a quite skilled programmer), why not dig deeper into the facilities that Common Lisp brings to solve those problems?
NOTE: This is an edited version of the comment i left on the page.