On Thu, Sep 1, 2011 at 2:08 PM, Alan Malloy <a...@malloys.org> wrote:
> Well, the two calls to subseq are unpleasant and possibly slow. I was
> thinking there's a way to write it as a single operation that returns
> three items, say (subseq s >= (dec 50)) to get the items before and
> after 50, but of course that doesn't work unless you know 49 is in
> there, and in that case why bother with subseq?
>
> It's a bit galling, because the sorted-set *knows* how to get to where
> 50 should be, and how to walk in either direction from there, but in
> order to walk in two different directions you have to walk down from
> the root twice. Maybe it'd be nice to have a (get-walker s 50) that
> you can later pass directions to, to walk through the set in whatever
> order.

A less-Clojury solution would be to have sorted-set implement List,
and provide something like get-walker that yields a ListIterator on
the specified element, or the next higher if any, or one past the end
otherwise, or whatever.

Of course a ListIterator is a mutable Java object.

A Clojury solution would be a function that traverses from the root
and then generates a return value equivalent to [(rsubseq s x) (subseq
s x)], except not performing two traversals to generate it. The caller
can destructure this and use the two seqs.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to