On 2010 Mar 23, at 9:14 AM, Per Vognsen wrote:

Remember the one-liner I gave you last time?

Yup. It was the 'hard coded + 0' parts that had been ruminating in the back of my mind as being something that could be abstracted out. :)

Since the one you just posted didn't have all the features of my version, I've taken the liberty of
adjusting it:
; Variation on Per Vognsen's version.
(defn semi-map
  [pred fun seq1 seq2]
  "Lazy sequence of seq1 optionally combined with seq2.
   when pred on seq1 item is true, yield fun of seq1 and seq2
   otherwise yield seq1 item without advancing seq2.
   Example: (semi-map vowel? vector \"Hello Word\" (iterate inc 1))
   -> (\\H [\\e 1] \\l \\l [\\o 2] \\space \\W [\\o 3] \\r \\d)
  "
  (map #(if (pred %1) (fun %1 (first %2)) %1)
       seq1
       (reductions #(if (pred %2) (rest %1) %1)
                   seq2 seq1)))
;;;

What I don't understand (yet) is how to do a lazyness analysis on this similar to what
Meikel Brandmeyer did with my original code.

So, for my own understanding:
the outermost map is lazy, hence nothing will happen it the first result needs to be realized.
OK, so far so good.
when the first result of the map needs to be realized, I'm getting a bit foggy... the 2nd parameter to map 'seq1' will have to have its first element (and tail?) realized
        in order to call the mapping function #(if...)
the 3rd parameter to map '(reductions...)' will have to have its first element realized in order to call the mapping function #(if...) of the outermost map.
then:
In order to realize the first value of the result of reductions, both the first value of seq1 has to be realized to pass in as the second parameter to the reductions' function #(if ...)

Ok, so now my head hurts. But in a good way.

I think I have convinced myself that the only "eager" realization/ evaluation might be of the tail of seq1, but I'm not sure.

Thanks Per!

-Doug

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

To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or 
reply to this email with the words "REMOVE ME" as the subject.

Reply via email to