Hi there, I'm rather new to Clojure but have a lot of experience with newLISP. 
I wrote a nifty function the other day that I'm trying to port to Clojure but 
my inexperience with the language and lack of knowledge of the api (which is 
down ATM) is making this difficult, maybe someone can help.

The function works like so:

(for-query-with-db db "SELECT name FROM people" (println NAME))
=> prints the names of all the people

Here's how it's defined in newLISP (it's fairly understandable even if you've 
never written newLISP code before):

(define-smacro (for-query-with-db db query)
        (letn (db (eval db) sql (db:prepare-sql query) keys '())
                (dotimes (i (sql:col-count))
                        (push (sym (upper-case (sql:col-name i))) keys -1)
                )
                (while (list? (setf values (sql:next-row)))
                        (eval (expand (cons 'begin $args) (unify keys values)))
                )
        )
)

The magic happens here:

                (while (list? (setf values (sql:next-row)))
                        (eval (expand (cons 'begin $args) (unify keys values)))
                )

$args is equivalent to the 'body' in [& body] in clojure, and the expand 
function will replace all of the symbols in 'keys' (in $args) with the 'values'.

So (println NAME) becomes (println "José Lopez"), and it gets eval'd each time 
in the loop to the different values in the table.

How would you implement this behavior in Clojure?

Thanks,

Greg

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to