Last active
August 29, 2015 14:01
-
-
Save dgellow/85a6c44375e2012ab6f1 to your computer and use it in GitHub Desktop.
A function to transform a list into a list of cons.
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
;; Example: | |
;; (part-cons '(1 2 3 4 5)) ;; => '((1 . 2) (3 . 4) (5)) | |
(define (part-cons l [acc '()]) | |
(if (equal? l null) | |
acc | |
(let ([k (car l)] | |
[v (if (null? (cdr l)) null (cadr l))] | |
[ll (if (> (length l) 1) | |
(drop l 2) | |
(drop l 1))]) | |
(if (equal? acc null) | |
(part ll (list (cons k v))) | |
(part ll (append acc | |
(list (cons k v)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment