Hi all,
Thanks John , Mike -- I feel safer now, consequently I will make a lot of trouble next time when there
The classic variadics :
(define (foo)
(doargs (i) (print i " ")))
(foo 1 2 3) -> 1 2 3
(define (foo L)
(dolist (i L) (print i " ")))
(foo (list 1 2 3)) -> 1 2 3
(map print (list 1 2 3)) -> 123 (no spaces, to fix this an anonymous function is needed)
(map (lambda(x) (print x " ")) (list 1 2 3)) -> 1 2 3
the glorious currying function !!!
(map (curry print " ") (list 1 2 3)) -> 1 2 3
the manual says : curry ::: Returns a function which will call FUNCTION passing it INITIAL-ARGS and then any other args. (funcall (curry #'list 1) 2) ==> (list 1 2) .. iirc Mr Curry was a math professor (not sure) .. in math language (curry f(x,y,...)) = fx(y,....)
Doing sequential things variadic
(apply + (list 1 2 3)) -> 6
works of course for own written definitions :
like in :
(define (prime? x)
(= 1 (length (factor x))))
(map prime? (list 1 2 3)) -> (nil true true)
so: setting up a boolean hash table for some primes :
(define prime-hash-index (map prime? (sequence 1 100000))) -- that's all
But all this magic is orthogonal on anything a processor understands and for this reason (mainly , there are some technical reasons making (for me) interpreted Lisp more interesting than compiled), the combinations with a compiler like O2,C whatever can be super additive .
As an example something I was curious about -- an extended Fibonacci -
While Fib considered the mapping (a b) -> (a a+b) , I expanded it to (a b) -> (a f(a,b))
In the program you can see one of the powertools (eval-script ... ) ; the math part is nothing (lines on NextFib) )
I should have written it variadic , but it will take less than a minute to convert to program for complex Fib numbers, or even Fib numbers of any dimension.
(ps the stories like that the Steel Bank Common Lisp compiler for common Lisp and the mysterious STALIN compiler for Scheme outperform C is imho wishful thinking -- use and a compiler and an interpreter , that's real power !! )
best Rob
oops , forgot : the mapping ->(b (a+b)/n) for n > 0
n < 2 ::-> inf
n=2 ::-> 2/3
n>2 ::->0
n=1 the classic Fib numbers
.