Chaining functions / "threading macro" in Sonic?

I’m looking for the idiomatic Sonic Pi way to chain or thread a number of function calls together in a single expression.

Eg. in Clojure I’d use the threading macro.

(-> x (f) (g y) (h a b c))

Or in OO Ruby, I’d create a class and have a number of functions each modifying and returning self so I chain them like this

x.f().g(y).h(a,b,c)

What’s the right, idiomatic way of doing this in Sonic?

I originally tried using classes and objects. But I understand that Sam doesn’t want to support classes and OO, and thinks of Sonic as more like Clojure with a Ruby syntax. (Which is great, I love Clojure)

But what’s the equivalent of the threading macro?

3 Likes