I am writing a macro in which the argument list ends with one or more lists. In my macro I am trying to get the index at which the lists start so I can slice them out. So I write something like this
(define-macro (func)
(setq cnt (first (index list? (args))))
)
but when I do this NewLISP squawks. What am I doing wrong?
args-macro question
-
- Posts: 95
- Joined: Wed Oct 13, 2004 8:02 pm
- Location: Bellingham WA
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Looks like it works a bit...
Code: Select all
newLISP v.8.8.9 on OSX UTF-8, execute 'newlisp -h' for more info.
> (define-macro (func) (set 'cnt (first (index list? (args)))))
(lambda-macro () (set 'cnt (first (index list? (args)))))
> (func "1" (list (sequence 1 2 3)))
1
>
this works for me:
always returns the first list argument found. But you can make it shorter using 'filter':
or even shorter using implicit indexing:
Lutz
Code: Select all
> (define-macro (func) (nth (first (index list? (args))) (args)))
(lambda-macro () (nth (first (index list? (args))) (args)))
> (func 1 2 (a b c))
(a b c)
> (func 1 2 (a b c) 4 5)
(a b c)
>
Code: Select all
> (define-macro (func) (first (filter list? (args))))
(lambda-macro () (first (filter list? (args))))
> (func 1 2 (a b c) 4 5)
(a b c)
>
Code: Select all
> (define-macro (func) ((filter list? (args)) 0))
(lambda-macro () ((filter list? (args)) 0))
> (func 1 2 (a b c) 4 5)
(a b c)
>
Lutz
-
- Posts: 95
- Joined: Wed Oct 13, 2004 8:02 pm
- Location: Bellingham WA
-
- Posts: 95
- Joined: Wed Oct 13, 2004 8:02 pm
- Location: Bellingham WA