Class Member Assignment

13 views
Skip to first unread message

kfb

unread,
Jul 28, 2012, 5:29:19 PM7/28/12
to looplang
I'm having some difficulty with class member variables in loop. Given:

class Test ->
a

t = new Test()

the REPL output from here is:

>> t.a = 10
10
>> t
{a=10}
>> t
10

Why did 't' suddenly become 't.a'? Is this a language feature I'm
misunderstanding, or a bug? I'd expect the output to be:

>> t.a = 10
10
>> t
{a=10}
>> t
{a=10}

(Using ':' in place of '=' has the same issue.)

Dhanji R. Prasanna

unread,
Jul 28, 2012, 5:44:49 PM7/28/12
to loop...@googlegroups.com
Hmm, that's just a bug in the shell. This example shows that everything is working correctly under the hood:

     by Dhanji R. Prasanna

>> class Test ->
|    a
|    
ok
>> main ->
|    t.a: 10,
|    print(t),
|    print(t),
|    print(t)
|    where
|      t: new Test()
|    
ok
>> main()
{a=10}
{a=10}
{a=10}
{a=10}



I'll have a look and see why the shell is being funny. Thanks for reporting this and sorry about the bug!

Dhanji.

kfb

unread,
Jul 28, 2012, 5:47:10 PM7/28/12
to looplang
> I'll have a look and see why the shell is being funny. Thanks for reporting
> this and sorry about the bug!

No problem! Happy to take a look myself if you can point me to roughly
the right source file...

Dhanji R. Prasanna

unread,
Jul 28, 2012, 5:51:01 PM7/28/12
to loop...@googlegroups.com
Good to hear.

Check out LoopShell.java it's all in there.

We basically "fake" a shell context by remembering each evaluation and adding it to the "where" block of a throwaway function that is compiled and evaluated every time you press enter. So I think there's some error in here, stepping through with a debugger should reveal the flaw quickly.

Thanks!

kfb

unread,
Jul 31, 2012, 2:44:24 PM7/31/12
to looplang
Okay, I think I may have made some progress, at least in diagnosing
the problem. Fixing it is still slightly beyond my familiarity with
Loop at the moment :(

Here's some annotated output:

loOp (http://looplang.org)
by Dhanji R. Prasanna

ii = 1; Evaluating 'class SimpleClass ->' with whereBlock:
[]
ii = 2; Evaluating ' a' with whereBlock:
[]
ii = 3; Evaluating '' with whereBlock:
[]
ok
ii = 4; Evaluating 't = new SimpleClass()' with whereBlock:
[]
{}
ii = 5; Evaluating 't.a = 10' with whereBlock:
[Assignment{[Variable{name='t'},
Computation{[CallChain{[JavaLiteral{[]},
Call{shellObtainCallArguments{[Computation{[CallChain{[String{''t''}]}]}]}}]}]}]}]
10
ii = 6; Evaluating 't' with whereBlock:
[Assignment{[Variable{name='t'}, CallChain{[JavaLiteral{[]},
Call{shellObtainCallArguments{[String{''t''}]}}]}]},
Assignment{[CallChain{[Variable{name='t'}, Call{a}]},
IntLiteral{value=10}]}]
{a=10}
ii = 7; Evaluating 't' with whereBlock:
[Assignment{[Variable{name='t'}, CallChain{[JavaLiteral{[]},
Call{shellObtainCallArguments{[String{''t''}]}}]}]},
Assignment{[CallChain{[Variable{name='t'}]}, IntLiteral{value=10}]}]
10
ii = 8; Evaluating ':quit' with whereBlock:
[Assignment{[Variable{name='t'}, CallChain{[JavaLiteral{[]},
Call{shellObtainCallArguments{[String{''t''}]}}]}]},
Assignment{[Variable{name='t'}, IntLiteral{value=10}]}]

Looks like the REPL is losing the "Call{a}" part from the whereBlock
and leaving just 't = 10'. I can't figure out why this is happening
though.

On Jul 28, 10:51 pm, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
> Good to hear.
>
> Check out LoopShell.java it's all in there.
>
> We basically "fake" a shell context by remembering each evaluation and
> adding it to the "where" block of a throwaway function that is compiled and
> evaluated every time you press enter. So I think there's some error in
> here, stepping through with a debugger should reveal the flaw quickly.
>
> Thanks!
>
> On Sun, Jul 29, 2012 at 7:47 AM, kfb
> <kaleidoscopicfilmstripbl...@gmail.com>wrote:

Dhanji R. Prasanna

unread,
Jul 31, 2012, 6:09:43 PM7/31/12
to loop...@googlegroups.com
Nice detective work!


I've fixed it--the problem was actually in that the shell was treating:
t.a = ...
t = ...

..as the same thing because it just inspected the first part of the LHS of the assignment block instead of the entire thing.


On Wed, Aug 1, 2012 at 4:44 AM, kfb <kaleidoscopic...@gmail.com> wrote:
ii = 6; Evaluating 't' with whereBlock:
[Assignment{[Variable{name='t'}, CallChain{[JavaLiteral{[]},
Call{shellObtainCallArguments{[String{''t''}]}}]}]},
Assignment{[CallChain{[Variable{name='t'}, Call{a}]},
IntLiteral{value=10}]}]

(This actually reveals a different issue--which I've also fixed)

I've done a release. Please test rigorously and let me know if I have broken anything else in the shell!

Thanks so much,
Dhanji.
Reply all
Reply to author
Forward
0 new messages