nchurch <nchubr...@gmail.com> writes:

> Replying to Tassilo: I'm not quite sure I understand this problem:
>
>> then changing its name requires changing all places where
>> clojure.core.quotient/remainder is used
>
> surely the call to Values takes place inside the function definition,
> which happens \once.  If you want a different variable name on \use,
> you use a let; if you want to return a different variable name on
> \definition, you use a let inside the function (or perhaps Values
> could have some sugar for renaming variables).

I understand your proposal in such a way, that in a function

  (defn foo [x]
    (let [double-x (* 2 x)]
      (values x double-x)))

the `values' was actually a macro that

  1. creates a namespace for the function (user.foo)

  2. creates a var holding the last second value (user.foo/double-x)
     where the name of the var is dictated by the local var holding the
     value

  3. expands into code that sets user.foo/double-x at runtime and then
     returns the first value x

Then, if I want to use the second value returned by foo in my code, I'd
so something like

  (let [x (foo 17), dx user.foo/double-x]
    (do-something-with x dx))

Since I have to refer to user.foo/double-x to get the second value, once
that name changes, I have to change my code, too.

But probably, I've simply misunderstood your intent.

> It's true that quotient/remainder must be thread-local (in fact it
> should really be function-local), but this makes it no different than
> a let-variable or a function parameter; it doesn't necessarily mean it
> is mutable.  Is X mutable in
>
> (let [X 1
>       X (inc X)])
>
> ?

Nope, the latter X shadows the former X.  But there's no such thing for
vars in a namespace.

> If you slapped that X in a data structure, you would not find it
> changing under your nose.  quotient/remainder really has to behave in
> the same way----imagine the quotient call creates an invisible let
> every time.

Sorry, I don't get you.  What am I misinterpreting in your approach?  To
me, it looks like you want to bind the multiple values to vars in an
ad-hoc namespace corresponding to a function.  Then, there's no such
thing as a lexical scope provided by let.  A namespace is a globally
accessible thingy.

> Perhaps I should explain why I think this is "simple".  It's simple
> because a) it allows you to ignore the extra values unless you want
> them and

Well, the Common Lisp approach does so, too.

> b) it gives you ready-to-use names.  To my taste, b) is very
> important.

To me, that's a major downside.

> (quotient 5 2)
> (quotient 8 3)
>
> quotient(5 2)/remainder  --> 1

Huh, you want to create a namespace not only for each function but for
each function call?  And then store the multiple values for each of
them?

Bye,
Tassilo

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