mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 05:18:07 -05:00
doc: Mention gexps in the "Scheme Crash Course".
* doc/guix-cookbook.texi (A Scheme Crash Course): Add note on gexps.
This commit is contained in:
parent
ff4f5a725e
commit
a33a335c89
1 changed files with 40 additions and 7 deletions
|
@ -234,10 +234,11 @@ A list structure can be created with the @code{list} procedure:
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
@item
|
@item
|
||||||
The @dfn{quote} disables evaluation of a parenthesized expression: the
|
@cindex S-expression
|
||||||
first term is not called over the other terms (@pxref{Expression Syntax,
|
The @dfn{quote} disables evaluation of a parenthesized expression, also
|
||||||
quote,, guile, GNU Guile Reference Manual}). Thus it effectively
|
called an S-expression or ``s-exp'': the first term is not called over
|
||||||
returns a list of terms.
|
the other terms (@pxref{Expression Syntax, quote,, guile, GNU Guile
|
||||||
|
Reference Manual}). Thus it effectively returns a list of terms.
|
||||||
|
|
||||||
@lisp
|
@lisp
|
||||||
'(display (string-append "Hello " "Guix" "\n"))
|
'(display (string-append "Hello " "Guix" "\n"))
|
||||||
|
@ -248,9 +249,10 @@ returns a list of terms.
|
||||||
@end lisp
|
@end lisp
|
||||||
|
|
||||||
@item
|
@item
|
||||||
The @dfn{quasiquote} disables evaluation of a parenthesized expression
|
The @code{quasiquote} (@code{`}, a backquote) disables evaluation of a
|
||||||
until @dfn{unquote} (a comma) re-enables it. Thus it provides us with
|
parenthesized expression until @code{unquote} (@code{,}, a comma)
|
||||||
fine-grained control over what is evaluated and what is not.
|
re-enables it. Thus it provides us with fine-grained control over what
|
||||||
|
is evaluated and what is not.
|
||||||
|
|
||||||
@lisp
|
@lisp
|
||||||
`(2 a 5 7 (2 ,a 5 ,(+ a 4)))
|
`(2 a 5 7 (2 ,a 5 ,(+ a 4)))
|
||||||
|
@ -260,6 +262,37 @@ fine-grained control over what is evaluated and what is not.
|
||||||
Note that the above result is a list of mixed elements: numbers, symbols (here
|
Note that the above result is a list of mixed elements: numbers, symbols (here
|
||||||
@code{a}) and the last element is a list itself.
|
@code{a}) and the last element is a list itself.
|
||||||
|
|
||||||
|
@item
|
||||||
|
@cindex G-expressions, syntax
|
||||||
|
@cindex gexps, syntax
|
||||||
|
@findex #~
|
||||||
|
@findex #$
|
||||||
|
@findex gexp
|
||||||
|
@findex ungexp
|
||||||
|
Guix defines a variant of S-expressions on steroids called
|
||||||
|
@dfn{G-expressions} or ``gexps'', which come with a variant of
|
||||||
|
@code{quasiquote} and @code{unquote}: @code{#~} (or @code{gexp}) and
|
||||||
|
@code{#$} (or @code{ungexp}). They let you @emph{stage code for later
|
||||||
|
execution}.
|
||||||
|
|
||||||
|
For example, you'll encounter gexps in some package definitions where
|
||||||
|
they provide code to be executed during the package build process. They
|
||||||
|
look like this:
|
||||||
|
|
||||||
|
@lisp
|
||||||
|
;; Below is a G-expression representing staged code.
|
||||||
|
#~(begin
|
||||||
|
;; Invoke 'ls' from the package defined by the 'coreutils'
|
||||||
|
;; variable.
|
||||||
|
(system* #$(file-append coreutils "/bin/ls") "-l")
|
||||||
|
|
||||||
|
;; Create this package's output directory.
|
||||||
|
(mkdir #$output))
|
||||||
|
@end lisp
|
||||||
|
|
||||||
|
@xref{G-Expressions,,, guix, GNU Guix Reference Manual}, for more on
|
||||||
|
gexps.
|
||||||
|
|
||||||
@item
|
@item
|
||||||
Multiple variables can be named locally with @code{let} (@pxref{Local
|
Multiple variables can be named locally with @code{let} (@pxref{Local
|
||||||
Bindings,,, guile, GNU Guile Reference Manual}):
|
Bindings,,, guile, GNU Guile Reference Manual}):
|
||||||
|
|
Loading…
Reference in a new issue