From: Samir Benmendil Date: Sun, 21 Jan 2018 00:56:01 +0000 (+0000) Subject: Support #bodx in number parser X-Git-Url: https://git.rmz.io/my-scheme.git/commitdiff_plain/369fde6e9fc7f5ddd28d83e34da21624cb4c2c7c?ds=sidebyside;hp=369fde6e9fc7f5ddd28d83e34da21624cb4c2c7c Support #bodx in number parser `where radix = ...` returns a function that takes a number and parses it accordingly. The function is chosed by 'try'ing to read a '#' followed by any of "bodx" and if that fails assume the base is decimal. The `>>` sequencing operator is used to combine `char` and `oneOf`, they are executed one after another, discarding the value of the first. `readInt` takes a base (2), a predicate returning what chars are valid and a function that describes the Integer value for a char. `(\x -> elem x "01")` is a lambda that returns true if x is in "01". `(read . (:[]))` is interesting. The `.` operator composes the functions `read` and `:[]`, where `:` is the append to list function and `[]` is the "first argument", i.e. `:[]` appends an element to the empty list. `let ((a,_):_) = ...` extracts the number from the `[(Number,String)]` type returned by the `read*` functions. Because strings starting with '#' are valid Atoms as well, we need to parse for numbers first. ---