case design

For the Compleat Fan

case design

Postby ssqq » Mon Aug 22, 2016 2:12 pm

Code: Select all
(constant 'Type 1)

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

(check-name 1)


==> 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 unevaluated expressions exp-1, exp-2,

I want to know Why make case expression with unevaluated?
Posts: 88
Joined: Sun May 04, 2014 12:49 pm

Re: case design

Postby lyl » Wed Jun 05, 2019 8:42 am

I meet this problem too, and has been waiting for answer!
Posts: 37
Joined: Sun Mar 25, 2018 5:00 am

Re: case design

Postby TedWalther » Thu Jun 06, 2019 4:21 pm

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.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.
Posts: 605
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC

Return to Anything else we might add?

Who is online

Users browsing this forum: No registered users and 1 guest