Error when trying Proto examples

I installed ddwPrototype and ddwCommon using the Quarks GUI. Running the following example from the Proto help file’s “Mimicking object-oriented behavior using Proto” example section

(
a = Proto({
	~a = 1;
	~b = 2;
	~times = { |mul|
		mul.notNil.if({ mul }, { ~a }) * ~b
	};
}, env: nil, parentKeys: #[b]);
)

a.times;        // 2
a.times(5);     // 10

b = a.copy;
b.a = 3;
b.times;        // 6

b.parent.b = 5; // error!

throws the following error:

ERROR: Message 'b_' not understood.
RECEIVER:
Instance of Environment {    (000002B0EA359388, gc=BC, fmt=00, flg=00, set=03)
  instance variables [5]
    array : instance of Array (000002B0E0D60288, size=32, set=5)
    size : Integer 2
    proto : nil
    parent : nil
    know : false
}
ARGS:
   Integer 5
CALL STACK:
	DoesNotUnderstandError:reportError
		arg this = <instance of DoesNotUnderstandError>
	Nil:handleError
		arg this = nil
		arg error = <instance of DoesNotUnderstandError>
	Thread:handleError
		arg this = <instance of Thread>
		arg error = <instance of DoesNotUnderstandError>
	Object:throw
		arg this = <instance of DoesNotUnderstandError>
	Object:doesNotUnderstand
		arg this = <instance of Environment>
		arg selector = 'b_'
		arg args = [*1]
	Interpreter:interpretPrintCmdLine
		arg this = <instance of Interpreter>
		var res = nil
		var func = <instance of Function>
		var code = "b.parent.b = 5;"
		var doc = nil
		var ideClass = <instance of Meta_ScIDE>
	Process:interpretPrintCmdLine
		arg this = <instance of Main>
^^ The preceding error dump is for ERROR: Message 'b_' not understood.
RECEIVER: Environment[ (times -> a Function), (b -> 2) ]

b.parent.know evaluates to false, so it looks like the message isn’t being relayed into the parent Environment.

b.parent[\b] = 5; // Environment[ (times -> a Function), (b -> 5) ], no error
a.b; //  5

Hi – you’re right. That example was broken.

I happened to be between tasks, and it’s a short fix, so I fixed it. You can update the quark from github and it should work after that.

hjh

2 Likes

Thank you for the super quick response and fix!