On Mon, Jul 26, 2010 at 08:13, ka <sancha...@gmail.com> wrote:
>> For the program, I know that when processing a character, I do not
>> need the previous result. All I need is the current character, and I
>> can return a function that acts on the result. I'm not sure if this is
>> simple to implement in a functional way.
>
> Actually my understanding says that you need the whole list as this
> cannot be implemented as lazy ? (you might have any number of
> backspaces ahead so you need all the result)
>
> See also: http://kotka.de/blog/2009/11/Stopping%20Times%20and%20Laziness.html

Yes, you're quite correct. I reformulated the assignment a bit. ;-)
Strings are not lazy in Java & Clojure. However, the originally
proposed solution is only half-lazy. It's lazy on the input.  The
ouput is always fully realized. Consider also that a StringBuffer of N
chars uses far less heap than a vector of N Characters due to
per-object overheads. So, in the end, a fully eager solution based on
strings might be preferable to a half-lazy solution. That would depend
on the problem size.

That said, don't use my code. It's hideous. And by now, I'm sure
there's a cleaner solution possible for my approach:

The idea is to split the input string into a lazy list of substrings
alternating between strings containing no "<" and strings composed
soley of "<". We then consume these strings 2 at a time, using the
length of the second to modify the first before passing it through.
The concatenation of the resulting lazy sequence of strings is the
solution.

// Ben

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