Last active
August 29, 2015 14:20
-
-
Save beoliver/754b8d42eed03df848e9 to your computer and use it in GitHub Desktop.
Scheme set-nth!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require r5rs) | |
(define (set-nth! n xs x) | |
(cond ((null? xs) (error "index out of bounds")) | |
((eq? n 0) (set-car! xs x)) | |
(#t (set-nth! (- n 1) (cdr xs) x)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment