diff options
author | EuAndreh <eu@euandre.org> | 2021-09-02 10:26:44 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-09-03 15:19:05 -0300 |
commit | d3822c5777d97e7381cc26f6ddd21369eba6b875 (patch) | |
tree | 8b2d44a053d050fa3874bf83e6036bbc15a81c62 | |
parent | aux/lib.sh: Add (diff) | |
download | euandre.org-d3822c5777d97e7381cc26f6ddd21369eba6b875.tar.gz euandre.org-d3822c5777d97e7381cc26f6ddd21369eba6b875.tar.xz |
pastebin: Auto-add _pastebins/2021-09-02-sicp-319.md
-rw-r--r-- | _pastebins/2021-09-02-sicp-exercise-3-19.md | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/_pastebins/2021-09-02-sicp-exercise-3-19.md b/_pastebins/2021-09-02-sicp-exercise-3-19.md new file mode 100644 index 0000000..75ee346 --- /dev/null +++ b/_pastebins/2021-09-02-sicp-exercise-3-19.md @@ -0,0 +1,42 @@ +--- + +title: SICP exercise 3.19 + +date: 2021-09-02 + +layout: post + +lang: en + +ref: sicp-exercise-3-19 + +--- + +```scheme +(define (cycle? l) + (define (rec l x) + (cond + ((null? x) false) + ((eq? l x) true) + (true (rec l (cdr x))))) + (rec l (cdr l))) +``` + +Sample interactive session: + +```scheme +scheme@(guile-user)> (define true #t) +scheme@(guile-user)> (define false #f) +scheme@(guile-user)> +(define (cycle? l) + (define (rec l x) + (cond + ((null? x) false) + ((eq? l x) true) + (true (rec l (cdr x))))) + (rec l (cdr l))) +scheme@(guile-user)> (cycle? '(1 2 3)) +$9 = #f +scheme@(guile-user)> (cycle? (make-cycle '(1 2 3))) +$10 = #t +``` |