Page 1 of 1

Does newLISP have &rest and big numbers...?

Posted: Tue Mar 26, 2013 2:10 pm
by ekd123
CL has a nice feature

Code: Select all

(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

Re: Does newLISP have &rest and big numbers...?

Posted: Tue Mar 26, 2013 2:34 pm
by cormullion
No. For bigger numbers, see https://en.wikibooks.org/wiki/Introduct ... er_numbers.

Don't know about &rest.

Re: Does newLISP have &rest and big numbers...?

Posted: Tue Mar 26, 2013 6:15 pm
by rickyboy
Rest arguments in newLISP (by example):

Code: Select all

> (define (f x y) (list x y (args)))

> (f 1 2 3 4 5 6)
(1 2 (3 4 5 6))

Another question

Posted: Wed Mar 27, 2013 4:59 am
by ekd123
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.

Code: Select all

;; 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)

Re: Does newLISP have &rest and big numbers...?

Posted: Wed Mar 27, 2013 8:37 am
by bairui
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.

Re: Does newLISP have &rest and big numbers...?

Posted: Wed Mar 27, 2013 1:49 pm
by ekd123
Thank you very much. Now I'm ready to do something in realworld =)

Re: Does newLISP have &rest and big numbers...?

Posted: Wed Mar 27, 2013 6:07 pm
by cormullion
Shamelessly stealing from the creator:

Code: Select all

(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

Re: Does newLISP have &rest and big numbers...?

Posted: Wed Mar 27, 2013 8:28 pm
by rickyboy
Cormullion's is a good approach. Here is another. I'm going to show it using ekd123's keylist definition. Just say

Code: Select all

(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."

Code: Select all

(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.

Code: Select all

> 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!

Re: Does newLISP have &rest and big numbers...?

Posted: Thu Mar 28, 2013 4:52 am
by ekd123
WOW GR8! Thank you very much XD

Well, but is there a way to mix them up?

Re: Does newLISP have &rest and big numbers...?

Posted: Thu Mar 28, 2013 7:03 pm
by rickyboy
How CL mixes these parameter types is discussed here by Seibel: http://www.gigamonkeys.com/book/functio ... eter-types.

I think it is possible to write a newLISP macro to mix the types. Want to try? :)

Re: Does newLISP have &rest and big numbers...?

Posted: Sat Mar 30, 2013 8:42 am
by ekd123
I tried use them together and just found it successful.

Code: Select all

(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!