Pattern in Pattern

let blue = "< 0 1 0 1 ~ ~ >"

let red = "[1 1 blue 0 <0 ~ ~ 0 1  > <1 ~ 0 ~ > <1 ~ ~ > blue]"

I'm obviously doing something wrong here. I'm trying to embed the blue patter inside the red pattern. Any idea how to make this work? Thank you.

Edit: fixed the code

I'm not sure if I understand the question: how do you want the blue to be embedded in red? Should it be dropped in where you have the ppp?

Ah sorry I copy pasted in haste:

let blue = "< 0 1 0 1 ~ ~ >"

let red = "[1 1 blue 0 <0 ~ ~ 0 1 > <1 ~ 0 ~ > <1 ~ ~ > blue]"

Like so.

Okay so there's a few ways to do this. You can do it with fastcat or squeeze if you're willing to break everything apart into the right weightings so like

(squeeze "0 1 2 3 4 5 6 2" $ ["1","1",blue,"0", "<0 ~ ~ 0 1 >", "<1 ~ 0 ~ >", "<1 ~ ~ >"])

can work as can

(fastcat $ ["1","1",blue,"0", "<0 ~ ~ 0 1 >", "<1 ~ 0 ~ >", "<1 ~ ~ >",blue])

but if you want just literal string concatenation then you can always just do

red = parseBP_E $ "[1 1 " ++ blue ++ "0 <0 ~ ~ 0 1 > <1 ~ 0 ~ > <1 ~ ~ >" ++ blue ++ "]"

which I personally kinda like just because it builds exactly what you think it would build by treating the strings as strings until you turn it into a pattern

I don't know have I missed an even more clever way of getting all the weightings right but keeping the code simple?

2 Likes

Ok nice, looks promising but gives me and error:

Variable not in scope: blue :: Pattern a

Just nevermind for a moment too because I was thinking way too literally and the weighting is wrong.

I fixed my answer and as a bonus you get at least three ways to do this

1 Like

Oh beautiful and elegant!! Thank you very much for the help!