Equation doesn't work as boolean in patterns

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

Sorry for the very late response, but thank you for your suggestion for replacing == with |==|

However, when I do so:

(
p = Pbind(
	\degree, Pif(
		condition: Pseq((0.0,0.1..1.1), inf) |==| 0.6,
		iftrue: Pwhite(-7, 0, inf), 
		iffalse: Pwhite(7, 14, inf)),
    \dur, 0.25
).play;
)

SC 3.10.x still returns an error message, which says:

  1. that the |==| is not understood
  2. and the receiver of this error message is the Pseq

The error message looks like this:

ERROR: Message ‘|==|’ not understood.
RECEIVER:
Instance of Pseq { (0x1332225e8, gc=C8, fmt=00, flg=00, set=02)
instance variables [3]
list : instance of Array (0x122a62938, size=12, set=4)
repeats : Float inf 00000000 7FF00000
offset : Integer 0
}
ARGS:
Float 0.600000 33333333 3FE33333
CALL STACK:
DoesNotUnderstandError:reportError
arg this =
Nil:handleError
arg this = nil
arg error =
Thread:handleError
arg this =
arg error =
Object:throw
arg this =
Object:doesNotUnderstand
arg this =
arg selector = ‘|==|’
arg args = [*1]
< closed FunctionDef > (no arguments or variables)
Interpreter:interpretPrintCmdLine
arg this =
var res = nil
var func =
var code = “(
p = Pbind(
\degree, Pif(
…”
var doc = nil
var ideClass =
Process:interpretPrintCmdLine
arg this =
^^ The preceding error dump is for ERROR: Message ‘|==|’ not understood.
RECEIVER: a Pseq

I tried to make sense of the Help file you quoted and linked, but unfortunately I don’t fully understand

  1. how the “lazy” equality can be applied to the context of patterns
  2. and how can I make equation work in that context

What I could think of is that the Pseq((0.0,0.1…1.1), inf) needs to be “evaluated” or the values it generates need to be “converted” into a type of data that the |==| inside the Pif can make sense of.
But I’m not sure whether this is a wrong direction towards the solution or if it’s not a wrong direction how am I supposed to do that?

:thinking:

|==| is a relatively recent addition. I forget which version introduced it but 3.10 is a bit on the old side.

If you’re reading documentation for 3.12.2 online but using 3.10.x, then it’s possible, if the method was added in between those versions, that you could see the help online but not find the method in the earlier version.

hjh

1 Like