Re: terminology question re: binding

2009-02-17 Thread Konrad Hinsen

On Feb 17, 2009, at 0:17, Stuart Sierra wrote:

 As I understand it, every Var has a name, which is a symbol, but the
 name is an inherent property of the Var and cannot be changed.  You

Unless you create a var using with-local-vars, right?

Konrad.



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



Re: terminology question re: binding

2009-02-17 Thread David Sletten

On Feb 16, 2009, at 10:34 AM, Stuart Halloway wrote:


 David Sletten sent me this erratum:

 
 At the beginning of section 2.4 we have The symbol user/foo refers to
 a var which is bound to the value 10. Under the next subsection
 Bindings we have Vars are bound to names, but there are other kinds
 of bindings as well. The Common Lisp standard defines a binding as
 an association between a name and that which the name denotes. This
 is the second sense used in the book. The first sense of a binding
 between a var and its value is inconsistent.


 Should I be using two different terms, or is the notion of binding
 overloaded?



Stuart,

I'm sorry but my comments appear to have raised more of a fuss than I  
intended. I think I need to clarify two issues:

1. I was probably not sufficiently clear in my intent. I did not mean  
so much to point out that you were wrong as to simply highlight the  
inconsistent use of the words binding and bound. Your term  
overloaded is more neutral, and therefore a better choice than mine.

In a language such as Common Lisp where every variable is  
(effectively) a reference variable, we have three concepts: names,  
variables (references), and values (referents). These three things  
have two connections. In an orthodox (perhaps pedantic) sense a name  
is bound to a variable, and the variable has a value. Names can  
be bound to different variables and variables can be assigned new  
values:

(defvar *x* 8) ; Bind *x* to special variable and assign value.
(setf *x* 9) ; Assign new value to variable. Binding hasn't changed.

(let ((x 12)) ; Bind x to variable, assign value.
   (let ((x pung)) ; Bind x to different variable - different  
binding.
 (setf x foo) ; Same (2nd) variable, new value.
   ...) ; 1st binding visible again outside of inner LET
...) ; No more binding for x out here

On a side note, when we talk of scope we shouldn't talk about an  
identifier's scope or a variable's scope. Scope is an issue  
involving both names and variables: bindings have scope.

The definitions in the CLHS glossary all reflect this interpretation.  
However, as I was looking through my notes it became clear that your  
overloaded use is hardly idiosyncratic. For example, the CLHS entry  
for LET states: let and let* create new variable bindings and  
execute a series of forms that use these bindings. Yet it explicitly  
states later that: ...Then all of the variables varj are bound to  
the corresponding values. This seems to me inconsistent with the  
glossary definitions, but such usage occurs throughout the Standard.

I think that the strict usage is consistent with Clojure's binding  
macro, which binds a name to a new variable. The let special form  
does a similar thing, but the situation is a little different than in  
CL since you can't assign a new value to a variable established by  
a Clojure let binding. Consequently, it seems that we can more safely  
blur the distinctions among name/variable/value here. A name is  
associated with a given value for the lifetime of the binding.

As another example, the language Oz has the notion of identifiers,  
which may be either bound or free, and variables, which may either be  
bound or unbound. Oz variables are like Clojure lexicals--once  
assigned their values cannot change. So an unbound variable is simply  
a variable that has not been assigned a value yet. Assignment binds  
a value to a variable. Likewise, a free identifier is a name that  
doesn't refer to anything yet. Once bound, an identifier names a  
variable.

So to wrap this all up, if you are satisfied with your discussion in  
the book--and you seem justified in that--then I'll just shut up  
about binding.

2. My erratum report and comments above should not be viewed as  
though I advocate Clojure being evaluated through the lens of Common  
Lisp. I have a few years experience studying CL, so naturally that  
affects my perception of Clojure. However, in fairness the language  
should be judged on its own merits, and I am far too new to Clojure  
to make any such judgment yet.

Aloha,
David Sletten


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



Re: terminology question re: binding

2009-02-17 Thread Jeffrey Straszheim
I'm still not *entirely* clear about the mappings from symbols and
namespaces to Vars.  I think  I sort of understand how it works in practical
terms, but this is a confusing area and getting the terminology nailed down
would be a big help.

On Tue, Feb 17, 2009 at 10:10 AM, Chouser chou...@gmail.com wrote:


 On Tue, Feb 17, 2009 at 7:01 AM, David Sletten da...@bosatsu.net wrote:
 
  In a language such as Common Lisp where every variable is (effectively) a
  reference variable, we have three concepts: names, variables
 (references),
  and values (referents). These three things have two connections. In an
  orthodox (perhaps pedantic) sense a name is bound to a variable, and
 the
  variable has a value.

 Clojure similarly has three concepts with two connection for global
 Vars.  As you point out later, locals (as created by 'fn' and 'let')
 are a bit different.

  I think that the strict usage is consistent with Clojure's binding
 macro,
  which binds a name to a new variable.

 Are you sure?  It seems to me the most natural mapping from the CL
 concepts to Clojure is:
  CL name - Clojure symbol, name, or perhaps namespace entry
  CL variable - Clojure Var (or perhaps ref, atom, etc.)
  CL value or referent - Clojure value.

 Clojure's 'binding' macro does not change the connection from name to
 Var, but the one from Var to (effective, thread-local) value.

 I think this is worth dicussing not so much so because I care about
 being consistent with the classic meaning of these words in various
 other languages, but I'm all for careful use of English to reduce
 confusion as much as possible.

 --Chouser

 


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



Re: terminology question re: binding

2009-02-17 Thread David Sletten


On Feb 17, 2009, at 5:10 AM, Chouser wrote:


 I think that the strict usage is consistent with Clojure's  
 binding macro,
 which binds a name to a new variable.

 Are you sure?  It seems to me the most natural mapping from the CL
 concepts to Clojure is:
   CL name - Clojure symbol, name, or perhaps namespace entry
   CL variable - Clojure Var (or perhaps ref, atom, etc.)
   CL value or referent - Clojure value.

 Clojure's 'binding' macro does not change the connection from name to
 Var, but the one from Var to (effective, thread-local) value.


I see that you are correct. Observe the following behavior:
; Common Lisp. We have no way to get ahold of the variable  
(reference) to which a
; name is bound. Dereferencing is automatic. However, with a dynamic
; variable we can access the symbol data structure associated with  
the name *PUNG*.
(defvar *pung* 8)
(defvar *foo* *pung*) ; Referent of *PUNG* assigned
(defvar *bar* '*pung*) ; Note the quote here--assigning symbol *PUNG*

; Establish a new binding for *PUNG*. *BAR* changed as well.
(let ((*pung* 9)) (list *pung* *foo* (symbol-value *bar*))) = (9 8 9)

; Clojure. We can access the reference itself via var.
(def pung 8)
(def foo pung) ; i.e., (deref (var pung)) or @#'pung
(def bar (var pung))

; binding changes value of pung--apparently not the variable  
itself, thus
; bar also reflects changed value.
(binding [pung 9] (list pung foo @bar)) = (9 8 9)

; By contrast let binds pung to a new variable, which shadows the  
global.
; bar still refers to global pung
(let [pung 9] (list pung foo @bar)) = (9 8 8)

Do I have it right now?

Aloha,
David Sletten


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



Re: terminology question re: binding

2009-02-17 Thread Chouser

On Tue, Feb 17, 2009 at 11:48 PM, David Sletten da...@bosatsu.net wrote:

 ; Clojure. We can access the reference itself via var.
 (def pung 8)
 (def foo pung) ; i.e., (deref (var pung)) or @#'pung
 (def bar (var pung))

 ; binding changes value of pung--apparently not the variable
 itself, thus
 ; bar also reflects changed value.
 (binding [pung 9] (list pung foo @bar)) = (9 8 9)

 ; By contrast let binds pung to a new variable, which shadows the
 global.
 ; bar still refers to global pung
 (let [pung 9] (list pung foo @bar)) = (9 8 8)

 Do I have it right now?

The code and comments look right to me, but I'm not sure where that
leaves us on the original question of terminology.

I could say that the var named pung (user/pung, to be specific) has
the root value 8, but was there anything bound there?  And I can't
deny that pung becomes bound to 9 since a macro named 'binding' was
used.  Does that imply that the var was bound to 8 earlier?  Was the
name 'pung' bound to the Var?

Everything seems to have stopped making sense.  Perhaps I shouldn't
try to post this late at night.

--Chouser

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



Re: terminology question re: binding

2009-02-16 Thread Chouser

On Mon, Feb 16, 2009 at 3:34 PM, Stuart Halloway
stuart.hallo...@gmail.com wrote:

 David Sletten sent me this erratum:

 
 At the beginning of section 2.4 we have The symbol user/foo refers to
 a var which is bound to the value 10. Under the next subsection
 Bindings we have Vars are bound to names, but there are other kinds
 of bindings as well. The Common Lisp standard defines a binding as
 an association between a name and that which the name denotes. This
 is the second sense used in the book. The first sense of a binding
 between a var and its value is inconsistent.
  

 Should I be using two different terms, or is the notion of binding
 overloaded?

Clojure does have another term already for that first meaning:

(def x 5)  == #'user/x
(.hasRoot #'x)  == true
(.getRoot #'x)  == 5

I don't know if it's more correct, but it might be less confusing to
say The symbol user/foo is bound to a var which has a root value of
10.

--Chouser

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



Re: terminology question re: binding

2009-02-16 Thread Chouser

On Mon, Feb 16, 2009 at 5:29 PM, Chouser chou...@gmail.com wrote:

 I don't know if it's more correct, but it might be less confusing to
 say The symbol user/foo is bound to a var which has a root value of
 10.

Eh, well, I'm not sure about that first part.  I don't know if the
symbol is bound to the var or not.

But the var does has a root value of 10.  :-)

--Chouser

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



Re: terminology question re: binding

2009-02-16 Thread Stuart Sierra

On Feb 16, 3:34 pm, Stuart Halloway stuart.hallo...@gmail.com wrote:
 Should I be using two different terms, or is the notion of binding  
 overloaded?

I think it's overloaded.  In Common Lisp, symbols are bound to
values.  Clojure's Vars are closer to CL symbols than Clojure symbols
are to CL symbols. (!)  It's funky because CL docs talk of binding
symbols to values.  I like to think of both CL symbols and Clojure
Vars as storage locations.

As I understand it, every Var has a name, which is a symbol, but the
name is an inherent property of the Var and cannot be changed.  You
can bind a Var to different values with def, binding, var-set, set!,
and alter-var-root.  But you never bind a Var to a different name.

Within a namespace, a Var may be mapped to a name (a symbol).  There
is ns-unmap to remove a mapping, but no corresponding function to add
a mapping.  All you have is refer.

I await corrections. :)

-Stuart Sierra
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---