guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/06: doc: Illustrate procedures that return packages.


From: guix-commits
Subject: 03/06: doc: Illustrate procedures that return packages.
Date: Tue, 3 Nov 2020 05:58:42 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit 1566cb05cd2c58e4bd8c6337169b0560025512d8
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Tue Nov 3 11:01:37 2020 +0100

    doc: Illustrate procedures that return packages.
    
    * doc/guix.texi (Defining Package Variants): Illustrate procedures that
    return packages.
---
 doc/guix.texi | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index a20e54f..b7f1bc1 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,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]