Okay, great.  That's my background too.

Without discussing a specific application, I think what you're looking
for can be achieved by normal macros and functions in Clojure.  I'll
try implement the collect method in Clojure, and hopefully that will
explain things.

Let's start by creating a collect function.

(defn collect
  [pred coll]
  (loop [remaining coll
         output []]
    (if (empty? remaining)
      output
      (recur (rest remaining)
        (conj output (pred (first remaining)))))))

And a quick test shows

(collect (fn[x](* 2 x)) [1 2 3])
=>[2 4 6]

Notice that the clojure collect takes a function, pred as an
argument.  The s-expression (pred (first remaining)) automatically
applies the right function do to the *pure genius* that is eval.  It's
pretty slick.

Here's my best attempt at writing an all-purpose collect-m macro.
It's ugly, and I don't like it.

(defmacro collect-m
  [coll & body]
  `(let [~'pred (fn [~'elemen...@body)]
     (loop [~'remaining ~coll
         ~'output []]
    (if (empty? ~'remaining)
      ~'output
      (recur (rest ~'remaining)
        (conj ~'output (~'pred (first ~'remaining))))))))

(collect-m [1 2 3] (* 2 element))
=>[2 4 6]

Notice that the term element is fixed as a parameter name.  I assume
that there is ONLY on input in the function.  The macro is ugly to
read.  Maybe someone else can do better.

Revisiting the function version, notice:

(collect (fn[x](* 2 x)) [1 2 3])

Feels very similar to

[1, 2, 3].collect(){|x| 2*x}

You have much more control of the function.

The main point I'm getting at is that I don't think the blockfn macro
approach is the way to go.  Either write a function that take
functions, or use a traditional macro.

Hope this helps.

Sean


On May 28, 1:37 pm, CuppoJava <patrickli_2...@hotmail.com> wrote:
> Haha. You got it. I discovered Lisp after using Ruby. Ruby was
> actually the language that helped me realize what a good idea
> functional programming is.
--~--~---------~--~----~------------~-------~--~----~
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
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