Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "else" a special symbol in scheme? Can it be defined as a procedure?

Tags:

lisp

scheme

I started learning Scheme recently by reading SICP. In the opening chapter, it goes over conditionals and it talks about using else within the cond "special form" - which to my understanding is defined as "something the interpreter "just knows about". My question, is why is else defined as a "special form" and not as a procedure?

If I fire up my mit-scheme interpreter, and type: (else 1) it raises an error. If I define something like (define (myelse x) x), I can use it in the same way it is used within the cond expression like:

(define (abs x)
    (cond ((< x 0) (- x))
        (myelse x)))

So why is else treated as something special, and not defined in scheme itself?

like image 632
6124j50n Avatar asked Feb 16 '23 20:02

6124j50n


1 Answers

If it were an ordinary variable, you could do:

(set! else #f)

and then all the cond expressions that depend on the else clause being executed would stop working.

like image 98
Barmar Avatar answered May 19 '23 19:05

Barmar