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

Q&A's, tips, howto's
Locked
ekd123
Posts: 13
Joined: Sat Mar 16, 2013 5:15 pm

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

Post 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

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Post by cormullion »

No. For bigger numbers, see https://en.wikibooks.org/wiki/Introduct ... er_numbers.

Don't know about &rest.

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

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

Post 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))
(λx. x x) (λx. x x)

ekd123
Posts: 13
Joined: Sat Mar 16, 2013 5:15 pm

Another question

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

bairui
Posts: 64
Joined: Sun May 06, 2012 2:04 am
Location: China
Contact:

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

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

ekd123
Posts: 13
Joined: Sat Mar 16, 2013 5:15 pm

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

Post by ekd123 »

Thank you very much. Now I'm ready to do something in realworld =)

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Post 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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

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

Post 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!
(λx. x x) (λx. x x)

ekd123
Posts: 13
Joined: Sat Mar 16, 2013 5:15 pm

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

Post by ekd123 »

WOW GR8! Thank you very much XD

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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

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

Post 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? :)
(λx. x x) (λx. x x)

ekd123
Posts: 13
Joined: Sat Mar 16, 2013 5:15 pm

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

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

Locked