Hi,

On 4 Dez., 07:53, Mon Key <[EMAIL PROTECTED]> wrote:
> So, in the case where the (doc)string is placed after the param I
> should expect that REPL reads that string but doesn't necesarily
> evaluate it?  Where does that string go? Does it become nil?  It
> wasn't passed as a nil anymore than it was passed as a docstring.

I'm not sure I understand correctly what you are asking for
but the following is my understanding what happens.

(defn foo
  "docstring here"
  [x y]
  (+ x y))

This - as discussed before - places the string in the metadata
of the Var foo, not the function itself. Functions cannot be
associated with metadata.

(defn foo
  [x y]
  "some string here"
  (+ x y))

This is a function which first evaluates "some string here",
which happens to evaluate to itself since it is a string. However
since the string is not the last expression of the function body
it is discarded and evaluation goes on with the next expression.

Since there is no docstring it is not assigned to the metadata
of the Var foo, which refers to the function. Hence retrieving
it will return nil.

> Following defns do not evaluate as equivalent - nor are they identical
> - nor do they appear to share the same identity.
> I can understand cases for passing the empty string, the empty list,
> etc.  However, I have trouble understanding how it isn't an error/
> exception to pass a non-empty string after the param list and have
> that string be converted to nil.

Ok. Let's try to understand what happens. Say you the second foo
function of above. Then a call (foo 1 2) is roughly equivalent to the
following:

(let [x 1
      y 2]
  (do
    "some string here"
    (+ x y)))

The part after the argument vector goes into the function body, which
is wrapped in a do. do evaluates the expressions and returns the
value of the last one. The results of evaluating the other expressions
are discarded.

So in (defn foo "string" [] ...) "string" is a docstring, while in
(defn foo [] "string" ...) "string" is part of the function body.

Hope this helps.

Sincerely
Meikel


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to