type conversion

20 views
Skip to first unread message

mette Joergensen

unread,
Dec 3, 2020, 3:29:59 AM12/3/20
to NGLess
Hi
Is it possible to convert strings into integers in NGLess. I'm reading in a number using ARGV[], but NGLess thinks it is string and I get the following error:

Error in type-checking (line 21): Expected numeric expression, got Just NGLString for expression Lookup 'MY_CONSTANT'

Best,
Mette

Renato Alves

unread,
Dec 3, 2020, 5:12:38 AM12/3/20
to ngl...@googlegroups.com
Dear Mette,

Not yet: https://github.com/ngless-toolkit/ngless/issues/78

Cheers,
Renato

mette Joergensen

unread,
Dec 3, 2020, 5:32:33 AM12/3/20
to NGLess
Thanks. Do you have any idea when the issue is fixed. I can see that you opened the issue two years ago.
Cheers,
Mette.

Luis Pedro Coelho

unread,
Dec 4, 2020, 12:35:07 AM12/4/20
to NGLess List
Dear Mette,

We tend to consider bugs high priority, but sometimes, as in this case, the issues are just for us to not forget ideas and so they can stay open for a longer time.

Frankly, this is not a hard thing to implement, just that there was never any high priority case as one could "hack around it", but if you need it, I don't mind just writing the little bits of code to get it done fast. In the issue discussion there was a concern about getting the best API, which we might eschew in favor of just getting it doe.

Best
Luis

Luis Pedro Coelho | Fudan University | http://luispedro.org
--
You received this message because you are subscribed to the Google Groups "NGLess" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngless+un...@googlegroups.com.

mette Joergensen

unread,
Dec 4, 2020, 4:16:45 AM12/4/20
to NGLess
I agree that it is better to do it correct than just doing something that is working and I understand that you prioritize bugs higher than extensions to the api. For now I have solved it by having one NGLess script per possible value of the number. My wrapper script which submits the jobs to our HPC is then calling the correct script. This works fine as long as it is only one number with a small number of possible values. It is actually also better as it follows the philosophy that the commandline parameters shouldn't change the output of the NGLess script. Anyway in the future at some point it would be nice to have the possibility to read in numbers.  

Luis Pedro Coelho

unread,
Dec 4, 2020, 6:59:01 AM12/4/20
to NGLess List
Okay, I implemented this for the github version:


1) int/double now have a method .to_string() to convert to string. This turned out to be really easy to do
2) two new functions read_int() and read_double() convert from string to int/double

HTH,
Luis

Luis Pedro Coelho | Fudan University | http://luispedro.org


Reply all
Reply to author
Forward
0 new messages