Page 1 of 1
(apply case) doesn't work as expected
Posted: Sat Sep 08, 2007 7:03 am
by kinghajj
These two pieces of code should be equivalent, correct? But they are not. (apply case ...) doesn't work.
Code: Select all
(apply case '(1 (1 2)))
(case 1 (1 2))
Posted: Sat Sep 08, 2007 7:20 am
by kinghajj
I wrote a simple macro that will work like apply, but works correctly with case.
Code: Select all
(define-macro (myapply func arglist)
(eval (cons func (eval arglist))))
Re: (apply case) doesn't work as expected
Posted: Sat Sep 08, 2007 9:34 am
by cormullion
case wants at least two arguments:
(case exp-switch (exp-1 body-1) [ (exp-2 body-2) ... ] )
but you're giving it just a single entity, a quoted list. It's got the switch, but nothing to match and evaluate.
When you want to use apply with a function that wants more than one argument, you can use curry, but I don't know whether that's useful here...
I might be wrong, though... :-)
Posted: Sat Sep 08, 2007 10:26 am
by cormullion
I might be wrong - the manual has this:
apply should only be used on functions and operators that evaluate all of their arguments, not on special forms like setq or case, which evaluate only some of their arguments. Doing so will cause the function to fail.
So perhaps my previous suggestion was wrong... :-(