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

Re: [sc-users] 2D array question



On Fri, Mar 8, 2019 at 10:33 AM <brianlheim@xxxxxxxxx> wrote:
> Your second analogy also makes a distinction between the two cases:
>
> > C. resolve x --> 5; add 1; you get 6, and now change x's arrow to point to this 6
>
> i.e.: when x is resolved and that value is modified, a new value is created and x's arrow is changed
>
> > C. you've done something to the thing that x is pointing to. But y is
> > pointing to the same thing. So if you look at x, you see the change,
> > and if you look at y, you also see the change, because they're
> > pointing in the same direction.
>
> i.e.: when x is resolved and that value is modified, no new value is created and x's arrow is not changed
>
> Maybe I'm misunderstanding, but I don't see any explanation in the analogy as to why those two behaviors differ.

The distinction is right there in the code. The first case writes `x =
(something new)` and the second one does not.

`x = ` means "move the arrow." If you don't have `x = `, then you
didn't move the arrow.

The real problem with the arrow analogy is that you have to know
whether the operation was in-place (returns the identical object) or
returns a new object:

x = [0, 1];
y = x;
x = x.put(0, 2);
-> [ 2, 1 ]
y
-> [ 2, 1 ]

x = x.collect { |item| item * 2 };
-> [ 4, 2 ]
y
-> [ 2, 1 ]

And SC syntax doesn't give you any help with that. You just have to know. ??!!

Whereas (and maybe I'm missing something), "primitive data types are
passed by value while objects are passed by reference" is invisible in
user code:

x = 0.5;
rand(x)  // passed by value

x = Point(1.0, 1.0);
rand(x)  // looks the same but passed by reference

Which, I promise you, when you're dealing with
not-especially-technically-minded musicians, will not go over well.

Tom:
> Out of curiosity, is this actually what happens in sclang's implementation? I.e. there's an "integer 5" somewhere that both x and y have pointers to? In other words, if you were to look in memory, you'd see one "00000101" and not two?

My point is not about explaining the implementation. It's about
teaching people who are not programmers, and not especially interested
in programming minutiae, how to do something useful with a programming
language. They don't need to know whether x is a slot containing an
integer value 5, or if it points to the data. They do need to
understand how to control variable assignments to manipulate the
system's state.

The conversation/explanation should fit the audience.

hjh

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/