Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oneandoneis2/c43b77f468454637a1b09ebaf34150b8 to your computer and use it in GitHub Desktop.
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??
(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