Changeset trunk,24


Ignore:
Timestamp:
06/24/2007 01:48:00 AM (19 years ago)
Author:
dsowen
revision id:
svn-v3-trunk0:2948df59-2b31-0410-8e06-c40c0b09d5b6:trunk:24
Message:

Recognize symbols by name instead of identity.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/matching.lisp

    r21 r24  
    234234    (list
    235235     (destructuring-bind (head . tail) rule
    236        (case head
     236       (symcase head
    237237         (^ (destructuring-bind (regex) tail
    238238              `(if-matches-regex ,input ,regex (,next ,match) ,then ,else)))
  • trunk/util.lisp

    r21 r24  
    4040    ((not ,cond))
    4141    ,@body))
     42
     43(defmacro symcase (symvar &body clauses)
     44  (flet ((is-default (clause)
     45           (string= (symbol-name (first clause)) #.(symbol-name 't))))
     46    (let ((symname (gensym))
     47          (default-clause (find-if #'is-default clauses)))
     48      `(let ((,symname (symbol-name ,symvar)))
     49        (cond
     50          ,@(mapcar (lambda (clause)
     51                      (destructuring-bind (sym form) clause
     52                        `((string= ,symname ,(symbol-name sym)) ,form)))
     53                    (remove-if #'is-default clauses))
     54          ,@(when default-clause
     55                  (destructuring-bind (sym form) default-clause
     56                    `((,sym ,form)))))))))
Note: See TracChangeset for help on using the changeset viewer.