CL has a nice feature
(defun my-list (&rest list)
list)
(my-list 'a 'b 'c 'd) => (a b c d)
Has newlisp got &rest? I haven't found anything about that. :-(
Also, big numbers are also very useful. It's here or not?
Thanks.
-- ekd123
No. For bigger numbers, see //https://en.wikibooks.org/wiki/Introduction_to_newLISP/Working_with_numbers#Bigger_numbers.
Don't know about &rest.
Rest arguments in newLISP (by example):
> (define (f x y) (list x y (args)))
> (f 1 2 3 4 5 6)
(1 2 (3 4 5 6))
Thanks. They worked with some hacks for gmp.lsp. (GMP in Fedora 64bit is located /usr/lib64/libgmp.so.10)
Well, another question. Has newLISP got &key and &optional? They are useful features, too.
;; Common Lisp example
(defun keylist (a &key x y z)
(list a x y z))
(defun )
(keylist 1 :z 5 :y 3) => (1 NIL 3 5)
(defun optionallist (a &optional (x 5)) (list a x ))
(optionallist 6)
newlisp has optional arguments (no need to point them out with a special keyword).
As I understand it, newlisp doesn't explicitly support keyword arguments although you could achieve a similar effect using association lists or hashes.
Thank you very much. Now I'm ready to do something in realworld =)
Shamelessly stealing from the creator:
(define-macro (foo)
(local (len width height)
(bind (args) true)
(println "len:" len " width:" width " height:" height)
))
> (foo (width 20) (height 30) (len 10))
len:10 width:20 height:30
Cormullion's is a good approach. Here is another. I'm going to show it using ekd123's keylist definition. Just say
(define-with-keys (keylist a)
(list a x y z))
> (keylist 1 'z 5 'y 3)
(1 nil 3 5)
and you have the answer, but you have to use this "secret sauce."
(define-macro (define-with-keys name+params)
(letex ($keylet (cons 'let (cons '$keybinds (args)))
$name+params name+params)
(define $name+params
(letex ($keybinds (explode (args) 2))
$keylet))))
Let's look at the value of keylist to see what define-with-keys does.
> keylist
(lambda (a)
(letex ($keybinds (explode (args) 2))
(let $keybinds
(list a x y z))))
It assumes that (args) is keyword argument list. That may be too simple for your use ... or it may be "just right." :) Happy hacking!
WOW GR8! Thank you very much XD
Well, but is there a way to mix them up?
How CL mixes these parameter types is discussed here by Seibel: http://www.gigamonkeys.com/book/functions.html#mixing-different-parameter-types.
I think it is possible to write a newLISP macro to mix the types. Want to try? :)
I tried use them together and just found it successful.
(define-with-keys (together a (b nil)) (list a b c d))
(together 'a 'b 'c 1 'd 2) ; ==> (a b 1 2)
Just right!