Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created December 11, 2012 02:20
Show Gist options
  • Save yao2030/4255309 to your computer and use it in GitHub Desktop.
Save yao2030/4255309 to your computer and use it in GitHub Desktop.
(define (last-pair list1)
(if (= (length list1) 1)
(car list1)
(last-pair (cdr list1))))
(define (but-last list1)
(if (= (length list1) 1)
'()
(cons (car list1) (but-last (cdr list1)))))
(define (reverse x)
(if (null? x)
'()
(cons (last-pair x) (reverse (but-last x)))))
(define (deep-reverse x)
(list (reverse (cadr x)) (reverse (car x))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment