diff options
author | rsiddharth <s@ricketyspace.net> | 2019-06-22 15:46:35 -0400 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2019-06-22 15:46:35 -0400 |
commit | d548d2a4d08896dfd8d55e9909cebcb744234947 (patch) | |
tree | 8dab9c39e974617a2fa6bc8cebf0ffa3a8586119 /net | |
parent | 5dc212c708d960580ab5fd285720b42ee65ed8a1 (diff) |
net: Add (net rickteyspace sicp two twentyseven).
Diffstat (limited to 'net')
-rw-r--r-- | net/ricketyspace/sicp/two/twentyseven.scm | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/two/twentyseven.scm b/net/ricketyspace/sicp/two/twentyseven.scm new file mode 100644 index 0000000..eea04bd --- /dev/null +++ b/net/ricketyspace/sicp/two/twentyseven.scm @@ -0,0 +1,30 @@ +;;;; License: CC0-1.0 + +(define-module (net ricketyspace sicp two twentyseven) + #:export (sicp-deep-reverse)) + +(define (sicp-append list1 list2) + (if (null? list1) + list2 + (cons (car list1) (sicp-append (cdr list1) list2)))) + +(define (sicp-deep-reverse items) + (cond ((null? items) '()) + ((pair? (car items)) + (sicp-append (sicp-deep-reverse (cdr items)) + (list (sicp-deep-reverse (car items))))) + (else + (sicp-append (sicp-deep-reverse (cdr items)) + (list (car items)))))) + +;;; Guile REPL + +;;; scheme@(guile-user)> ,use (net ricketyspace sicp two twentyseven) +;;; scheme@(guile-user)> (sicp-deep-reverse '((1 2 3) (4 5 6))) +;;; $27 = ((6 5 4) (3 2 1)) +;;; scheme@(guile-user)> (sicp-deep-reverse '(1 (4 5 6))) +;;; $28 = ((6 5 4) 1) +;;; scheme@(guile-user)> (sicp-deep-reverse '(1 (6))) +;;; $29 = ((6) 1) +;;; scheme@(guile-user)> (sicp-deep-reverse '(1 2 3 4 5 6)) +;;; $30 = (6 5 4 3 2 1) |