Version française
Home     About     Download     Resources     Contact us    
Browse thread
camlp4 3.10 and ints
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] camlp4 3.10 and ints
On 6/13/07, Richard Jones <rich@annexia.org> wrote:
> I'm getting some odd errors with camlp4 (3.10) and integers.

Thanks to Jeremy Yallop for responding to this. I then just add a few bits...

>
> Firstly, INT returns a string, rather than an int, and similarly
> $int:...$ expects a string instead of an int.  I can live with this,
> but it seems a bit strange, and unless I'm mistaken is different from
> what camlp4 <= 3.09 did.

Not it's not different and the reason is simple. Camlp4 wants to keep
the representation of your integer and turning it to int will
normalize it ("42", "4_2", "0000042", "0b0101010"...).

With 3.10 you also have active antiquotations $`int:...$ $`int32:...$ for that.

Conversely on the parser side you can also get integers instead of
string by using real patterns in your production rule.

old_prod:
[[ s = INT -> (* s is a string *) ... ]];

new_prod:
[[ `INT(i, s) -> (* i is an integer and s its representation *) ... ]];

-- 
Nicolas Pouillard