I experiment with keyword arguments. Like :key in common lisp.
(define-macro (keyfun _fn)
(eval (append '(let) (list _args) _fn)))
(define (add-two)
(let (_args (args))
(keyfun
(println (+ first-val second-val)))))
so:
newLISP v.8.7.0 on linux, execute 'newlisp -h' for more info.
> (add-two 'first-val 1 'second-val 2)
3
This makes possible constructs like:
(send-email
'from "me@here"
'to "you@there"
'body (format-message....))
(I reproduce some lisp example)
But can the syntax be more clear?
Something like:
(define (add-two)
(keyfun body))
or even:
(define-keyfun (fun-name) (fun-body))
I was quite stupit yesterday... it's simple!
(define-macro (keyfun)
(eval (append '(let) (list _args) (args))))
(define-macro (define-keyfun _fnh)
(set (_fnh 0)
(append '(lambda) (list (1 _fnh))
(list (append '(let (_args (args)))
(list (append '(keyfun) (args))))))))
(define-keyfun (test-val val)
(print "testing " val " against " against "...")
(println (unless (= val against) " not" "") " match"))
(test-val 1 'against 2)
; This solution doesn't hide the implementation details. Good or bad?
(define (test)
(let (x nil y nil)
(apply set (args))
(println "x = " x " y = " y)))
(test 'x 1 'y 2) ; => x = 1 y = 2
(test 'y 2 'x 1) ; => x = 1 y = 2
Fanda
Yes! It's that I really looking for :-)
Thanks.