variables in a string - is that actually supported?
No. Haskell names (formal parameters for subprograms, or defined with let
in the current module, or import
ed from others) are never available at run-time (the compiler replaces them with addresses), but mini-notation is evaluated at run-time.
(for computer science students: missing the distinction between static semantics (e.g., name resolution, type checking) and dynamic semantics (evaluation) is the price we pay for allowing javascript and python at the start of the curriculum ... to which you might reply: but teaching LISP (and SCHEME) apparently worked fine 60 years ago ...)
From a Tidal user's standpoint, referring to Haskell names from mini-notation is a very natural thing to want - because the distinction between Haskell notation and mininotation appears, at first sight, like some implementation detail that only distracts from writing music.
(entering Innards area briefly) I can think of two "solutions", both ugly, none recommended:
- ask the current ghci session about the meaning of a name (programmatically, during evaluation)
- implement let/lambda calculus in mininotation. Don't! because next you want operators, precedences, libraries, types, ...
Oh, and I can't count, because there's also the option to use quasi quotes to make the compiler (ghci) parse application-specific concrete syntax (mininotation) (cf. 6.13. Template Haskell — Glasgow Haskell Compiler 9.4.4 User's Guide) Well ... perhaps? (Yesod Yesod Web Framework Book- Version 1.6 uses quasiquation heavily.)
Back to the immediate topic at hand - the solution shown above uses setF s e
to manually connect mininotation identifier s
to the value of the Haskell expression e
(which could be a Haskell name) that denotes a Pattern
. (There is no documentation for setF
and mininotation-^
?)
Forgive me for rambling, I've never used ^
before, so I find this interesting. E.g., I wondered:
why do these sound different?
tidal> do setI "x" "[c d e f]"; d1 $ n "[^x ^x/4] " # s "superpiano"
tidal> do setF "x" "[c d e f]"; d1 $ n "[^x ^x/4] " # s "superpiano"
does this work?
do setI "x" "[c d]"; setI "y" "^x e" ; d1 $ n "^y f" # s "superpiano"