Page 1 of 1

define-macro problems

Posted: Tue Jan 29, 2008 11:54 am
by ale870
Hello,

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

Code: Select all

(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:

Code: Select all

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

Posted: Tue Jan 29, 2008 11:59 am
by Fanda
Either leave it as a macro and run it:

Code: Select all

> (clientParams-get action) 
my action
"my action"
or change it to normal function and run it:

Code: Select all

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

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

Posted: Tue Jan 29, 2008 12:08 pm
by Fanda
Error when using macro is that argKey is 'action NOT action.

Code: Select all

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

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

Posted: Tue Jan 29, 2008 12:32 pm
by ale870
Great!
I made several tests, but maybe I "lost" that combination! :-)

Thank you!