[chuck-users] FileIO.read( int ) -- why not implement?

Hans Aberg haberg at math.su.se
Mon Feb 8 15:24:26 EST 2010

I made a C++ manipulator syntax for use with a Bison/Flex parser. In  
ChucK pseudocode:
   parser p;
   value v;
   chin => p => v;
If the parse succeeds, one gets a value v, which can be polymorphic or  
static, depending how the parse defines it. Errors are checked by
   if (!chin => p => v)
     error ...
or by exceptions:
   try {
     chin => p => v
   catch ...

If one likes values to check errors, rather than states and  
exceptions, then Haskell has a type Maybe t, where t is a type, which  
have the value Nothing or Just t, a value t:
   chin => p => Maybe value m;
   if ( == Nothing)
     error ....
   just m => value v;

I like this manipulator syntax, because it is easy to remember. One  
might have a class for regular expressions:
   "..." => regex r:
   chin => r => string s;
and other standard classes for parsing values such as integers,  
floats, etc.

Also, I found the C++ way of setting various states to parse the input  
rather cumbersome, because often one wants to write a function that  
has its own context for parsing the input. With the state model, one  
then has to record the state and reste it when finished.

The manipulator syntax avoids that problem.


More information about the chuck-users mailing list