newLISP Fan Club

Forum => Anything else we might add? => Topic started by: ssqq on August 22, 2016, 07:12:05 AM

Title: case design
Post by: ssqq on August 22, 2016, 07:12:05 AM

(constant 'Type 1)

(define (check-type x)
  (case
    (Type (println "it is Type"))
    (true (println "it is not Type"))))

(check-name 1)

(exit)

==> it is not Type



For: case

syntax: (case exp-switch (exp-1 body-1) [(exp-2 body-2) ... ])



The result of evaluating exp-switch is compared to each of the[size=150] unevaluated [/size]expressions exp-1, exp-2,



I want to know Why make case expression with unevaluated?
Title: Re: case design
Post by: lyl on June 05, 2019, 01:42:55 AM
I meet this problem too, and has been waiting for answer!
Title: Re: case design
Post by: TedWalther on June 06, 2019, 09:21:31 AM
case doesn't evaluate the conditions.  So if you call check-type 1, it compares Type to 1, and of course they aren't the same.  If you called (check-type 'Type) it would work.  Or if you changed the condition to (case x (1 (println "the type is Type"))) it would work.



As for the "why"?  I don't know.  Perhaps it is because that is how it normally is in LISP.  Ancient tradition.



If you want the condition evaluated, you can use cond instead of case.