Re:Show HN: New Lisp data structure
by daniel-cussen on Wednesday December 01, 2010 @06:55PM
(#1960304)
About the bug, I talk about this at the end of trellis2.lisp. I didn't want to weird people out by adding a second sentinel to the list.
I realize these aren't the best at any one thing, but in situations where you'd normally use lists (exploratory programming, say) you can swap to this for a performance boost.
That's just broken, and will lead to horrible bugs. There is a reason why normal Lisp lists end with NIL instead of storing the last element in the last cdr.
Re:Show HN: New Lisp data structure
by daniel-cussen on Wednesday December 01, 2010 @08:00PM
(#1960504)
> That's just broken, and will lead to horrible bugs.
You mean you think people will use this? Thanks :)
Here's how I was thinking of fixing it:
(setf nol 'nol) ; make nol evaluate to itself
(defun my-null (x) ;redefine null (if (or (null x) (eql nol x)) t null))
Then, change add so that if it's adding a nil, it changes the sentinel at the end of the linked list part of the list to nol.
So (trellis 1 2) returns (1 . ((2 . NIL) . NIL))
And (add nil (trellis 1 2)) returns (1 . ((2 . NIL) . NOL))
As soon as someone adds something other than a nil to a cdr of a cons in a tree, add changes nol back to nil.
Use gensym to make a unique sentinel.
Indeed, I'm not sure in what situations this tradeoff of cons/decons- for lookup-speed is helpful. If I just need fast lookup, I'll use a mapping structure (hashtable, balanced binary tree, patricia trie, etc). If I need reasonable lookup speed and also standard sequence manipulations, finger trees or ropes seem like a better choice. They're more complex, but if performance is an issue, then it's probably worth it.
Also, a bug/design flaw: You can't store NILs in the terminal position: