[[ Please switch to "draft release". ]]
On Apr 2, 2015, at 3:03 PM, Daniel Bastos wrote: > > Exercise 336 > > Solution. It's not a proper use. It produces nothing. It doesn't terminate. > Because (drop ls 0) returns a list not smaller than ls, hence the recursion > of bundle doesn't reach the base case. > > I felt like adding an error case to bundle. Re-read the section on checked- functions (end of part I). > Exercise 337. Define the function list->chunks. It consumes a list l of > arbitrary data and a natural number n. The function’s result is a list of > list chunks of size n. Each chunk represents a sub-sequence of items in l. > > Use list->chunks to define bundle via function composition. > > Solution. To define bundle via function composition, I used map. I don't > know if that was the desired answer. I called it bundle-string. I think > bundle-string is really partition of exercise 338, so I'm not understanding > either this last bit of 337 or the entire point of 338. > > ; exercise 337 > ; ls n -> [List-of [List-of n-chunks]] > ; produces a list of lists of chunks > ; where each chunk represents a subsequence of items in ls > > ; boundaries > (check-expect (list->chunks empty 3) empty) > (check-expect (list->chunks empty 0) empty) > > ; usual case > (check-expect (list->chunks '(a b c d e f g) 2) (list '(a b) '(c d) '(e f) > '(g))) > > (define (list->chunks ls n) > (cond > [(or (= n 0) (empty? ls)) empty] > [else (cons (take ls n) (list->chunks (drop ls n) n))])) > > ; bundle via list->chunks > (check-expect (bundle-string (explode "mumble") 2) (bundle-string (explode > "mumble") 2)) I would be very surprised if (f x) were not equal (f x) for all functions f and arguments x. Please re-consider your example (formulated as test). This is where you went wrong, including setting up 338. -- Matthias -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.