2010/9/10 Stefan Rohlfing <stefan.rohlf...@gmail.com>:
> @ Nicolas and ajuc
>
> Thank you very much for showing me where I went wrong! With so many
> parentheses it sometimes happens that I misplace one
>
> Now the output of the function is as expected:
>
> (defn prefix->postfix [expr]
>  (if (coll? expr)
>    (let [ [op arg1 arg2] expr]
>      [ (prefix->postfix arg1) (prefix->postfix arg2) op])  ;; <--
> removed on parenthesis here
>  expr))
>
> (prefix->postfix '(+ 2 (* 3 2)))
> ;; --> [2 [3 2 *] +]
>
> There is just one point I still don't quite understand. That is,
> during one of the recursive calls, the expression (* 3 2) is passed as
> an argument to prefix->postfix:
>
> (prefix->postfix (* 3 2))
>
> As prefix->postfix is a normal function and not a macro, (* 3 2)
> should get evaluated BEFORE being passed to the function. However,
> this is not the case here.
>
> Could it be that because (* 3 2) is quoted, because the initial
> argument to the function, '(+ 2 (* 3 2)), was quoted?
>
> Could it be that because the initial argument to prefix->postfix, '(+
> 2 (* 3 2)), is quoted, (* 3 2) is also quoted and therefore does not
> get evaluated?

Yes. '(+ 2 (* 3 2)) being quoted means that the function receives a
datastructure : a list composed of the symbol +, the number 2, and
finally a list composed of the symbol *, the number 3 and the number
2.
' is a syntactic sugar for the special form named quote , whose
purpose is to not evaluate everything which is quoted, and just keep
as a datastructure what the reader has read.

And now, food for thought :-) :

user=> (quote (defn x))
(defn x)

;; => See, no macroexpansion, just what the reader read

user=> (read-string "(defn x)")
(defn x)

;; => I prove the point of above: just what the reader read

user=> (quote (defn ^{:foo :bar} x))
(defn x)

;; => but in the above ^^^, where's :foo :bar ?

user=> (meta (second (quote (defn ^{:foo :bar} x))))
{:foo :bar}

;; => it's there, but the reader has already interpreted the ^
(because it is a reader macro) and placed {:foo :bar} as the metadata
map for the symbol x

HTH,

-- 
Laurent

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

Reply via email to