redirecting functions

Started by cormullion, September 19, 2007, 07:22:17 AM

Previous topic - Next topic

cormullion

Ahoy there!



What's the best way to do this:



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

Jeff

#1
(if (= x 3)
  (set 'action '(sin x))
  (set 'action '(pow x 5)))

(eval (expand action 'x))
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

cormullion

#2
Thanks Jeff. Eventually I decided to do it using "fn".



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

jrh

#3
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!

cormullion

#4
Quote from: "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!


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

Jeff

#5
You could do it without the eval if you want it to not evaluate yet:


(if (= x 3)
  (set 'action '(sin x))
  (set 'action '(pow x 5)))

(setq to-be-evaled-later (expand action 'x))
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code