newLISP Fan Club

Forum => Anything else we might add? => Topic started by: cormullion on September 19, 2007, 07:22:17 AM

Title: redirecting functions
Post by: cormullion on September 19, 2007, 07:22:17 AM
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.
Title:
Post by: Jeff on September 19, 2007, 08:04:23 AM
(if (= x 3)
  (set 'action '(sin x))
  (set 'action '(pow x 5)))

(eval (expand action 'x))
Title:
Post by: cormullion on September 21, 2007, 10:36:48 AM
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... :-)
Title:
Post by: jrh on September 21, 2007, 06:26:38 PM
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!
Title:
Post by: cormullion on September 22, 2007, 03:32:57 AM
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..!
Title:
Post by: Jeff on September 22, 2007, 06:26:57 AM
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))