Discussion:
looping/iterating back and forth?
Michael Zacherl
2014-10-02 21:26:04 UTC
Permalink
Hi, is there a more elegant/convenient/shorter… way for

j.do({
(0..n).do(
{|i| f.value(i)}
);
(n..0).do(
{|i| f.value(i)}
)
})

?

Thanks, Michael.

_______________________________________________
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/
vividsnow
2014-10-02 23:01:16 UTC
Permalink
looks like perl golf task, but in sclang )

{(..n).mirror do:f}!j
Post by Michael Zacherl
Hi, is there a more elegant/convenient/shorter… way for
j.do({
(0..n).do(
{|i| f.value(i)}
);
(n..0).do(
{|i| f.value(i)}
)
})
?
Thanks, Michael.
_______________________________________________
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/
_______________________________________________
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/
Daniel Mayer
2014-10-02 23:24:54 UTC
Permalink
Post by vividsnow
{(..n).mirror do:f}!j
The colon notation is nice here as it's really short !

Just two points: it should be mirror2 (repeating turning point)
and '!' means 'dup' so returns an Array, which is a bit different from 'do'
which returns the receiver, so if this is necessary in this context either stay with 'do'


(
j = 2;
n = 5;
f = _.postln;

j.do { (..n).mirror2 do: f }
)


or, if wanting to keep '!', a bit wasteful in terms of storage,
but with same number of non-space chars ...

(
j = 2;
n = 5;
f = _.postln;

{ (..n).mirror2 do: f }!j; j
)


But admittedly { ... } ! n
is a great notation -
so clear and short !
Also like to use it wherever possible.


Greetings

Daniel

-----------------------------
www.daniel-mayer.at
-----------------------------





_______________________________________________
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/
vividsnow
2014-10-02 23:45:48 UTC
Permalink
thanks for "mirror2" correction

originally wrote:

j collect: (..n).mirror reduce: '++' do: f

but then decided to shorten it )

indeed, sclang is very flexible&expressive!
Post by Daniel Mayer
Post by vividsnow
{(..n).mirror do:f}!j
The colon notation is nice here as it's really short !
Just two points: it should be mirror2 (repeating turning point)
and '!' means 'dup' so returns an Array, which is a bit different from 'do'
which returns the receiver, so if this is necessary in this context either stay with 'do'
(
j = 2;
n = 5;
f = _.postln;
j.do { (..n).mirror2 do: f }
)
or, if wanting to keep '!', a bit wasteful in terms of storage,
but with same number of non-space chars ...
(
j = 2;
n = 5;
f = _.postln;
{ (..n).mirror2 do: f }!j; j
)
But admittedly { ... } ! n
is a great notation -
so clear and short !
Also like to use it wherever possible.
Greetings
Daniel
-----------------------------
www.daniel-mayer.at
-----------------------------
_______________________________________________
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/
_______________________________________________
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/
Michael Zacherl
2014-10-03 01:00:22 UTC
Permalink
Post by vividsnow
thanks for "mirror2" correction
j collect: (..n).mirror reduce: '++' do: f
Thanks a lot, I was sure there was some more compact and indeed interesting notation.
In the case of 'do:', where does the index go, as in my original code?
Post by vividsnow
but then decided to shorten it )
indeed, sclang is very flexible&expressive!
:)
Post by vividsnow
Post by Daniel Mayer
Post by vividsnow
{(..n).mirror do:f}!j
The colon notation is nice here as it's really short !
Just two points: it should be mirror2 (repeating turning point)
and '!' means 'dup' so returns an Array, which is a bit different from 'do'
which returns the receiver, so if this is necessary in this context either stay with 'do'
(
j = 2;
n = 5;
f = _.postln;
j.do { (..n).mirror2 do: f }
)
or, if wanting to keep '!', a bit wasteful in terms of storage,
but with same number of non-space chars ...
(
j = 2;
n = 5;
f = _.postln;
{ (..n).mirror2 do: f }!j; j
)
But admittedly { ... } ! n
is a great notation -
so clear and short !
Also like to use it wherever possible.
--
http://mz.klingt.org


_______________________________________________
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/
vividsnow
2014-10-03 08:55:16 UTC
Permalink
since "f" is just a function, it isn't necessary to wrap it with another function to simply pass argument:
http://doc.sccode.org/Classes/Array.html#-do
Post by Michael Zacherl
Post by vividsnow
thanks for "mirror2" correction
j collect: (..n).mirror reduce: '++' do: f
Thanks a lot, I was sure there was some more compact and indeed interesting notation.
In the case of 'do:', where does the index go, as in my original code?
Post by vividsnow
but then decided to shorten it )
indeed, sclang is very flexible&expressive!
:)
Post by vividsnow
Post by Daniel Mayer
Post by vividsnow
{(..n).mirror do:f}!j
The colon notation is nice here as it's really short !
Just two points: it should be mirror2 (repeating turning point)
and '!' means 'dup' so returns an Array, which is a bit different from 'do'
which returns the receiver, so if this is necessary in this context either stay with 'do'
(
j = 2;
n = 5;
f = _.postln;
j.do { (..n).mirror2 do: f }
)
or, if wanting to keep '!', a bit wasteful in terms of storage,
but with same number of non-space chars ...
(
j = 2;
n = 5;
f = _.postln;
{ (..n).mirror2 do: f }!j; j
)
But admittedly { ... } ! n
is a great notation -
so clear and short !
Also like to use it wherever possible.
--
http://mz.klingt.org
_______________________________________________
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/
_______________________________________________
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/
Michael Zacherl
2014-10-03 10:33:20 UTC
Permalink
Michael Zacherl
2014-10-03 01:00:06 UTC
Permalink
Post by Daniel Mayer
Post by vividsnow
{(..n).mirror do:f}!j
The colon notation is nice here as it's really short !
Just two points: it should be mirror2 (repeating turning point)
good to know there's this option. in my current case .mirror would be just fine. ;)
Thanks!




--
http://mz.klingt.org


_______________________________________________
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/
Continue reading on narkive:
Search results for 'looping/iterating back and forth?' (Questions and Answers)
4
replies
visual basic help - pls?
started 2007-05-06 15:30:21 UTC
programming & design
Loading...