(apply case '(...))

For the Compleat Fan
Locked
Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

(apply case '(...))

Post by Dmi »

Code: Select all

(eval '(case 1 (1 "a"))) => "a"
(apply case '(1 (1 "a"))) => nil
What is the difference?
WBR, Dmi

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

You can use 'apply' only on normal functions evaluating their arguments. In 'case' the parenthesized terms are never evaluated but broken up by 'case' directly to access the innerts. In LISP lingo functions which do not evaluate their arguments are called special functions or special forms because they do not follow the normal evaluation rules.

It is the same as doing:

(apply dotimes '((x 10) (print x))) => fails
;or
(apply setq '(x 10)) => fails

Lutz

ps: I realize this should be mentioned in the documentation of 'apply'

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post by Dmi »

Thanks!
WBR, Dmi

Locked