From: Ken A. <kan...@bb...> - 2004-07-09 14:36:46
|
Q1`: In src/jsint/Evaluator.java: public DynamicEnvironment INTERACTION_ENVIRONMENT Should this be static final, or should it be named interactionEnvironment? Q2: analyze() line 265: return new DynamicVariable((Symbol)x, dynamicEnv); This returns a new DynamicVariable for each use of a symbol in the body. Shouldn't it reuse one if there is one already like Symbol.intern()? Though that might require a synchronized method. k |
From: Geoffrey K. <ge...@kn...> - 2004-07-09 16:23:00
|
On Jul 9, 2004, at 10:36, Ken Anderson wrote: > Q1`: > In src/jsint/Evaluator.java: > public DynamicEnvironment INTERACTION_ENVIRONMENT > > Should this be static final, or should it be named > interactionEnvironment? Would anyone ever override/replace the interaction environment? If yes, I vote the latter. If no, I vote the former. > Q2: analyze() > line 265: > return new DynamicVariable((Symbol)x, dynamicEnv); > This returns a new DynamicVariable for each use of a symbol in the > body. > Shouldn't it reuse one if there is one already like Symbol.intern()? > Though that might require a synchronized method. By DynamicVariable I assume you mean a variable of local scope. If that is true, then I think you'd want a new one for each new binding, as opposed to each use. The word "dynamic" is a bit confusing to me, because it means one thing in the context of C or Java, another thing in Common Lisp. And here we are talking about a Scheme written in Java. Symbol.intern() -- wouldn't that let you have only one "x", instead of one at the top-level (global scope) and each lower local scope? Or, in the case of (define x 1) (let ((x 2)) ...), are the two x's guaranteed to have different Symbols, interned separately? Geoffrey -- Geoffrey S. Knauth | http://knauth.org/gsk |
From: Ken A. <kan...@bb...> - 2004-07-09 17:45:19
|
At 12:22 PM 7/9/2004 -0400, Geoffrey Knauth wrote: >On Jul 9, 2004, at 10:36, Ken Anderson wrote: >>Q1`: >>In src/jsint/Evaluator.java: >>public DynamicEnvironment INTERACTION_ENVIRONMENT >> >>Should this be static final, or should it be named interactionEnvironment? > >Would anyone ever override/replace the interaction environment? >If yes, I vote the latter. If no, I vote the former. Yes, i think it should be an instance field. >>Q2: analyze() >>line 265: >> return new DynamicVariable((Symbol)x, dynamicEnv); >>This returns a new DynamicVariable for each use of a symbol in the body. >>Shouldn't it reuse one if there is one already like Symbol.intern()? >>Though that might require a synchronized method. > >By DynamicVariable I assume you mean a variable of local scope. If that is true, then I think you'd want a new one for each new binding, as opposed to each use. The word "dynamic" is a bit confusing to me, because it means one thing in the context of C or Java, another thing in Common Lisp. And here we are talking about a Scheme written in Java. > >Symbol.intern() -- wouldn't that let you have only one "x", instead of one at the top-level (global scope) and each lower local scope? Or, in the case of (define x 1) (let ((x 2)) ...), are the two x's guaranteed to have different Symbols, interned separately? Yes, the name isn't very informative. Originally, a Symbol had a name and a value field. The value was used to store the global value of the Symbol if any. Several people have contributed code so things are a bit different. A DynamicVariable has a symbol and a DynamicEnvironment which is a hash from symbol -> value. This is what lets the module system work. So if you type x to the REPL The reader returns a the symbol 'x, which the evaluator analyzes and turns into a Dynamic Variable in the evaluator's DynamicEnvironment. It then executes that DV to produce a value, by looking it up in the DV's DE. The DV also has a field that is used to store the value during serialization. This explanation has helped me understand this, and i found a slight bug in serialization and i have a new proposal for DV and DE which i'll send in my next message. k |
From: Toby A. <tob...@pe...> - 2004-07-11 19:06:43
|
On Fri, Jul 09, 2004 at 01:45:10PM -0400, Ken Anderson wrote: > At 12:22 PM 7/9/2004 -0400, Geoffrey Knauth wrote: > >On Jul 9, 2004, at 10:36, Ken Anderson wrote: > >>Q1`: > >>In src/jsint/Evaluator.java: > >>public DynamicEnvironment INTERACTION_ENVIRONMENT > >> > >>Should this be static final, or should it be named > >>interactionEnvironment? > > > >Would anyone ever override/replace the interaction environment? > >If yes, I vote the latter. If no, I vote the former. > > Yes, i think it should be an instance field. Yes, I forgot to change its name when I made the patch to make it an instance field. > The DV also has a field that is used to store the value during > serialization. > > This explanation has helped me understand this, and i found a slight > bug in serialization and i have a new proposal for DV and DE which > i'll send in my next message. I also have found a bug in the serialization of DynamicVariables, for which I as going to submit a patch this week. The one I found has to do with serializing DynamicVariables that are created as the result of Java-dot notation. My (not cleaned up) fix is below. Index: src/jsint/DynamicVariable.java =================================================================== RCS file: /cvsroot/jscheme/jscheme/src/jsint/DynamicVariable.java,v retrieving revision 1.4 diff -r1.4 DynamicVariable.java 5a6 > boolean isDefined; 19,20c20,23 < // create the binding < setDynamicValue(storedDynamicValue); --- > // create the binding if it was defined > if (isDefined) { > setDynamicValue(storedDynamicValue); > } 43c46,51 < out.writeObject(getDynamicValue()); --- > if (getDynamicEnv().isDefined(name)) { > out.writeBoolean(true); > out.writeObject(getDynamicValue()); > } else { > out.writeBoolean(false); > } 56c64,67 < storedDynamicValue = in.readObject(); --- > isDefined = in.readBoolean(); > if (isDefined) { > storedDynamicValue = in.readObject(); > } Toby. |