[plt-scheme] HTDP Exercise 17.1.2

From: aditya shukla (adityashukla1983 at gmail.com)
Date: Sun Jun 21 23:26:06 EDT 2009

This is what I have done , I Guess I am missing something


; This function takes a list of symbols and list of numbers and produces all
possible pairs of numbers and symbols
; Data definition A list of symbols is either an empty  or a los , lon is
either empty or lon
; contract : cross los * lon - list of lists
; Purpose : for every item in the los make a list with every item in lon and
make a list of all these lists
;examples : (cross '(a b c) '(1 2))
;(list (list 'a 1) (list 'a 2) (list 'b 1) (list 'b 2) (list 'c 1) (list 'c
2))
;template : - (define cross (first los ) ( rest los) (first lon ) (rest
lon))
(define cross (lambda ( los lon)
               (cond
                 [(or (empty? los)(empty? lon))  empty]

                 [else ((cr (first los) lon)(cross (rest los) lon))])))
;contract symbol * lon -> list list of symbols and number
;purpose:-take the symbol and make a list of list of symbol and every
element of lon
;examples : (list (list a 1) (list a 2))
(define cr (lambda (sym lon)
             (cond
               [(empty? lon) empty]
               [else (append (list sym (first lon))(list(cr sym (rest
lon)))) ])))

;(cr 'a '(1 2))

(cross '(a) '(1))
;(cross '(a b c) '())

procedure application: expected procedure, given: (list 'a 1 empty);
arguments were: empty

Thanks
Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090621/1b4e0143/attachment.html>

Posted on the users mailing list.