define-macro problems

Started by ale870, January 29, 2008, 03:54:31 AM

Previous topic - Next topic

ale870

Hello,



I created the following function, but it seems it doesn't work:


(setq clientParams
'(
(action "my action")
(selMenu "sel menu 1")
(param1 "my param 1")
(param2 "my param 2")
)
);clientParams

(define-macro (clientParams-get argKey)
(println (lookup argKey clientParams) )
);define


If I try it, I get:


> (clientParams-get 'action)
nil
nil
>


What's wrong? Why "lookup" cannot find the value?



Please help me, I'm creating my first application in NewLisp in the company where I work, and I need to give a good impression about this language!



Thank you!
--

Fanda

#1
Either leave it as a macro and run it:
> (clientParams-get action)
my action
"my action"


or change it to normal function and run it:
(define (clientParams-get argKey)
   (println (lookup argKey clientParams) )
);define

> (clientParams-get 'action)
my action
"my action"

Fanda

#2
Error when using macro is that argKey is 'action NOT action.


(define-macro (clientParams-get argKey)
   (println argKey)
   (println (lookup argKey clientParams) )
);define

> (clientParams-get 'action)
'action
nil
nil

ale870

#3
Great!

I made several tests, but maybe I "lost" that combination! :-)



Thank you!
--