Else: not allowed as an expression in: else

else is syntax used by cond and case is a syntax object that's defined as something that raises a syntax error when it's used outside of the context of a macro that uses it as a literal value. Identifiers in an expression being matched by the syntax-case pattern matcher are compared to literal ids with free-identifer=?, so have to be defined outside the macro. This means you can actually rename them and it automatically adjusts:

(require (only-in racket/base [else otherwise]))
(case 1
  ((2) 'a)
  (otherwise 'b))

Kawa defines else like so:

(define-syntax else
  (syntax-rules ()
    ((_ . rest)
     (syntax-error "invalid use of 'else"))))

Using it in a way that matches the pattern is a syntax error, but using it by itself like in your example just evaluates to a macro object:

#|kawa:1|# else
#<macro else>

Racket on the other hand defines it directly as a syntax transformer without wrapping it in syntax-rules:

(define-syntaxes (else)
    (lambda (stx)
      (raise-syntax-error #f "not allowed as an expression" stx)))

and anywhere it's used raises an error. If it was defined the same was as in Kawa, you'd get a different syntax error when it appears by itself.

2 Likes