PasteRack.org | ||

Paste # 7551 | ||

2013-10-10 16:57:32 | ||

Fork as a new paste. | ||

Paste viewed 981 times. | ||

Tweet | ||

Embed: | ||

#lang/bsl+ ; LON is one of: ; – empty ; – (cons Number LON) ; interpretation: a list of numbers ; LON -> LON ; created a sorted version of one-lon (check-expect (sort '(13 0 1 2 3 4 5 6 7 8 9 10 11 12 14 15)) '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)) (define (sort one-lon) (cond [(empty? one-lon) '()] [(cons? one-lon) (ryan (first one-lon) (sort (rest one-lon)))])) ; Number LON -> LON ; puts n into one-lon according to ascending order ; WHAT DO WE KNOW: one-lon is sorted in ascending order ; because ryan is called inside of sort with (sort (rest ...)) (check-expect (ryan 13 (list 11 12 14 15)) (list 11 12 13 14 15)) (check-expect (ryan 13 empty) (list 13)) (define (ryan n one-lon) (cond [(empty? one-lon) (list n)] [(cons? one-lon) (if (<= (first one-lon) n) (cons (first one-lon) (ryan n (rest one-lon))) (cons n one-lon))])) (ryan 13 empty) (check-expect (ryan 13 empty) (list 12))

=>

prog:1:0: read: expected a single space after `#lang'