[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] 2D array question





On Tue, Mar 5, 2019, 9:39 AM <jamshark70@xxxxxxxxx> wrote:
On Tue, Mar 5, 2019 at 8:22 AM <brianlheim@xxxxxxxxx> wrote:
> The original explanation is exactly how it is implemented in the sclang interpreter.

I'd argue that, when you have to think about the implementation of an
abstraction, then the abstraction has failed :D

I was bringing up the implementation to show that there is a simple and direct correspondence between the semantics in the language and the implementation in the interpreter. I'm sorry if that confused you.

sclang syntax, as an abstraction, doesn't distinguish between value or
reference passing. The implementation does. I'm suggesting that users
shouldn't have to worry about the implementation.

It's the other way around -- the implementation mirrors the semantics exposed to the programmer.

If objects were passed by value, like primitive data types, we would have this:

a = "abc"
f = { |x| x[0] = $d }
f.(a) // contents of a remain "abc" after this call

Passing primitive data types by reference is more or less impossible by definition, but it would look like this:

a = 5
f = { |x| x = 3 }
f.(a) // value of a is now 3

And in fact that's exactly what you get when you use Ref:

a = `5
f = { |x| x.value = 3 }
f.(a) // a.value is now 3

I think you are overthinking this a bit, let's keep it simple.

Brian