(apply case) doesn't work as expected

Started by kinghajj, September 08, 2007, 12:03:52 AM

Previous topic - Next topic

kinghajj

These two pieces of code should be equivalent, correct? But they are not. (apply case ...) doesn't work.



(apply case '(1 (1 2)))

(case 1 (1 2))

kinghajj

#1
I wrote a simple macro that will work like apply, but works correctly with case.

(define-macro (myapply func arglist)
  (eval (cons func (eval arglist))))

cormullion

#2

(apply case '(1 (1 2)))


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

cormullion

#3
I might be wrong - the manual has this:


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