Hi Paul,

Have you seen C-ENUM: in alien.syntax? This word is in alien.syntax
because we generally only use it when interfacing with C libraries. If
you just need symbolic constants (without requiring them to be
consecutive numbers), use SYMBOLS: or SINGLETONS:.

Slava

On Tue, Jan 20, 2009 at 3:30 PM, Paul Moore <[email protected]> wrote:
> 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
>

------------------------------------------------------------------------------
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

Reply via email to