From 7f64b4262ee7c71c6fe2593cd00b5606a14a8155 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Thu, 26 Dec 2019 21:33:42 -0500 Subject: Add (net ricketyspace sicp two thirtynine). * net/ricketyspace/sicp/two/thirtynine.scm: New file. --- net/ricketyspace/sicp/two/thirtynine.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 net/ricketyspace/sicp/two/thirtynine.scm (limited to 'net') diff --git a/net/ricketyspace/sicp/two/thirtynine.scm b/net/ricketyspace/sicp/two/thirtynine.scm new file mode 100644 index 0000000..8c05587 --- /dev/null +++ b/net/ricketyspace/sicp/two/thirtynine.scm @@ -0,0 +1,22 @@ +;;;; License: CC0-1.0 + +(define-module (net ricketyspace sicp two thirtynine) + #:use-module (net ricketyspace sicp two thirtyeight) + #:export (reverse-fr + reverse-fl)) + +(define (reverse-fr sequence) + (fold-right (lambda (x y) (append y (list x))) '() sequence)) + +(define (reverse-fl sequence) + (fold-left (lambda (x y) (append (list y) x)) '() sequence)) + +;;; +;;; Guile REPL +;;; +;;; scheme@(guile-user)> ,re (net ricketyspace sicp two thirtynine) +;;; scheme@(guile-user)> (reverse-fr '(1 2 3 4 5 6)) +;;; $8 = (6 5 4 3 2 1) +;;; scheme@(guile-user)> (reverse-fl '(1 2 3 4 5 6)) +;;; $9 = (6 5 4 3 2 1) +;;; -- cgit v1.2.3