Skip to content

Commit 595130d

Browse files
committed
notes
1 parent 76f8a6d commit 595130d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

notes/guix-guile-nix/guile.scrbl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,26 @@
264264

265265
@block{@block-name{Various code snippets}
266266
@lisp{
267+
(use-modules (ice-9 match))
268+
(match (list 1 2) [(f s) (list "f: " f "s: " s)]) ; => ("f: " 1 "s: " 2)
269+
270+
(use-modules (srfi srfi-9)) ; define-record-type
271+
(use-modules (ice-9 match))
272+
(let ()
273+
(define-record-type person
274+
(make-person name friends)
275+
person?
276+
(name person-name)
277+
(friends person-friends))
278+
;;
279+
(letrec ((alice (make-person "Alice" (delay (list bob))))
280+
(bob (make-person "Bob" (delay (list alice)))))
281+
(match alice
282+
(($ person name (= force (($ person "Bob"))))
283+
(list 'friend-of-bob name))
284+
(_ #f))))
285+
;; => (friend-of-bob "Alice")
286+
267287
(use-modules) (srfi srfi-13) ;; String Library
268288
(string->number "1") ;; => 1
269289
(string->number* "1") ;; from (guix ui)

0 commit comments

Comments
 (0)