Created
July 21, 2016 14:42
-
-
Save oneandoneis2/c43b77f468454637a1b09ebaf34150b8 to your computer and use it in GitHub Desktop.
Why would you want to return more than one value from a function when you have this simple alternative??
This file contains 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
(define (split src fn) | |
(if (null? src) | |
(fn '() '()) | |
(split (cdr src) | |
(lambda (letters numbers) | |
(let ((next (car src))) | |
(if (number? next) | |
(fn letters (cons next numbers)) | |
(fn (cons next letters) numbers))))))) | |
1 ]=> (split (list 1 2 'a 'b 3 'c 'd 'e 4 5 6 'f) list) | |
((a b c d e f) (1 2 3 4 5 6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment