Discussion:
endless loop repeating function's value
konstantinos Vasilakos
2014-09-08 07:36:49 UTC
Permalink
Hi all, 


I was playing with some code this morning, and came across something accidentally peculiar, or at least something I wasn’t aware of in SC. If I execute this:


x = {
var name = [“K", "M", "N"].choose;
("hello " ++ name).postln;
x.value
};


x.value


It will start an endless loop of evaluating this function, is there any viable explanation to that?


— —
SC 3.7alpha | MacOS 10.9
FZ
2014-09-08 08:09:39 UTC
Permalink
good morning,

i think if you do x.value, your funcition » x « is again evaluating » x.value « as a simple recursion.
you'll get stuck in a loop, because you haven't formulated a condition on which your function stops evaluating itself.

solution could be:

///////////////////////////
x = {
var name = {["K", "M", "N"].choose};
100.do{ // this is your condition now.
("hello " ++ name.()).postln;
}
};

x.value
/////////////////////////


hope it helps.
florian
Post by konstantinos Vasilakos
Hi all,
x = {
var name = [“K", "M", "N"].choose;
("hello " ++ name).postln;
x.value
};
x.value
It will start an endless loop of evaluating this function, is there any viable explanation to that?
— —
SC 3.7alpha | MacOS 10.9
_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Loading...