Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

if statement - Is the "else" keyword, used as final case in a cond-expression, a special form in Scheme?

The cond-expression in Scheme is a special form, but is the else keyword, used as final case in a cond-expression, a special form? Or is it just a reserved keyword that is essentially equivalent to the truth-value #t ? In the latter case, why cannot I write something like (?eq else #t)?

question from:https://stackoverflow.com/questions/65831822/is-the-else-keyword-used-as-final-case-in-a-cond-expression-a-special-form-i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Scheme standards call else, as used in a cond form, auxiliary syntax. R6RS shows one possible implementation of cond using syntax-rules; here else is called a <literal>:

(define-syntax cond
  (syntax-rules (else =>)
    ((cond (else result1 result2 ...))
     (begin result1 result2 ...))
;; ...

Note that else is not a replacement for #t. A <literal> is an identifier that is used to match input subforms; it is treated as a syntactic keyword within the syntax-rules form.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...