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: "1234<5678<<9". > > 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' in Haskell/F#) fits perfectly here. I am not too familiar with clojure syntax, the equivalent F#(and more or less the same in Haskell):
let del (s:string) = let x = List.fold (fun a x -> if (x = '<') then List.tail a else x::a) [] (List.ofSeq s) |> List.rev |> List.toArray new System.String(x) basically it just turn the string into list of char(native if in Haskell) and use the very efficient cons(::)/tail operation in the fold and do a reverse at the end. This also handles 'over deletion' as 'tail of [] -> []'. -- 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