shreds, namespace, functions, classes, etc
Dear list,
Shreds are objects (of type Shred) and functions aren't objects. This is all
good and well but it gets harder when we spork a function and the function
becomes a Shred and hence a Object. Consider this;
------------------------
fun void tester()
{
"boom" => string beep;
while(1)
{
<<<beep>>>;
second => now;
}
}
spork ~ tester() @=> Shred foo;
5::second => now;
"clik" => foo.beep; //this doesn't work
day=> now;
----------------------------------------
It's not so clear to me *why* the offending line doesn't work. Maybe I'm
misunderstanding something or making a syntax error but I think that what we
are seeing here is a loss of namespace that would be useful and I don't
understand why this happens.
I also tried stuff along these lines;
----------------------
class Bar extends Shred
{
//stuff including variables and a constructor
}
------------------------------
If I do that I can instantiate a "Bar" but all it does is run it's
constructor; I can't manage to spork a Bar or assign a sporked shred to a
Bar. I can also make a array of Bar's but all that gets me is the
constructor running;
---------------------------
class Bar extends Shred
{
static int number;
<<
Hello,
I think it's not so much a question of 'what a shred is', as a more general
issue of the scope of variables that are declared within a function (ie,
they are not accessible outside the scope of said function). I'm about to
leave my house, and not feeling quite clear enough to explain more
completely, but I hope that's enough to point you in the right direction.
Cheers,
Peter
On Nov 15, 2007 4:46 PM, Kassen
Dear list,
Shreds are objects (of type Shred) and functions aren't objects. This is all good and well but it gets harder when we spork a function and the function becomes a Shred and hence a Object. Consider this;
------------------------ fun void tester() { "boom" => string beep; while(1) { <<<beep>>>; second => now; } }
spork ~ tester() @=> Shred foo; 5::second => now;
"clik" => foo.beep; //this doesn't work
day=> now; ----------------------------------------
It's not so clear to me *why* the offending line doesn't work. Maybe I'm misunderstanding something or making a syntax error but I think that what we are seeing here is a loss of namespace that would be useful and I don't understand why this happens.
I also tried stuff along these lines;
---------------------- class Bar extends Shred { //stuff including variables and a constructor } ------------------------------
If I do that I can instantiate a "Bar" but all it does is run it's constructor; I can't manage to spork a Bar or assign a sporked shred to a Bar. I can also make a array of Bar's but all that gets me is the constructor running;
--------------------------- class Bar extends Shred { static int number; <<
>>; } //print a series of numbers, no shreds in sight Bar array[5]; ----------------------------------
So, now I'm quite happy I said so many times that there are no "stupid n00b questions" because now it's my turn to ask exactly what a "Shred" is because I'm starting to feel like I have no idea. :¬)
Could somebody please explain to me exactly what's going on here?
Yours, Kas.
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
On 11/15/07, Peter Todd
Hello,
I think it's not so much a question of 'what a shred is', as a more general issue of the scope of variables that are declared within a function (ie, they are not accessible outside the scope of said function). I'm about to leave my house, and not feeling quite clear enough to explain more completely, but I hope that's enough to point you in the right direction.
Yes, I know variables declared within a function belong to that function and can't be adressed from the outside but member variables of *objects* can be adressed from the outside and when sporking the function becomes a object. With all due respect I do think there are some big questions here about "what a Shred is". I can execute the following; ------------------ Shred foo[3]; foo[0].exit(); ------------------------ This is quite mysterious to me, here a "Shred" (object) that's not a "shred" (sub-process) can "exit". Those two lines don't generate any errors, apparently they are fine but I have no idea what they do. Yours, Kas.
Hmmmmm. more weirdness;
-----------------------------
2 => int n;
Shred foo[n];
while(1)
{
<<
Hi!
----------------------------- 2 => int n;
Shred foo[n];
while(1) { <<
>>; second => now; } ------------------------------- Run that a few times for various values for n. Something very weird is going on here, -1266432768 seems like a very odd number as a shred id, especially when the VM monitor (running these in the mini) reports only a single shred.
This is bug, where the internal ID is uninitialized for user instantiated Shred instances. This has been fixed in CVS (unsporked shreds id default to 0). However, it brings up the bigger question of what this user created Shred might be used for, since currently, there is no facility to spork from these Shred objects (at the moment, Shred instances are internally created and can be accessed afterwards). For now, perhaps it makes sense to disable Shred instantiation from code? Thoughts? Best, Ge!
On 19/11/2007, Ge Wang
Hi!
Hi Ge! This is bug, where the internal ID is uninitialized for user instantiated
Shred instances. This has been fixed in CVS (unsporked shreds id default to 0).
Very good! I now see why normal shreds don't start counting at 0 like everything else, good solution. However, it brings up the bigger question of what this user
created Shred might be used for, since currently, there is no facility to spork from these Shred objects (at the moment, Shred instances are internally created and can be accessed afterwards). For now, perhaps it makes sense to disable Shred instantiation from code? Thoughts?
Yes, I admit I have no real use for them right now but if spork ~ my_function() @=> Shred foo; is useful (and I think it is, giving shreds names might lead to more readable code if we are dealing with a situation where we need to remove shreds from the VM) then I'd say creating a array of empty Shred objects would be useful too. We could assign shreds to them as they get sporked and deal with larger numbers of shreds with less efford. I could imagine this getting useful if we have shreds that represent something like synth voices, we know how many the CPU can take and we want some sort of voice management or something. How useful this is depends more or less on the member functions the Shred object has. .exit() and .id() were easy to assume but are there more? The documentation is rather vague about that class, aside from noting it exists. class Super_shred extends Shred { //blahblah} ....on the other hand gives us a object that can't be used for anything right now so I would be fine with disabling that until somebody has a good idea on how to use a thing like that. Not the most fruitful of experiments, this, so far, but I do quite like the idea of making the variables that the function had accessible as members of the object that it becomes once sporked. How hard would that be to implement? It's not worth a lot of work as we can get equivalent functionality by using a class and sporking from there but as a concept it makes sense to me, particularly with regard to inter-shred communication at low syntax-overhead. I'd say that's a topic that does deserve our attention in the coming time but perhaps there are better ideas. Also, that whole "scope" thing to the --shell, is that a plan that has since been discarded and and should I stop lusting after it? That sort of functionality is the one thing I envy our friends in the SuperCollider world over. I've been talking about that rather a lot and if there was some sort of outline like say "we won't do it for now" or -say- "after garbage collection" I could relax about it on the list/ WiKi, I'm sure people are quite bored with me going "I want that, preferably graphically in the Mini" all the time by now :¬). Thanks for your help, hope you are well, Kas.
On 19/11/2007, AlgoMantra
oh shit, i just swallowed a whole peg of rum.
Could be good? http://xkcd.com/323/ Cheers! Kas.
ROTFL!!!!!!!!!!!!
On 19/11/2007, AlgoMantra
wrote: oh shit, i just swallowed a whole peg of rum.
Could be good? http://xkcd.com/323/
Cheers! Kas.
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- ------- -.- 1/f ))) --. ------- ... http://www.algomantra.com
On 19/11/2007, Ge Wang
This is bug, where the internal ID is uninitialized for user instantiated Shred instances. This has been fixed in CVS (unsporked shreds id default to 0).
One more thing, perhaps you already implemented this but in this code;
----------------------------
Shred foo;
spork ~ test() @=> foo;
second => now;
<<
Hi again Kassen and all!
------------------ Shred foo[3];
foo[0].exit(); ------------------------
This is quite mysterious to me, here a "Shred" (object) that's not a "shred" (sub-process) can "exit". Those two lines don't generate any errors, apparently they are fine but I have no idea what they do.
Yup, this part of the current state of things is confusing. The Shred object is meant to represent a concurrent process/shred, so we'd have means to talk about and communicate with various shreds. Instantiating a Shred in code (e.g., Shred foo;) simply makes one of these placeholder objects but no actual new shred is sporked in the VM. And currently, there really isn't anything one can do with code-spawned Shred objects. In short, instantiating Shred's don't really create new actual VM shreds - the Shred type is there to deal with Shred internally created when spork ~ (and other sporking mechanisms) are invoked. I hope this helps? Best, Ge!
participants (4)
-
AlgoMantra
-
Ge Wang
-
Kassen
-
Peter Todd