define-macro problems

Notices and updates
Locked
ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

define-macro problems

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

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

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

Fanda
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post 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

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

Post by ale870 »

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

Thank you!

Locked