zilch/docs/modules/ROOT/pages/zexp.adoc

31 lines
1 KiB
Text

= zexps
zexps, similar to g-expressions in Guix, are a way to generate
S-expressions that are tagged with store paths. The syntax in Zilch is inspired
by it, but has been developed separately.
A zexp is used similarly to a ``quasiquote``d value in Scheme, but has an extra type
of unquoting, called `zexp-unquote`, which unquotes a value such as a `++<store-path>++`
or another `zexp`.
Each `zexp` keeps track of the derivation outputs and store files it depends on,
similarly to how string context works in Nix:
[,scheme]
----
#~(foo bar #$baz)
; is identical to:
(zexp (foo bar (zexp-unquote baz)))
----
When a `zexp-unquote` (or its reader syntax, `#$`) is encountered, the value
contained in the `zexp` (or compatible object) is used as-is, with no
evaluation. It is possible to mix and match `zexp-unquote` with `unquote`,
allowing building e.g. dynamic strings from zexps. `zexp-unquote` is always
evaluated before `unquote` is.
[,scheme]
----
(define world ...)
(define hello #~("hello" ,(string-append "very " "cute" #$world)))
----