all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* question to `case'
@ 2005-03-23 12:39 Klaus Berndl
  2005-03-23 13:07 ` Barry Margolin
  0 siblings, 1 reply; 2+ messages in thread
From: Klaus Berndl @ 2005-03-23 12:39 UTC (permalink / raw)



Can i use variables for the keys of the KEY-CLAUSES?

Example:

This is a case with two keys 1 and 2 which works very well:

,----
| (case (tree-node->type node)
|   (1
|    (nth 2 (tree-node->data node)))
|   (2
|    (ignore-errors (semantic-tag-class (tree-node->data node))))
|   (otherwise nil))
`----


My question: I would prefer to define some constants, so e.g.

,----
| (defconst my-bucket-node-type 1)
| (defconst my-tag-node-type 2)
`----

And then i want to use these two constants as keys in this case
instead of this hard-coded numbers 1 and 2, so for example something
like:

,----
| (case (tree-node->type node)
|   (my-bucket-node-type
|    (nth 2 (tree-node->data node)))
|   (my-tag-node-type
|    (ignore-errors (semantic-tag-class (tree-node->data node))))
|   (otherwise nil))
`----

whereas my-bucket-node-type and my-tag-node-type should be evaluated to
the const values...

Of course the notation above can not work but my question is: What is right
notation?

Thanks a lot in advance!
Klaus

-- 
Klaus Berndl			mailto: klaus.berndl@sdm.de
sd&m AG				http://www.sdm.de
software design & management	
Carl-Wery-Str. 42, 81739 Muenchen, Germany
Tel +49 89 63812-392, Fax -220

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: question to `case'
  2005-03-23 12:39 question to `case' Klaus Berndl
@ 2005-03-23 13:07 ` Barry Margolin
  0 siblings, 0 replies; 2+ messages in thread
From: Barry Margolin @ 2005-03-23 13:07 UTC (permalink / raw)


In article <upsxqiliv.fsf@sdm.de>, Klaus Berndl <klaus.berndl@sdm.de> 
wrote:

> Can i use variables for the keys of the KEY-CLAUSES?

No.  The keys are actually a list of constants.  If it were evaluated, a 
list would be treated as a function call.

> Of course the notation above can not work but my question is: What is right
> notation?

Use 'cond' instead:

(let ((type (tree-node->type node)))
  (cond (eq type my-bucket-node-type) ...)
        (eq type my-tag-node-type) ...)))

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-03-23 13:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-23 12:39 question to `case' Klaus Berndl
2005-03-23 13:07 ` Barry Margolin

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.