-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmsg00023.html
169 lines (155 loc) · 6.11 KB
/
msg00023.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!-- MHonArc v2.3.3 -->
<!--X-Subject: Re: Closure failure? [ How they work ] -->
<!--X-From: Pat <[email protected]> -->
<!--X-Date: Wed, 16 Feb 2000 22:57:20 -0600 (CST) -->
<!--X-Message-Id: [email protected] -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: mtuzot07jsb.fsf@hodge-podge.mit.edu -->
<!--X-Reference: mtuzot07jsb.fsf@hodge-podge.mit.edu -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML//EN">
<HTML>
<HEAD>
<TITLE>Re: Closure failure? [ How they work ]</TITLE>
<LINK REV="made" HREF="mailto:[email protected]">
</HEAD>
<BODY>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->
<HR>
[<A HREF="msg00031.html">Date Prev</A>][<A HREF="msg00024.html">Date Next</A>][<A HREF="msg00031.html">Thread Prev</A>][<A HREF="msg00024.html">Thread Next</A>][<A HREF="maillist.html#00023">Date Index</A>][<A HREF="threads.html#00023">Thread Index</A>]
<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>Re: Closure failure? [ How they work ]</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: "Nathan J. Williams" <<A HREF="mailto:[email protected]">[email protected]</A>></LI>
<LI><em>Subject</em>: Re: Closure failure? [ How they work ]</LI>
<LI><em>From</em>: Pat <<A HREF="mailto:[email protected]">[email protected]</A>></LI>
<LI><em>Date</em>: Wed, 16 Feb 2000 22:44:04 -0600</LI>
<LI><em>Cc</em>: <A HREF="mailto:[email protected]">[email protected]</A>, <A HREF="mailto:[email protected]">[email protected]</A></LI>
<LI><em>In-Reply-To</em>: <[email protected]>; from Nathan J. Williams on Wed, Feb 16, 2000 at 07:30:12PM -0500</LI>
<LI><em>Mail-Followup-To</em>: "Nathan J. Williams" <[email protected]>,[email protected], [email protected]</LI>
<LI><em>References</em>: <[email protected]></LI>
<LI><em>Reply-To</em>: <A HREF="mailto:[email protected]">[email protected]</A></LI>
<LI><em>Resent-Date</em>: Wed, 16 Feb 2000 23:56:02 -0500</LI>
<LI><em>Resent-From</em>: [email protected]</LI>
<LI><em>Resent-Message-ID</em>: <"9tbogD.A.TCH.u63q4"@host3.cedant.com></LI>
<LI><em>Resent-Sender</em>: [email protected]</LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
On Wed, Feb 16, 2000 at 07:30:12PM -0500, Nathan J. Williams wrote:
>
> Greetings. I'm trying to use Beanshell as part of an introductory Java
> teaching environment. The goal is to let the students write simple
> expressions to solve a problem without making them deal with the full
> overhead of class and method syntax, as well as to have a GUI
> environment that can give them rapid feedback on what their code is
> doing.
Great. I'd love to hear more about your project as you get it going.
> In porting this environment to use bsh, I've run into a problem with
> closures. The system wants some variable to be persistent across
> function calls, but I seem to be getting copy-on-write semantics
> instead of normal access semantics. My minimal test case is:
[ example moved to the bottom of this email ]
I can see how this would be confusing, but I'm afraid that it's currently
the expected behavior. The problem with loosening up the language such that
you don't have to declare variables is that you don't have a clear way to
determine where they are intended to be declared vs. where they are simply
being assigned. The most general solution (and the one that BeanShell
currently uses) is that variablas are declared wherever they are assigned
and if you want to assign a variable in a parent scope you have to use a
modifier...
I agree that this is not linguistically pleasant and it bothers me that it
diverges from Java in a sense... however Java doesn't allow defining methods
within methods, so it's not entirely divergent.
I agree that forcing students to learn a new (or at least non-standard usage)
keyword is not ideal... I'll have to think about a suggestion for you.
[ The example ]
> ctest() {
>
> int x;
> x = 5;
>
> print("Start. X is " + x);
>
> subfunc() {
> print ("Subfunc. X is " + x);
> x = x + 1;
> print ("X is now " + x);
> }
> return this;
> }
>
> I would expect that creating a ctest() object and callung subfunc()
> twice would print 5,6 and then 6,7. Instead:
>
> bsh % source("closure.bsh");
> bsh % obj=ctest();
> Start. X is 5
> bsh % obj.subfunc();
> Subfunc. X is 5
> X is now 6
> bsh % obj.subfunc();
> Subfunc. X is 5
> X is now 6
>
> ... indicating that the change to x isn't being made in the ctest()
> environment.
>
> I can get the behaviour I want if I change the references to x in
> subfunc() to super.x, but that both seems linguistically wrong and
> adds different, extraneous syntax to the code the students have to write.
Thanks,
Pat
P.S. I apologize again to people who get this twice (one for users@ and
once for developers@) I will work out a solution as soon as possible.
</PRE>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<UL><LI><STRONG>Follow-Ups</STRONG>:
<UL>
<LI><STRONG><A NAME="00024" HREF="msg00024.html">Re: Closure failure? [ How they work ]</A></STRONG>
<UL><LI><EM>From:</EM> [email protected] (0000-Admin(0000))</LI></UL></LI>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00031.html">BeanShell in the news...</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00024.html">Re: Closure failure? [ How they work ]</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00031.html">BeanShell in the news...</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00024.html">Re: Closure failure? [ How they work ]</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="maillist.html#00023"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="threads.html#00023"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</BODY>
</HTML>