Carlo <the...@carlocapocasa.com> writes: > Is there any way to use the 'case' special op with other comparisons > that 'eq', e.g. 'string='?
No. You need to write your own macro for that.
I suspect that there are actually many such implementations around. In any case, it isn't that hard to come up with your own macro:
(defmacro case* (item &rest clauses) (if (listp test) (destructuring-bind (object &key test) test (if test ...<build and return clauses here... `(case ,object ,@clauses))) `(case ,test ,@clauses)))
All that's left is to build the clauses. You can do that by introducing a GENSYM'd binding for the value of OBJECT and then construct the clauses appropriately using either the TEST argument directly or FIND/MEMBER with the appropriate :TEST argument.
-- Thomas A. Russ, USC/Information Sciences Institute
> All that's left is to build the clauses. You can do that by > introducing a GENSYM'd binding for the value of OBJECT and then > construct the clauses appropriately using either the TEST argument > directly or FIND/MEMBER with the appropriate :TEST argument.
A macro isn't needed.
Ruby:
x = 5 [ [2, 'two'], [4, 'four'], [6, 'six'] ].find{|a,b| a > x }.first ==>6
> > All that's left is to build the clauses. You can do that by > > introducing a GENSYM'd binding for the value of OBJECT and then > > construct the clauses appropriately using either the TEST argument > > directly or FIND/MEMBER with the appropriate :TEST argument.
> A macro isn't needed.
> Ruby:
> x = 5 > [ > [2, 'two'], > [4, 'four'], > [6, 'six'] > ].find{|a,b| a > x }.first > ==>6
x = 5 [ [2, 'two'], [4, 'four'], [6, 'six'] ].find{|a,b| a > x }.last ==>"six"