lens
lens copied to clipboard
`string->number-lens` breaks lens laws when given string numbers in unexpected bases
> (lens-view string->number-lens "#o10")
8
> (lens-set string->number-lens "#o10" (lens-view string->number-lens "#o10"))
"8"
Possible fix:
- Restrict string->number-lens to only operate on base 10 numbers, possibly create a function that accepts a radix and constructs an isomoprhism lens between strings and numbers using that radix
Oh I completely forgot about that.
This is one case of a more general issue with read/write isomorphisms, because they aren't really isomorphisms. There are multiple ways to write a value, that would all read to the same original value.
(1) = (1 . ())
(1 . + . 2) = (+ 1 2) = (+ . (1 . (2 . ())))
'1 = (quote 1) = (quote . (1 . ()))
#o10 = 8
Perhaps there should be some sort of restricted version of reading and writing where each datum is required to be in some canonical form? For instance, pairs are flattened into lists as far as possible, all numbers are in base 10, quoting is minimized, stuff like that. That could get pretty complex however.