guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enumeration in GUILE


From: Thien-Thi Nguyen
Subject: Re: Enumeration in GUILE
Date: Thu, 09 Oct 2003 07:32:03 -0400

   From: address@hidden
   Date: Thu, 9 Oct 2003 12:55:45 +0530

   typedef enum { FIRST, SECOND, THIRD, NONE) CHOICE;

   Is it possible to get these enums recognized by GUILE.

   guile> (my-choice-is FIRST)

there are three approaches: variables, symbols and keywords.  for
variables, you need to choose a symbol for each element, bind an integer
value to it, and arrange for your functions to accept numeric integers.
for symbols, your functions should accept symbols and translate them to
integers internally.  similarly for keywords.

using variables is a step backward in some sense.  even though the
symbols and keywords approach is a little more work to put in place, it
makes debugging simpler on the scheme side; a backtrace w/ symbols is
less work to understand than a backtrace w/ integers.  (presuming your
stuff is not buggy at the C level -- if that's the case, you have to
take care of that first. :-)

thi




reply via email to

[Prev in Thread] Current Thread [Next in Thread]