]> git.rmz.io Git - my-scheme.git/commit
Support #bodx in number parser
authorSamir Benmendil <me@rmz.io>
Sun, 21 Jan 2018 00:56:01 +0000 (00:56 +0000)
committerSamir Benmendil <me@rmz.io>
Sun, 21 Jan 2018 00:56:01 +0000 (00:56 +0000)
commit369fde6e9fc7f5ddd28d83e34da21624cb4c2c7c
treed382cf6f3d513b99db0b58c7e162bb357a352ba1
parent2cd941c44d3b067acab871474383057344afcf37
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.
app/Main.hs