Hello everyone,
I’ve been struggling to understand why bigger than smaller than works perfectly in the below example:
(
p = Pbind(
\degree, Pif(Pseq((0.0,0.1..1.1), inf).trace < 0.6, Pwhite(-7, 0, inf), Pwhite(7, 14, inf)),
\dur, 0.25
).play;
)
p.stop;
but equation just wouldn’t return true ever:
(
p = Pbind(
\degree, Pif(Pseq((0.0,0.1..1.1), inf).trace == 0.6, Pwhite(-7, 0, inf), Pwhite(7, 14, inf)),
\dur, 0.25
).play;
)
p.stop;
I tried to test whether it’s an equality vs. identity problem, but I don’t understand why <,>,<=,>= does not return the same result as ==
Any advice, pointers, guide on why this is the case would be much appreciated!
TL;DR: use the |==|
operator.
That’s indeed a subtle issue. Here’s the relevant passage in the AbstractFunction
help file:
NOTE: The comparison operators <
, <=
, >
and >=
automatically perform function composition, as does *
in the example above.
Equality comparisons have two possible meanings: to compare the objects as they exist right now, or a composite operator that will evaluate the operands in the future and check the equality of those results. Both are needed at different times, and are supported by different operators: ==
for an immediate equality check (which always returns a Boolean result), or |==|
for a “lazy” equality operator to be performed later.
https://doc.sccode.org/Classes/AbstractFunction.html#Function%20Composition