Can the "if" object evaluate symbols (strings) as input?

TY BOWMAN's icon

For example, I want to do...
if $s1 == hello then 1 else 0
I get errors when I try this.

The "if" help reference talks about using $s1 as a replacement value for $1 but that doesn't work either. What am I doing wrong?

I can get a symbol as the result of comparing two integers like below which seems odd that "if" can output symbols but can't take them as input.
if $i1 == 1 then hello else goodbye

So what's the easiest way to evaluate symbols?

broc's icon

[zl.compare hello]

Roman Thilenius's icon

$s1 points to a table object (see expr help)

TY BOWMAN's icon

Ok, so I have a patcher that uses zl compare to evaluate two symbols. Is that as simple as it can be?

Max Patch
Copy patch and select New From Clipboard in Max.

But now I want a logical OR comparison to more than one symbol.
For example,
if $i1== hello or $i1==hi then 1 else 0
This got more complex adding in zl sect. Is this as simple as it can be?

Max Patch
Copy patch and select New From Clipboard in Max.

I think Max is a masterful programming environment and I'll probably stick with it, however, I am surprised at how complex it is to do what otherwise would be very simple statements in a text based environment. The balance to that is, of course, it makes very complex things very simple. But how hard would it be to re-write the "if" object to evaluate symbols as input? Maybe it's possible to write a javascript object that does just that. I guess I'll try that next.

Roman Thilenius's icon

not hard, but if you allow an external to take inputs of different type, it would have to do a typ check at these inputs. and [if] is already slow enough. yet not as slow as things will get with javascript.

also, when you would add symbols to the if object, then you would have to take out its table funtionality.

btw, not long ago there was no zl.compare either and you´d have to do

zl union

zl len

to find out if symbols are equal or not.

and before there was zl ... you get the idea.

broc's icon

Your example with [zl sect] can be simplified.

Max Patch
Copy patch and select New From Clipboard in Max.

TY BOWMAN's icon

Roman and Broc,

Thanks to you both. This helps.