Search code examples
if-statementconditional-statementsschemespecial-form

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)?


Solution

  • 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.