From: Stefan Voss
Subject: Re: having trouble evaluating function, help!
Date: 
Message-ID: <1g7fjnINNg0c@iraul1.ira.uka.de>
In article <·············@persimmon>, ···@persimmon.ucsb.edu (David E. Goggin) writes:
|> I am trying to write something like this.
|> 
|> (defun wow (var test) (cond ((eval test) t) (t nil) )  )
|> 
|> Where test is a expression like (= var 3)
|> 
|> so you would do something like
|> 
|> (wow 3 `(< var 2))
|> returns nil
|> 
|> (wow 3 `(= var 3))
|> returns t
|> (defun wow (var test)
|> But I can`t seem to make it work right.  I get errors like
|> "error in EVAL: test has no value"
|> 
|> Does this make sense?
|> 
|> *dt*

Hi David,

I suppose you want to have the body of a function with parameters as an argument.
You should use funcall and a lambda construct.

(defun wow (var test)
  (eval `(if (funcall #'(lambda (var) ,test) ,var) t)))


Stefan Voss
(····@ira.uka.de)

From: Michael Greenwald
Subject: Re: having trouble evaluating function, help!
Date: 
Message-ID: <michaelg.724005528@Xenon.Stanford.EDU>
····@i40s19.ira.uka.de (Stefan Voss) writes:

>In article <·············@persimmon>, ···@persimmon.ucsb.edu (David E. Goggin) writes:
>|> I am trying to write something like this.
>|> 
>|> (defun wow (var test) (cond ((eval test) t) (t nil) )  )
>|> 
>|> Where test is a expression like (= var 3)
>|> 
>|> so you would do something like
>|> 
>|> (wow 3 `(< var 2))
>|> returns nil
>|> 
>|> (wow 3 `(= var 3))
>|> returns t

>I suppose you want to have the body of a function with parameters as an argument.
>You should use funcall and a lambda construct.

>(defun wow (var test)
>  (eval `(if (funcall #'(lambda (var) ,test) ,var) t)))

Perhaps I'm confused as to what the first poster >really< wants, but
isn't he simply asking to evaluate a function with a single bound
parameter?  Why do you need EVAL at all -- why can't the caller of WOW
be modified to call funcall instead?

i.e. (funcall #'(lambda (var) (= var 3)) 3)
or   (funcall #'(lambda (var) (< var 2)) 3)

Or is this supposed to be an interactive evaluator, typed at by a user?  
If VAR is supposed to represent a constant symbol name, then isn't

(DEFUN WOW (VAR-VALUE TEST)
 (LET ((VAR VAR-VALUE))
   (DECLARE (SPECIAL VAR))
   (NOT (NULL (EVAL TEST)))))

clearer and simpler than backquoting a funcall of a #'lambda?  I
included the (NOT (NULL ...)) even though I'm not sure why the
original poster wanted to convert the result to strictly 'T or NIL.
I assume he knows what he needs.
From: Stefan Voss
Subject: Re: having trouble evaluating function, help!
Date: 
Message-ID: <1ga0a1INN4ue@iraul1.ira.uka.de>
In article <··················@Xenon.Stanford.EDU>, ········@Xenon.Stanford.EDU (Michael Greenwald) writes:
|> [some stuff deleted]
|> 
|> Perhaps I'm confused as to what the first poster >really< wants, but
|> isn't he simply asking to evaluate a function with a single bound
|> parameter?  Why do you need EVAL at all -- why can't the caller of WOW
|> be modified to call funcall instead?
|> 
|> i.e. (funcall #'(lambda (var) (= var 3)) 3)
|> or   (funcall #'(lambda (var) (< var 2)) 3)

This was my first thought,too, but compare your function invocation to
the original one (wow 3 `(= var 3)). I think, David's is more simple, although
not "lisp-like".

|> 
|> Or is this supposed to be an interactive evaluator, typed at by a user?  
|> If VAR is supposed to represent a constant symbol name, then isn't
|> 
|> (DEFUN WOW (VAR-VALUE TEST)
|>  (LET ((VAR VAR-VALUE))
|>    (DECLARE (SPECIAL VAR))
|>    (NOT (NULL (EVAL TEST)))))
|> 
|> clearer and simpler than backquoting a funcall of a #'lambda?  I
|> included the (NOT (NULL ...)) even though I'm not sure why the
|> original poster wanted to convert the result to strictly 'T or NIL.
|> I assume he knows what he needs.
|> 

Well, that's another way to do it. I must admit that I haven't worked with
(DECLARE (SPECIAL ...)) yet.

Stefan Voss
(····@ira.uka.de)