Skip to content

Instantly share code, notes, and snippets.

@games647
Created November 22, 2016 16:24
Show Gist options
  • Save games647/e6fba2304726367bcc1e1bd652f99093 to your computer and use it in GitHub Desktop.
Save games647/e6fba2304726367bcc1e1bd652f99093 to your computer and use it in GitHub Desktop.
Reimplementation of inverting a list
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-reader.ss" "lang")((modname invert) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
(define (invert lst)
(cond [(empty? lst) empty]
[else (append (invert (rest lst)) (cons (first lst) empty))]))
(check-expect (invert empty) empty)
(check-expect (invert (list 1)) (list 1))
(check-expect (invert (list 1 2 3 4)) (list 4 3 2 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment