From: D. Goel
Subject: (funcall #'case ls) <-- how to do an equivalent...
Date: 
Message-ID: <ap3r8lb94wb.fsf@fosters.umd.edu>
i have a list  called ls which stores the latter half of a case
statement.  Thus, ls may look like
	'(
		((1 2 3) 2)
		(a 3)
		(otherwise 4))

i want to basically  (eval (cons 'case (cons elt ls))).

but guess one shouldn't use eval, 
and funcall won't work because case is a macro.


So, is there no way i can use the lisp's case macro on this list
without having to use eval?


To avoid eval, i am currently doing somethingn like

 (cadr
	(assoc-if
	 #'(lambda (arg)
		(or
		 (equal arg t)
		 (equal arg 'otherwise)
		 (equal elt arg)	
		 (and (listp arg) (member elt arg))))
	ls)


but seems like i am doing it the Wrong Way, and that there should be a
way to use case, that i a missing..


D				   <http://www.glue.umd.edu/~deego>
-- 
Signature?  Naah.  Just some recently visited websites:
http://www.whitehouse.org
http://www.wired.com/wired/archive/9.12/aspergers_pr.html

From: Barry Margolin
Subject: Re: (funcall #'case ls) <-- how to do an equivalent...
Date: 
Message-ID: <33Wv8.4$9z1.49@paloalto-snr1.gtei.net>
In article <···············@fosters.umd.edu>,
D. Goel  <·····@glue.umd.edu> wrote:
>To avoid eval, i am currently doing somethingn like
>
> (cadr
>	(assoc-if
>	 #'(lambda (arg)
>		(or
>		 (equal arg t)
>		 (equal arg 'otherwise)
>		 (equal elt arg)	
>		 (and (listp arg) (member elt arg))))
>	ls)
>
>
>but seems like i am doing it the Wrong Way, and that there should be a
>way to use case, that i a missing..

Other than using EVAL, I can't think of any way you could do this using
CASE.  The ASSOC family of functions is probably the closest ones analogous
to the CASE macro.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Kent M Pitman
Subject: Re: (funcall #'case ls) <-- how to do an equivalent...
Date: 
Message-ID: <sfwit6n4ndz.fsf@shell01.TheWorld.com>
D. Goel <·····@glue.umd.edu> writes:

> i have a list  called ls which stores the latter half of a case
> statement.  Thus, ls may look like
> 	'(
> 		((1 2 3) 2)
> 		(a 3)
> 		(otherwise 4))
> 
> i want to basically  (eval (cons 'case (cons elt ls))).
> 
> but guess one shouldn't use eval, 
> and funcall won't work because case is a macro.
>
> 
> So, is there no way i can use the lisp's case macro on this list
> without having to use eval?
> 
> 
> To avoid eval, i am currently doing somethingn like
> 
>  (cadr
> 	(assoc-if
> 	 #'(lambda (arg)
> 		(or
> 		 (equal arg t)
> 		 (equal arg 'otherwise)
> 		 (equal elt arg)	
> 		 (and (listp arg) (member elt arg))))
> 	ls)
> 
> 
> but seems like i am doing it the Wrong Way, and that there should be a
> way to use case, that i a missing..

Does the data list ever look like:

 (((1 2 3) (+ 2 2))
  (a x)
  (otherwise (sin x)))

and do you want the result to be eval'd?  If so, you're  not really avoiding
the use of EVAL.

If this is not an arbitrary Lisp code form, and you're able to avoid eval
anyway.

Furthermore, if it might look like

 (((1 2 3) 1 2)
  (a 3 4)
  (t 5 6))

then you can't use CADR to do the extraction.

If it _isn't_ able to be these things, then that suggests you are personally
in charge of the data structure.  In that case, you might want to
disallow one of otherwise of t or otherwise (for speed, to not have to do
extra tests) and you might want permit only a list rather than a symbol or
list (again for speed).

It is definitely not the case that CASE works by first doing an EQUAL
check and then using member.  CASE checks for a syntactic list _first_ 
and uses MEMBER; it uses EQL, not EQUAL, in the case that the case form
is not a list.  So your predicate is a bit messed upon this if you're trying
to emulate CL.
From: D. Goel
Subject: Re: (funcall #'case ls) <-- how to do an equivalent...
Date: 
Message-ID: <ap3n0vydxao.fsf@fosters.umd.edu>
Barry and Kent

thanks a lot for your responses.  they were both very educational for
me. 


> 
> It is definitely not the case that CASE works by first doing an EQUAL


yeah i am aware i was nowhere near implementing the true behavior of
'case'.. that's why i mentioned the 'something' below-->


> > To avoid eval, i am currently doing somethingn like


in fact, i used 'equal' rather than 'eql' on purpose, coz using
strings.. and am not actually using 'otherwise' in the actual
program..