mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-04-27 03:40:31 -07:00
The macroexpander for CASE also warns about an improper order of statements.
This commit is contained in:
parent
671aef6634
commit
b053cd80ec
2 changed files with 27 additions and 16 deletions
|
|
@ -12,6 +12,8 @@ ECL 12.2.2:
|
|||
- DIRECTORY no longer complains when it finds an inexistent directory
|
||||
component: it simply returns NIL as the list of pathnames.
|
||||
|
||||
- CASE now complains when the OTHERWISE/T clause is not the last one.
|
||||
|
||||
;;; Local Variables: ***
|
||||
;;; mode:text ***
|
||||
;;; fill-column:79 ***
|
||||
|
|
|
|||
|
|
@ -279,22 +279,31 @@ values of the last FORM. If no FORM is given, returns NIL."
|
|||
(defmacro sys::until (test &body body)
|
||||
(while-until test body 'unless))
|
||||
|
||||
(defmacro case (keyform &rest clauses &aux (form nil) (key (gensym)))
|
||||
(dolist (clause (reverse clauses)
|
||||
`(LET ((,key ,keyform))
|
||||
; (DECLARE (:READ-ONLY ,key)) ; Beppe
|
||||
,form))
|
||||
(if (or (eq (car clause) 'T) (eq (car clause) 'OTHERWISE))
|
||||
(setq form `(PROGN ,@(cdr clause)))
|
||||
(if (consp (car clause))
|
||||
(setq form `(IF (MEMBER ,key ',(car clause))
|
||||
(PROGN ,@(cdr clause))
|
||||
,form))
|
||||
(if (car clause)
|
||||
(setq form `(IF (EQL ,key ',(car clause))
|
||||
(PROGN ,@(cdr clause))
|
||||
,form))))))
|
||||
)
|
||||
(defmacro case (keyform &rest clauses)
|
||||
(let* ((last t)
|
||||
(form nil)
|
||||
(key (gensym)))
|
||||
(dolist (clause (reverse clauses)
|
||||
`(LET ((,key ,keyform))
|
||||
;;(DECLARE (:READ-ONLY ,key)) ; Beppe
|
||||
,form))
|
||||
(let ((selector (car clause)))
|
||||
(cond ((or (eq selector T) (eq selector 'OTHERWISE))
|
||||
(unless last
|
||||
(si::signal-simple-error
|
||||
'program-error nil
|
||||
"CASE: The selector ~A can only appear at the last position."
|
||||
(list selector)))
|
||||
(setq form `(PROGN ,@(cdr clause))))
|
||||
((consp selector)
|
||||
(setq form `(IF (MEMBER ,key ',selector)
|
||||
(PROGN ,@(cdr clause))
|
||||
,form)))
|
||||
(selector
|
||||
(setq form `(IF (EQL ,key ',selector)
|
||||
(PROGN ,@(cdr clause))
|
||||
,form))))
|
||||
(setq last nil)))))
|
||||
|
||||
(defmacro return (&optional (val nil)) `(RETURN-FROM NIL ,val))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue