I couldn't find any way in Factor to define an enumeration, as in C -
a series of symbolic names for consecutive numbers. I may well have
missed one, but after a bit of digging in the documentation, I decided
it was probably easy enough to define my own. So I did :-)
If this is of any use to anyone else, they are welcome to use it.
Basic usage is
ENUM: a b c ;
which is equivalent to
CONSTANT: a 0
CONSTANT: b 1
CONSTANT: c 2
---- enum.factor
USING: kernel parser words.constant
sequences lexer ;
IN: enum
: make-enum ( token val -- ) [ create-in ] dip define-constant ;
: define-enums ( seq -- ) [ make-enum ] each-index ;
: ENUM: ";" parse-tokens define-enums ; parsing
---- end
Paul.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk