Teletype Array comparison

Does anyone know of any tricks for array comparison in teletype? Say have a pattern looks something like [0 10 20 30] and I want to run it through a conditional to check the entire value of the pattern. Naively, I could so something like:

IF NE P 0 10: break
IF NE P 1 20: break
IF NE P 2 30: break
IF NE P 3 40: break
;;;OK, it matches!

But this obviously blows 4 lines of code. Is there a shorter way to do this?

That code checks all four patterns’ current position–is this what you intend?

I’m having trouble coming up with a one-liner to do this… maybe it’s possible, with a loop and a variable, but it’s a bit of a puzzle.

Why do you need to check through a sequence of stored numbers like this? What’s the job?

That’s something for which a custom operator would be the ideal solution as it can be very easily and cleanly done in a very small amount of C/C++ code…

I’m not in front of my Teletype now but something like this should work though :

Note : in this example I compare the first X variables of pattern 1 with the first X variables of pattern 4, adjust as desired.

A 1; X 4
L 0 X: A AND A EQ PN 1 I PN 4 I

So we start with A being true (1) and for each index A only stays true if the patterns values are equal for that index. So at the end A is either 1 if the (sub)patterns are identical or 0 otherwise.

I’m not sure the whole second line fits or not, it’s 31 characters so probably ok.
It’s not optimal at all and keeps comparing even after one value differs but I guess that’s ok for Teletype scripts :slight_smile:

Edit : you can shave one character by using && instead of AND :
A 1; X 4
L 0 X: A && A == PN 1 I PN 4 I

2 Likes

Sorry, let me try that example again(I’m spit-balling at work).

We are looking to match a pattern: [0 10 20 30].

IF NE 0 PN 1 0: break
;; break if the 1st element in the pattern is not equal to 0

IF NE 10 PN 1 1: break
;;break if the 2nd element in the pattern is not equal to 10

IF NE 20 PN 1 2: break
;;break if the 3rd element in the pattern is not equal to 20

IF NE 30 PN 1 3: break
;;break if the 4th element in the pattern is not equal to 30

otherwise, they are equal :slight_smile:

Basically, I track the number of hits for a given instrument- say a kick drum in the first pattern.

So, [0 1 1 2] could mean, the kick triggered 0 times on the last 8th note, 1 time on the 8th note before that, 1 time on the 8th note before that, 2 times on the 8th note before that. Then I apply rules on this history to determine if I should trigger a snare for example.

I have gen~ code that does this pretty well but I prefer using teletype whenever possible as it is simpler.

Yeah that is perfect. Thank you kindly.

1 Like