Page 1 of 1
					
				redirecting functions
				Posted: Wed Sep 19, 2007 2:22 pm
				by cormullion
				Ahoy there!
What's the best way to do this:
Code: Select all
(define (task)
   (action))
(if (= x 3)
  (set 'action '(sin x))
  (set 'action '(pow x 5)))
(set 'x 4)
(task)
Ie you want the 'action' function to do different things when it's called.
 
			 
			
					
				
				Posted: Wed Sep 19, 2007 3:04 pm
				by Jeff
				Code: Select all
(if (= x 3) 
  (set 'action '(sin x)) 
  (set 'action '(pow x 5)))
(eval (expand action 'x))
 
			 
			
					
				
				Posted: Fri Sep 21, 2007 5:36 pm
				by cormullion
				Thanks Jeff. Eventually I decided to do it using "fn". 
Code: Select all
 (set 'do-content (fn (f) (single-entry-by-id (CGI:get {entry-id}))
this doesn't evaluate till I want to call it. There's probably a better way, but this works for now... :-)
 
			 
			
					
				
				Posted: Sat Sep 22, 2007 1:26 am
				by jrh
				God, what a mongrelized bastard newLISP is!  (this is a good thing.)
With C library support and sockets, a TCL/TK interface, and now Java graphics it's the language of The Day of the Triffids.   Watch out, you will be assimilated!
			 
			
					
				
				Posted: Sat Sep 22, 2007 10:32 am
				by cormullion
				jrh wrote:God, what a mongrelized bastard newLISP is!  (this is a good thing.)
With C library support and sockets, a TCL/TK interface, and now Java graphics it's the language of The Day of the Triffids.   Watch out, you will be assimilated!
That's one way of putting it! :-) Or you could say that newLISP is a good citiizen and a considerate neighbor. Not so dramatic, though..!
 
			 
			
					
				
				Posted: Sat Sep 22, 2007 1:26 pm
				by Jeff
				You could do it without the eval if you want it to not evaluate yet:
Code: Select all
(if (= x 3) 
  (set 'action '(sin x)) 
  (set 'action '(pow x 5))) 
(setq to-be-evaled-later (expand action 'x))