Today there is no string to number conversion. [int "42"] and
[float "3.14"] both return (); there is no parse-int,
parse-float, to-int, or equivalent in the builtin set.
This is the single most surprising gap when writing real programs:
you cannot read a number from stdin, args, env, or a file.
Proposal
Add parse-int and parse-float, both returning Option
(or Result for richer errors):
[parse-int "42"] ; [Some 42]
[parse-int "x"] ; None
[parse-float "3.14"]
Acceptance criteria
- Builtins available in the VM and listed in
web/src/pages/ref/builtins.loon.
- A test covering valid input, invalid input, leading/trailing whitespace,
negative numbers, and out-of-range integers.
Found while completing the hyperpolyglot ml column.
Today there is no string to number conversion.
[int "42"]and[float "3.14"]both return(); there is noparse-int,parse-float,to-int, or equivalent in the builtin set.This is the single most surprising gap when writing real programs:
you cannot read a number from stdin, args, env, or a file.
Proposal
Add
parse-intandparse-float, both returningOption(or
Resultfor richer errors):Acceptance criteria
web/src/pages/ref/builtins.loon.negative numbers, and out-of-range integers.
Found while completing the hyperpolyglot ml column.