newLISP Fan Club

Forum => newLISP in the real world => Topic started by: ekd123 on March 26, 2013, 07:10:51 AM

Title: Does newLISP have &rest and big numbers...?
Post by: ekd123 on March 26, 2013, 07:10:51 AM
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
Title: Re: Does newLISP have &rest and big numbers...?
Post by: cormullion on March 26, 2013, 07:34:19 AM
No. For bigger numbers, see //https://en.wikibooks.org/wiki/Introduction_to_newLISP/Working_with_numbers#Bigger_numbers.



Don't know about &rest.
Title: Re: Does newLISP have &rest and big numbers...?
Post by: rickyboy on March 26, 2013, 11:15:20 AM
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))
Title: Another question
Post by: ekd123 on March 26, 2013, 09:59:42 PM
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)
Title: Re: Does newLISP have &rest and big numbers...?
Post by: bairui on March 27, 2013, 01:37:19 AM
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.
Title: Re: Does newLISP have &rest and big numbers...?
Post by: ekd123 on March 27, 2013, 06:49:13 AM
Thank you very much. Now I'm ready to do something in realworld =)
Title: Re: Does newLISP have &rest and big numbers...?
Post by: cormullion on March 27, 2013, 11:07:58 AM
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
Title: Re: Does newLISP have &rest and big numbers...?
Post by: rickyboy on March 27, 2013, 01:28:23 PM
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!
Title: Re: Does newLISP have &rest and big numbers...?
Post by: ekd123 on March 27, 2013, 09:52:05 PM
WOW GR8! Thank you very much XD



Well, but is there a way to mix them up?
Title: Re: Does newLISP have &rest and big numbers...?
Post by: rickyboy on March 28, 2013, 12:03:23 PM
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?  :)
Title: Re: Does newLISP have &rest and big numbers...?
Post by: ekd123 on March 30, 2013, 01:42:11 AM
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!