cognate
cognate copied to clipboard
Canonical string representations
Currently the box.cog test fails for Cogni only because I decided to stringify boxes slightly differently.
One of the tests is:
Let E be a List (Box 1 Box 2 Box 3 Box 4);
Set Index 0 E be Index 1 E;
Set Index 1 E be Index 2 E;
Set Index 2 E be Index 3 E;
Set Index 3 E be Index 0 E;
Print E;
Under cognac it gives:
([[[[...]]]] [[[[...]]]] [[[[...]]]] [[[[...]]]])
But under cogni it gives:
(#1=[#2=[#3=[#4=[#1#]]]] #2# #3# #4#)
The reason it does this is I implemented the cyclic printer using Scheme's write-with-shared-structure algorithm. What are your opinions on this format?
I don't see any representational advantage to just bailing and printing ... when a recursive object is detected, because it doesn't show which other object it points back to. Especially with this test, with cognac's stringification it's not clear that the nested boxes are actually pointing to each other and there are only four boxes in use, or each of the elements is four independent boxes that point to themselves in a loop (for a total of 16 boxes in use). With the write/ss form it's clear what points where. Do you agree?
Ohh that's an interesting way of doing it. While less aesthetically pleasing than what Cognac currently does it does certainly seem more useful. What does it look like for non-cyclic boxes?
If there aren't any cycles then there aren't any #N= or #N# datum markers. So it would look the same. But the advantage of this is is also shows when you have the same box in two different places (i.e. setting one will change the other, because there isn't any other, they're the same object).
$ cat test.cog
Let X be List (Twin Box 0); Print X;
Let Y be List (Box 0 Box 0); Print Y;
$ cognac test.cog >/dev/null && ./test
([0] [0])
([0] [0])
$ ./cogni test.cog
(#1=[0] #1#)
([0] [0])
oh yeah that does make sense