lens icon indicating copy to clipboard operation
lens copied to clipboard

`string->number-lens` breaks lens laws when given string numbers in unexpected bases

Open jackfirth opened this issue 10 years ago • 3 comments

> (lens-view string->number-lens "#o10")
8
> (lens-set string->number-lens "#o10" (lens-view string->number-lens "#o10"))
"8"

Possible fix:

  1. 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

jackfirth avatar Aug 21 '15 19:08 jackfirth

Oh I completely forgot about that.

AlexKnauth avatar Aug 21 '15 19:08 AlexKnauth

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

AlexKnauth avatar Aug 31 '15 04:08 AlexKnauth

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.

jackfirth avatar Aug 31 '15 07:08 jackfirth