summary refs log tree commit diff
path: root/doc/guix.texi
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-11-03 11:01:37 +0100
committerLudovic Courtès <ludo@gnu.org>2020-11-03 11:58:01 +0100
commit1566cb05cd2c58e4bd8c6337169b0560025512d8 (patch)
tree46b41b1828c9fc107be541e836025414943c456b /doc/guix.texi
parentdbf572e0077fba3a67c404d830da38861dda4587 (diff)
downloadguix-1566cb05cd2c58e4bd8c6337169b0560025512d8.tar.gz
doc: Illustrate procedures that return packages.
* doc/guix.texi (Defining Package Variants): Illustrate procedures that
return packages.
Diffstat (limited to 'doc/guix.texi')
-rw-r--r--doc/guix.texi37
1 files changed, 35 insertions, 2 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index a20e54f8ae..b7f1bc1f00 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -6908,11 +6908,44 @@ The @code{alist-delete} call above removes the tuple from the
 (@pxref{SRFI-1 Association Lists,,, guile, GNU Guile Reference
 Manual}).
 
+In some cases, you may find it useful to write functions
+(``procedures'', in Scheme parlance) that return a package based on some
+parameters.  For example, consider the @code{luasocket} library for the
+Lua programming language.  We want to create @code{luasocket} packages
+for major versions of Lua.  One way to do that is to define a procedure
+that takes a Lua package and returns a @code{luasocket} package that
+depends on it:
+
+@lisp
+(define (make-lua-socket name lua)
+  ;; Return a luasocket package built with LUA.
+  (package
+    (name name)
+    (version "3.0")
+    ;; several fields omitted
+    (inputs
+     `(("lua" ,lua)))
+    (synopsis "Socket library for Lua")))
+
+(define-public lua5.1-socket
+  (make-lua-socket "lua5.1-socket" lua-5.1))
+
+(define-public lua5.2-socket
+  (make-lua-socket "lua5.2-socket" lua-5.2))
+@end lisp
+
+Here we have defined packages @code{lua5.1-socket} and
+@code{lua5.2-socket} by calling @code{make-lua-socket} with different
+arguments.  @xref{Procedures,,, guile, GNU Guile Reference Manual}, for
+more info on procedures.  Having top-level public definitions for these
+two packages means that they can be referred to from the command line
+(@pxref{Package Modules}).
+
 @cindex package transformations
 These are pretty simple package variants.  As a convenience, the
 @code{(guix transformations)} module provides a high-level interface
-that directly maps to package transformation options (@pxref{Package
-Transformation Options}):
+that directly maps to the more sophisticated package transformation
+options (@pxref{Package Transformation Options}):
 
 @deffn {Scheme Procedure} options->transformation @var{opts}
 Return a procedure that, when passed an object to build (package,