case の途中で (otherwise ...)

keys---a designator for a list of objects. In the case of case, the symbols t and otherwise may not be used as the keys designator. To refer to these symbols by themselves as keys, the designators (t) and (otherwise), respectively, must be used instead.

CLHS: Macro CASE, CCASE, ECASE

"may not be used" ってどうすりゃいいんだよ。エラー投げていいのん?と CL 処理系の挙動を調べてみたらバラバラだった・・・。

※処理系のバージョンが古いのは突っ込んであった LispCabinet に付属してたものだからです。

xyzzy デフォルト

無言でマッチする

(case 3
  (x 'x)
  (otherwise 'otherwize)
  (3 :three))
=> otherwize

xyzzy + ansify

無言でマッチしない

(require "ansify")
=> t
(ansify::case 3
  (x 'x)
  (otherwise 'otherwise)
  (3 :three))
=> :three

Clozure CL Version 1.6-r14468M

警告を出してマッチする

CL-USER> (case 3
           (x 'x)
           (otherwise 'otherwise)
           (3 :three))
; Warning: T or OTHERWISE clause in the middle of a CASE statement.  Subsequent clauses ignored.
; While executing: CCL::CASE-AUX, in process repl-thread(10).
OTHERWISE

SBCL 1.0.45

無言でマッチしない

CL-USER> (case 3
           (x 'x)
           (otherwise 'otherwise)
           (3 :three))
:THREE

CLISP 2.48

エラーで止まる

CL-USER> (case 3
           (x 'x)
           (otherwise 'otherwise)
           (3 :three))
---- debugger ----
CASE: the OTHERWISE clause must be the last one
   [Condition of type SYSTEM::SIMPLE-SOURCE-PROGRAM-ERROR]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*PROCESS-INPUT] Continue reading input.
 2: [ABORT] Return to SLIME's top level.
 3: [CLOSE-CONNECTION] Close SLIME connection.
 4: [ABORT] Abort main loop