Pbit / Pfbit
"It is not A;
it is not non-A;
it is both A and non-A;
and it is neither A nor non-A."
Pbit.hqx classes: Pbit/Pbit2/Pfbit/Pfbit2
//returns the bitvalues of the numbers from back to front contained in the list.
//Julian Rohrhuber 2000/5
Pbit : ListPattern {
asStream {
^Routine.new({ arg inval;
repeats.do({
list.do({ arg item;
var bit;
while({ item > 0}, {
bit = if(item % 2 == 0, { 0 }, { 1 });
item = item div: 2;
bit.embedInStream(inval)
})
})
})
})
}
}
___
-> James McCartney wrote:
You should only use embedInStream if there is possibly an embedded stream.
Since you are turning whatever is in the list into a zero or one then it
can't be a stream. Thus you do not need embedInStream and yield is more
efficient. also the correct usage would have been:
inval = item.embedInStream(inval);
(The assignment is important because that is where the new event comes in.)
Pbit : ListPattern {
asStream {
^Routine.new({ arg inval;
repeats.do({
list.do({ arg item;
var bit;
while({ item > 0}, {
bit = item & 1;
item = item +>> 1;
bit.yield;
})
})
})
})
}
}
//as I wanted to use any input stream, I wrote the following class:
//filters a stram of integers into bit values
//jr 3/01
Pfbit : FilterPattern {
asStream {
^Routine({
var stream, bit, item;
stream = pattern.asStream;
loop({
item = stream.next;
if(item.notNil, {
while({ item > 0}, {
bit = item & 1;
item = item +>> 1;
bit.yield;
})
}, {
nil.alwaysYield
});
})
})
}
}
Links to this Page
- Public Library 3 last edited on 27 October 2006 at 9:41 pm by host81-159-217-15.range81-159.btcentralplus.com
- enter. last edited on 29 January 2003 at 10:46 pm by 203.14.169.19
- recent contributions (2003-2004) last edited on 14 March 2005 at 3:50 pm by max1-207.dialin.uni-hamburg.de
- Public Library SC2 last edited on 2 March 2005 at 2:20 pm by max2-223.dialin.uni-hamburg.de
- Public Library last edited on 26 June 2008 at 10:06 am by adsl-76-254-22-46.dsl.pltn13.sbcglobal.net