[Nix-dev] isFloat

Christian Theune ct at flyingcircus.io
Tue Jan 5 15:55:52 CET 2016


Howdi,

beside “isFloat” I was also looking into making a builtin for “toInt” (and then also “toFloat”).

I remembered why I love Python, so after some twiddling I decided to base the conversion on std::stol.

However, this has different properties than the regular language.

I wonder: could I just call the parser on the string and ask it to use INT as the starting symbol?

Cheers,
Christian

> On 05 Jan 2016, at 10:34, Christian Theune <ct at flyingcircus.io> wrote:
> 
> Hi,
> 
> (I lost a mail. Hopefully this doesn’t end up in a double post).
> 
> I got it working and made a ticket to get into a more structured working mode. :)
> 
> nix-instantiate --eval -E '123.45 * 1E2'
> 12345
> 
> If anyone wants to follow up:
> https://github.com/NixOS/nix/issues/760
> 
> Happy to do whatever is necessary to wrap this up. :)
> 
> Cheers,
> Christian
> 
>> On 05 Jan 2016, at 00:48, Christian Theune <ct at flyingcircus.io> wrote:
>> 
>> Hi,
>> 
>> alright. I was really interested in trying to see whether I can figure out what’s going on.
>> 
>> I didn’t quite get it working today and my lack of Flex/Bison understanding is blocking me from figuring out what’s going on. :/
>> 
>> Most changes were done by reviewing everything that touched the integer handling and following all traces of all things it touched.
>> 
>> My current work is here:
>> https://github.com/NixOS/nix/compare/master...ctheune:ctheune-floats?expand=1
>> 
>> For some reason, the lexer seems to fail picking up the FLOAT symbol _at all_ and complains:
>> 
>> nix-instantiate --eval -E '123.1'
>> error: syntax error, unexpected INT, expecting ID or OR_KW or DOLLAR_CURLY or '"', at (string):1:5
>> 
>> So it notices the first thing as an INT (I think, it might be a float, but I don’t think so) but the “.” seems to be interpreted as the attribute access operator. I didn’t find the rule for this - can someone point this out to me?
>> 
>> Overall, I hope I didn’t make too much of a mess. I picked up a few little things along the way that I think warranted a quick correction (NixInt vs. regular int references and using a custom parser instead of stoi - or should that be stol?).
>> 
>> If someone could help me figure out what I’m butchering in the Lexer (or elsewhere) …
>> 
>> Cheers,
>> Christian
>> 
>>> On 04 Jan 2016, at 17:27, Eelco Dolstra <eelco.dolstra at logicblox.com> wrote:
>>> 
>>> Hi,
>>> 
>>> On 04/01/16 17:12, Rok Garbas wrote:
>>> 
>>>> should we add this to nixpkgs/lib? it is usefull (using it right now) :)
>>> 
>>> IMHO, it would be cleaner to add floats to the Nix language. Before somebody
>>> decides to implement floating point arithmetic using a bunch of regexps ;-)
>>> 
>>> --
>>> Eelco Dolstra | LogicBlox, Inc. | http://nixos.org/~eelco/
>>> _______________________________________________
>>> nix-dev mailing list
>>> nix-dev at lists.science.uu.nl
>>> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>> 
>> --
>> Christian Theune · ct at flyingcircus.io · +49 345 219401 0
>> Flying Circus Internet Operations GmbH · http://flyingcircus.io
>> Forsterstraße 29 · 06112 Halle (Saale) · Deutschland
>> HR Stendal HRB 21169 · Geschäftsführer: Christian. Theune, Christian. Zagrodnick
>> 
> 
> --
> Christian Theune · ct at flyingcircus.io · +49 345 219401 0
> Flying Circus Internet Operations GmbH · http://flyingcircus.io
> Forsterstraße 29 · 06112 Halle (Saale) · Deutschland
> HR Stendal HRB 21169 · Geschäftsführer: Christian. Theune, Christian. Zagrodnick
> 
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev

--
Christian Theune · ct at flyingcircus.io · +49 345 219401 0
Flying Circus Internet Operations GmbH · http://flyingcircus.io
Forsterstraße 29 · 06112 Halle (Saale) · Deutschland
HR Stendal HRB 21169 · Geschäftsführer: Christian. Theune, Christian. Zagrodnick

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160105/ee3404bc/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
Url : http://lists.science.uu.nl/pipermail/nix-dev/attachments/20160105/ee3404bc/attachment.bin 


More information about the nix-dev mailing list