# How does cat behave with patterns that are longer than one cycle?

**URL:** <https://uzu.lurk.org/t/how-does-cat-behave-with-patterns-that-are-longer-than-one-cycle/3143>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [12 May 2021 23:11 UTC](https://uzu.lurk.org/t/how-does-cat-behave-with-patterns-that-are-longer-than-one-cycle/3143 "2021-05-12T23:11:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattia.paterna](https://uzu.lurk.org/user_avatar/uzu.lurk.org/mattia.paterna/32/112_2.png) [@mattia.paterna](https://uzu.lurk.org/u/mattia.paterna)\
**Post date:** [12 May 2021 23:11 UTC](https://uzu.lurk.org/t/how-does-cat-behave-with-patterns-that-are-longer-than-one-cycle/3143/1 "2021-05-12T23:11:35Z")

</div>

I have this snippet

```haskell
d5 $ (cat [
    slow 3 $ note "d'min a4'min'i g4'maj"
    , note "bf3'maj'i f3'maj'ii c4'maj'i"
    ]) # s "midi" # midichan "0" # legato 0.7

```

and I would expect as concatenation

- the first 3 chords, one per cycle
- the last 3 chords in one cycle
- grand total: _4_ cycles

But, Tidal gives me back a new pattern that is made of _6_ cycles, where the second pattern in the list gets interleaved ie.

```haskell
d'min -- first chord in first pattern
+ (bf3'maj'i f3'maj'ii c4'maj'i) -- second pattern
+ a4'min'i -- second chord in first pattern
+ (bf3'maj'i f3'maj'ii c4'maj'i) -- second pattern
+ g4'maj -- third chord in first pattern
+ (bf3'maj'i f3'maj'ii c4'maj'i) -- second pattern

```

How is that? Does `cat` concatenate a list of patterns only if the patterns are _all_ one-cycle long?  
And how I can achieve the expected result, shall I move to `seqPLoop`?

---

<div class="post-metadata">

**Author:** ![bgold](https://uzu.lurk.org/user_avatar/uzu.lurk.org/bgold/32/383_2.png) [@bgold](https://uzu.lurk.org/u/bgold)\
**Post date:** [13 May 2021 01:56 UTC](https://uzu.lurk.org/t/how-does-cat-behave-with-patterns-that-are-longer-than-one-cycle/3143/2 "2021-05-13T01:56:31Z")

</div>

Yes, `cat` basically concatenates if patterns are one-cycle. Or said in a different way - it takes one cycle of the first pattern, one cycle of the second pattern, one cycle of the third... until it gets to the end of the list, then starts with the second cycle of the first pattern and so on. In general, patterns don't know how "long" they are (they may never repeat!) so in your example there's no way for `cat` to know to repeat the first pattern three times.

So yes, `seqPLoop` might work for you, since you can tell it explicitly how long you want to run each pattern. Or you could use the mininotation:

```haskell
d1 $ note "<d'min a4'min'i g4'maj [bf3'maj'i f3'maj'ii c4'maj'i]>" ...

```

---

<div class="post-metadata">

**Author:** ![ben](https://uzu.lurk.org/user_avatar/uzu.lurk.org/ben/32/362_2.png) [@ben](https://uzu.lurk.org/u/ben)\
**Post date:** [13 May 2021 03:18 UTC](https://uzu.lurk.org/t/how-does-cat-behave-with-patterns-that-are-longer-than-one-cycle/3143/3 "2021-05-13T03:18:10Z")

</div>

Wouldn't `append` also work?

---

<div class="post-metadata">

**Author:** ![yaxu](https://uzu.lurk.org/user_avatar/uzu.lurk.org/yaxu/32/2_2.png) [@yaxu](https://uzu.lurk.org/u/yaxu)\
**Post date:** [13 May 2021 07:20 UTC](https://uzu.lurk.org/t/how-does-cat-behave-with-patterns-that-are-longer-than-one-cycle/3143/4 "2021-05-13T07:20:19Z")

</div>

`append` works the same way as `cat`, it's defined like this: `append a b = cat [a,b]`

---

<div class="post-metadata">

**Author:** ![mattia.paterna](https://uzu.lurk.org/user_avatar/uzu.lurk.org/mattia.paterna/32/112_2.png) [@mattia.paterna](https://uzu.lurk.org/u/mattia.paterna)\
**Post date:** [13 May 2021 10:24 UTC](https://uzu.lurk.org/t/how-does-cat-behave-with-patterns-that-are-longer-than-one-cycle/3143/5 "2021-05-13T10:24:23Z")

</div>

Thanks @bgold, you're making my days recently!

> [@bgold](#):
>
> patterns don't know how "long" they are

I am interested in knowing a bit more about what you wrote above if you can elaborate?

---

<div class="post-metadata">

**Author:** ![bgold](https://uzu.lurk.org/user_avatar/uzu.lurk.org/bgold/32/383_2.png) [@bgold](https://uzu.lurk.org/u/bgold)\
**Post date:** [13 May 2021 14:24 UTC](https://uzu.lurk.org/t/how-does-cat-behave-with-patterns-that-are-longer-than-one-cycle/3143/6 "2021-05-13T14:24:00Z")

</div>

> [@mattia.paterna](#):
>
> I am interested in knowing a bit more about what you wrote above if you can elaborate?

This gets into the guts a bit, but deep down a Pattern is really just(1) a function where the input is a timespan (called an "Arc" in Tidal) and the output is a list of Events that occur during that timespan. There's no info on whether it repeats or not, or how "long" the pattern is. In fact, patterns like `rand` should basically never repeat, but even with a pattern like `("[0.25 0.5]/3" ~>) $ iter 4 $ s "{bd sn [cp cp]}%5"` ... how long until it repeats? I have no idea, and it'd be a bit of a math puzzle to figure out. Fortunately, I don't need to, and neither does Tidal - it just asks for events during timespans.

There is _one_ slightly special length of time, which is just the "unit" we choose to use when we count - a cycle. So functions like `rev` and `cat` can be (and are) defined to work with patterns one cycle at a time. But if you have some other timespan in mind you're going to need to specify it one way or another, by writing it out explicitly in the mininotation or specifying it as an argument to something like `seqPLoop`.

This is related to a kind of mantra I have to repeat to myself often: Patterns Are Not Lists. It's easy to think of them as being _like_ lists, but that can be deceptive - lists have a length, a clear way to index their elements, an obvious well-ordering, etc. None of those are true for Patterns.

_(1) OK, nowadays Patterns have a bit of extra stuff attached to them but this is effectively true 99% of the time._
