Re: Efficiency of reduce function for lists.

2010-07-28 Thread gary ng
On Sat, Jul 24, 2010 at 3:16 PM, samnardoni samnard...@googlemail.com wrote: I have a simple string (or list of characters to be precise) in a form of: 123456789. I want to parse this string and end up with: 123569. The is essentially the same as a backspace. I think reduce(or fold/foldl'

Re: Efficiency of reduce function for lists.

2010-07-26 Thread ka
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

Re: Efficiency of reduce function for lists.

2010-07-26 Thread B Smith-Mannschott
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

Re: Efficiency of reduce function for lists.

2010-07-26 Thread Michael Wood
On 26 July 2010 09:25, B Smith-Mannschott bsmith.o...@gmail.com wrote: [...] 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

Efficiency of reduce function for lists.

2010-07-25 Thread samnardoni
I have a simple string (or list of characters to be precise) in a form of: 123456789. I want to parse this string and end up with: 123569. The is essentially the same as a backspace. I managed to implement this fairly simply using the reduce function - source: http://gist.github.com/489019.

Re: Efficiency of reduce function for lists.

2010-07-25 Thread Randy Hudson
This is a wholly appropriate use of reduce; it's the obvious function to use when you want to accumulate some calculation over a sequence. As you say, you can just produce a function that acts on the result, something like (defn fstep [c] (if (= c \) pop #(conj % c)) However, the obvious way

Re: Efficiency of reduce function for lists.

2010-07-25 Thread samnardoni
Randy, thanks for the reply. This has certainly cleared things up for me. I was only concerned about performance for an order of magnitude or more; just checking I was on the right track, so to speak. It seems I'll have to do a little research on transients now. On Jul 25, 4:23 pm, Randy Hudson

Re: Efficiency of reduce function for lists.

2010-07-25 Thread B Smith-Mannschott
On Sun, Jul 25, 2010 at 00:16, samnardoni samnard...@googlemail.com wrote: I have a simple string (or list of characters to be precise) in a form of: 123456789. I want to parse this string and end up with: 123569. The is essentially the same as a backspace. I managed to implement this