Quantcast

nil an array as argument

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

nil an array as argument

Jeroen
Hi list,

some little thing I cannot get my head around (yet), maybe somebody
would be so nice to help me out here

this is on 3.8 osx.

there is an array of synths of variable size, organized in two rows.
after their use I want to evaluate the function to free the synths, and
nil the array. however, although the synths are freed, the array is not
nilled. evaluating that directly works of course, but not as an
argument... is that because the array is not 'reachable' from within the
scope of the function? Is there a way to do that? I know I can do it
some place else, but I'd like to understand why.

<code>
~tempSynthB = Array.fill( ~data471Harp.at(\d)[0].size*2,
{Synth(\circuitBC, addAction: \addToTail)});
~tempSynthB = ~tempSynthB.reshape(2, (~data471Harp.at(\d)[0].size) );

~freeSynths = { |synths| synths !? { synths.flatten.do( _.free ); synths
= nil; }; };

~freeSynths.value(~tempSynthB);

<\code>

Thanks for any pointers.

Jeroen





_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nil an array as argument

Jeroen
Anyone?

cheers, jeroen



On 09.02.17 14:14, Jeroen wrote:

> Hi list,
>
> some little thing I cannot get my head around (yet), maybe somebody
> would be so nice to help me out here
>
> this is on 3.8 osx.
>
> there is an array of synths of variable size, organized in two rows.
> after their use I want to evaluate the function to free the synths, and
> nil the array. however, although the synths are freed, the array is not
> nilled. evaluating that directly works of course, but not as an
> argument... is that because the array is not 'reachable' from within the
> scope of the function? Is there a way to do that? I know I can do it
> some place else, but I'd like to understand why.
>
> <code>
> ~tempSynthB = Array.fill( ~data471Harp.at(\d)[0].size*2,
> {Synth(\circuitBC, addAction: \addToTail)});
> ~tempSynthB = ~tempSynthB.reshape(2, (~data471Harp.at(\d)[0].size) );
>
> ~freeSynths = { |synths| synths !? { synths.flatten.do( _.free ); synths
> = nil; }; };
>
> ~freeSynths.value(~tempSynthB);
>
> <\code>
>
> Thanks for any pointers.
>
> Jeroen
>
>
>
>
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
>
>


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nil an array as argument

ddw_music
In reply to this post by Jeroen
Jeroen wrote
there is an array of synths of variable size, organized in two rows.
after their use I want to evaluate the function to free the synths, and
nil the array. however, although the synths are freed, the array is not
nilled. evaluating that directly works of course, but not as an
argument... is that because the array is not 'reachable' from within the
scope of the function? Is there a way to do that? I know I can do it
some place else, but I'd like to understand why.

<code>
~tempSynthB = Array.fill( ~data471Harp.at(\d)[0].size*2,
{Synth(\circuitBC, addAction: \addToTail)});
~tempSynthB = ~tempSynthB.reshape(2, (~data471Harp.at(\d)[0].size) );

~freeSynths = { |synths| synths !? { synths.flatten.do( _.free ); synths
= nil; }; };

~freeSynths.value(~tempSynthB);
<\code>
We sometimes say "variables hold objects," but that isn't exactly true. Variables hold *references* to objects. Think of it like this: in a room, there's s bunch of tables. These are like memory locations. Each table has a number, and can have an object on it. There's also a set of blackboards, each with a variable name and a message saying "look at table number #."

So you have an array on table 1. The ~tempSynthB blackboard says "look at table 1." Then, when you value the function, there's another blackboard for "synths" and it *also* says "look at table 1." There are two different boards, both pointing to the same table.

Then you do "synths = nil." That instruction erases "table 1" from the synths board.

What happened to the ~tempSynthB board? NOTHING. It still points to table 1.

What happened to the array on table 1? NOTHING. You erased one reference to the array, but didn't do anything to the array itself.

To remove the reference from ~tempSynthB, you'll have to do it specifically to that name. A variable is a reference to an object. A variable is never a proxy for another variable.

More simply:

a = 1;
b = a;

b = nil;

Now, what do you expect 'a' to be?

hjh
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nil an array as argument

Jeroen
I see. Thanks a lot! Very clear.

cheers, jeroen



On 10.02.17 09:40, ddw_music wrote:
> Now, what do you expect 'a' to be?


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nil an array as argument

LightRate
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nil an array as argument

madamdata
correct me if I'm wrong, but wouldn't
~tempSynthB = ~freeSynths.value(~tempSynthB)
also work? that would set ~tempSynthB to the return value of
~freeSynths (nil), after freeing each individual synth.
It's messy and hides a lot of side effects inside what looks like a
declarative statement, but it'll do what you want I think.

On Fri, Feb 10, 2017 at 7:40 AM, LightRate <[hidden email]> wrote:

> Here are two possible options for rewriting ~freeSynths:
>
> The first requires that you pass ~freeSynths a symbol instead of a variable.
>
> ~freeSynths = { |synths| envirGet(synths) !? { envirGet(synths).flatten.do(
> _.free ); envirPut(synths, nil) } };
>
> ~freeSynths.(\tempSynthB);
>
> ~tempSynthB == nil; // true
>
> I wouldn't use this next one myself, but I'm including it to prove a
> concept.
>
> ~freeSynths = { |synths| synths !? { synths.flatten.do( _.free );
> envirPut(currentEnvironment.findKeyForValue(synths), nil) } };
>
> ~freeSynths.(~tempSynthB);
>
> This second option would not be wise if it's possible that another
> environment variable could share the same value as the 'synths' argument, or
> prove true for equality, because then the second ~freeSynths function might
> set /that/ variable to nil, and not the intended one.
>
>
>
> --
> View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/nil-an-array-as-argument-tp7630624p7630639.html
> Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nil an array as argument

LightRate
CONTENTS DELETED
The author has deleted this message.
Loading...