[m-users.] alternate pairs syntax?

nll at dent.vctlabs.com nll at dent.vctlabs.com
Tue Nov 10 06:59:43 AEDT 2015


Hello all,

I have been examining the code for a demo for the lex program delivered 
with Mercury in the extras directory, i.e., 
mercury/mercury-srcdist-14.01/extras/lex/samples/lex_demo.m

I present a few lines from the program which I do not understand:

:- func lexemes = list(lexeme(token)).

lexemes = [

     ( "%" ++ junk       -> (func(Match) = comment(Match)) ),
     ( signed_int        -> (func(Match) = 
integer(string.det_to_int(Match))) ),
     ( real              -> (func(Match) = 
real(string.det_to_float(Match))) ),

         % Multiple regexps can match the same token constructor.
         %
     ( "cat"             -> (func(Match) = noun(Match)) ),
     ( "dog"             -> (func(Match) = noun(Match)) ),
     ( "rat"             -> (func(Match) = noun(Match)) ),
     ( "mat"             -> (func(Match) = noun(Match)) ),


The problem here is the usage of "->"

I cannot find in the documntation this operator used to express the pair 
constructor.  I expected to see some pairs defined in this context.  Is 
this another way to talk about pairs? or am I missing out on what is going 
on?

Any clarification would be appreciated.

Regards,

Nick



More information about the users mailing list