Created
November 22, 2016 16:24
-
-
Save games647/e6fba2304726367bcc1e1bd652f99093 to your computer and use it in GitHub Desktop.
Reimplementation of inverting a list
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
;; 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