# Struct, variables and mininotation

**URL:** <https://uzu.lurk.org/t/struct-variables-and-mininotation/3131>\
**Category:** TidalCycles\
**Tags:** questions\
**Created:** [9 May 2021 18:06 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131 "2021-05-09T18:06:11Z")\
**Posts on this page:** 10\
**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:** [9 May 2021 18:06 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/1 "2021-05-09T18:06:11Z")

</div>

The idea I have in mind is the following: suppose you start with a very simple rhythmic structure defined using `struct` and some mininotation:

```haskell
d1 $ struct "1!3 1@3 1@2" $ s "bd"

```

and later you want to parameterise the number of kick samples at the beginning of the pattern.  
To begin with, it could be generated by `irand`.

In my mind, it should look like this:

```haskell
do
    setF "kickStut" $ irand 16
    d1 $ struct "1!^kickStut 1@3 1@2" $ s "p_bd"

```

but of course, it does not work.

What am I doing wrong?

---

<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:** [9 May 2021 21:05 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/2 "2021-05-09T21:05:59Z")

</div>

I think it's just that the mininotation doesn't (yet) support patterns in the argument after `!`, just numbers. While I don't think it's exactly the same, you could get something similar to what you're trying to do with

```haskell
setB "kick" $ fast (irand 16) "t"
d1 $ struct "^kick 1@3 1@2" $ s "bd"

```

---

<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:** [11 May 2021 06:54 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/3 "2021-05-11T06:54:13Z")

</div>

Thank you @bgold!  
Two follow-up questions:

1. I do understand `setB "kick" $ fast (irand 16)` but not the `"t"`: what does it mean in the context?
2. how about variables: can I use normal variables inside the mininotation?

---

<div class="post-metadata">

**Author:** ![Francesco\_Corvi](https://uzu.lurk.org/user_avatar/uzu.lurk.org/francesco_corvi/32/2826_2.png) [@Francesco\_Corvi](https://uzu.lurk.org/u/Francesco_Corvi)\
**Post date:** [11 May 2021 08:54 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/4 "2021-05-11T08:54:07Z")

</div>

When using struct t=1 f=0 (which stands for true and false) since struct accepts booleans

---

<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:** [11 May 2021 09:10 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/5 "2021-05-11T09:10:37Z")

</div>

Thank you @Francesco_Corvi, what I mean is: what is `"t"`: is it `Pattern`, or string or?

---

<div class="post-metadata">

**Author:** ![Francesco\_Corvi](https://uzu.lurk.org/user_avatar/uzu.lurk.org/francesco_corvi/32/2826_2.png) [@Francesco\_Corvi](https://uzu.lurk.org/u/Francesco_Corvi)\
**Post date:** [11 May 2021 11:50 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/6 "2021-05-11T11:50:46Z")

</div>

It is a Pattern of booleans.

---

<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:** [11 May 2021 15:09 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/7 "2021-05-11T15:09:41Z")

</div>

Yeah, oops I mixed notation a bit there. Technically `struct` uses `Pattern Bool`, but you can represent booleans using `"1 0 0 1"` or `"t f f t"` and often Haskell will figure out that the first should be Bool rather than Int.

And as far as variables in the mininotation - I think it just comes down to that since a variable is a Pattern, you can use it anywhere in the mininotation that Patterns are accepted. So `d1 $ s "bd(^foo, 8)"` works (assuming "foo" has been set somewhere) because the Euclidean stuff accepts Patterns.

I think the places in mininotation that **don't** take patterns are after \_, @, !, or ?

---

<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:** [11 May 2021 16:36 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/8 "2021-05-11T16:36:20Z")

</div>

> [@bgold](#):
>
> Technically `struct` uses `Pattern Bool`, but you can represent booleans using `"1 0 0 1"` or `"t f f t"` and often Haskell will figure out that the first should be Bool rather than Int.

Thank you for the explanation @bgold and @Francesco_Corvi !  
I asked because I sometimes inspect the pattern and if I write:

```haskell
tidal> putStrLn . show $ fast 2 $ s "bd"

```

I know I will get:

```haskell
(0>½)|s: "bd"
(½>1)|s: "bd"

```

and when I tried this:

```haskell
tidal> putStrLn . show $ fast 2 "t"

```

I got an error:

```haskell
<interactive>:2:26: error:
    • No instance for (Enumerable ()) arising from the literal ‘"t"’
    • In the second argument of ‘fast’, namely ‘"t"’
      In the second argument of ‘($)’, namely ‘fast 2 "t"’
      In the expression: putStrLn . show $ fast 2 "t"

```

but then I realised how stupid I am, because I have to explicitly set that `"t"` is `Pattern Bool`!

```haskell
tidal> putStrLn . show $ fast 2 ("t" :: Pattern Bool)
(0>½)|True
(½>1)|True

```

and it works as expected 😄

* * *

> [@bgold](#):
>
> I think the places in mininotation that **don't** take patterns are after \_, @, !, or ?

It seems very much the case here, as I am not able to figure out how to use it - using brackets does not solve the problem and I get a complaint from the compiler 😕  
Perhaps a future option @yaxu?

---

<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:** [11 May 2021 21:45 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/9 "2021-05-11T21:45:07Z")

</div>

> [@mattia.paterna](#):
>
> > [@bgold](#):
> >
> > I think the places in mininotation that **don't** take patterns are after \_, @, !, or ?
> 
> It seems very much the case here, as I am not able to figure out how to use it - using brackets does not solve the problem and I get a complaint from the compiler 😕  
> Perhaps a future option @yaxu?

Yes, definitely worth creating an issue for these.. I'm not sure how tricky this would be to fix, one of those things that might take five minutes, or five days..

---

<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 09:25 UTC](https://uzu.lurk.org/t/struct-variables-and-mininotation/3131/10 "2021-05-12T09:25:18Z")

</div>

@yaxu just did it 🙂
