[plt-scheme] Stepper doesn't run?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Apr 22 15:32:34 EDT 2004

I have reformulated your student's program with textual test cases:

(define-struct planeticket (start end price))
(define alop1 (list (make-planeticket 'LA 'DC 800)
                     (make-planeticket 'Chicago 'DC 1000)
                     (make-planeticket 'SF 'DC 5000)))

; (define (check-list alop start end)
;   (filter (lambda (x) (and (symbol=? start (planeticket-price x))
;                            (symbol=? end (planeticket-end x))))
;           alop))


(define (cross list1 list2)
   (map (lambda (y) (map (lambda (x) (list y x)) list2)) list1))

(define (last list)
   (cond
     [(empty? (rest list)) (first list)]
     [else (last (rest list))]))

;;find one that matches start
(define (findmatch place alop)
   (filter (lambda (x) (symbol=? place (planeticket-start x))) alop))


;; -----------------------
(equal?
  (findmatch 'LA (list (make-planeticket 'LA 'DC 800)
                       (make-planeticket 'DC 'Chicago 1000)
                       (make-planeticket 'Chicago 'DC 5000)))
  (list (make-planeticket 'LA 'DC 800)))
;; -----------------------

;;want to create a tree, start w/ trips possible starting from place 
want to start
;;create all combos of ways to get to end
;;if at end, don't add to list
(define (tree alop end alocombos)
   (map (lambda (listoftrips)
          (cond
            [(symbol=? end (planeticket-end (last listoftrips))) 
(listoftrips)]
            [else ;(cheapest-price ;(kill-infinite
             (cross alocombos (findmatch (planeticket-end (last 
listoftrips)) alop))]))
        alocombos))

;;test

;; -----------------------
(equal?
  (tree alop1 'DC (list (make-planeticket 'LA 'DC 800)
                        (make-planeticket 'DC 'Chicago 1000)))

  (list (make-planeticket 'LA 'DC 800)
        (make-planeticket 'DC 'Chicago 1000)
        (make-planeticket 'Chicago 'DC 1000)))
;; -----------------------

(define (calculate-price combotrips)
   (foldr (lambda (struct tot) (+ (planeticket-price struct) tot)) 0 
combotrips))

;; -----------------------
(=
  (calculate-price (list (make-planeticket 'LA 'DC 800)
                         (make-planeticket 'DC 'Chicago 1000)
                         (make-planeticket 'Chicago 'DC 5000)))
  6800)
;; -----------------------

;
; (define (cheapest-price alocombos)
;   (map (lambda (combotrips) (calculate-price combotrips)) alocombos))


(define (kill-infinite alocombos)
   (filter (lambda (combotrips)
             (let ((endoftrip (planeticket-end (last combotrips))))
               (andmap (lambda (struct) (symbol=? (planeticket-start 
struct) endoftrip)) combotrips)))
           alocombos))

;; -----------------------
(equal?
  (kill-infinite (list (list (make-planeticket 'LA 'DC 800)
                             (make-planeticket 'DC 'Chicago 1000)
                             (make-planeticket 'Chicago 'LA 5000))
                       (list (make-planeticket 'LA 'DC 800)
                             (make-planeticket 'DC 'Chicago 1000)
                             (make-planeticket 'Chicago 'DC 5000))
                       (list (make-planeticket 'LA 'DC 800)
                             (make-planeticket 'DC 'Chicago 1000)
                             (make-planeticket 'Chicago 'NY 5000))))
  (list
   (list (make-planeticket 'LA 'DC 800)
         (make-planeticket 'DC 'Chicago 1000)
         (make-planeticket 'Chicago 'NY 5000))))
;; -----------------------

As you see, the new test cases are now bracketed by lines ;; 
-----------------------.
My hunch is that the stepper and the embedded test cases don't work 
together (yet),
which is why I reformulated them as text.

Stepping now works and I almost immediately got to the "rest" problem 
that you mentioned and I saw where it came from.

A couple of notes on your student's program:

  (1) functions should come with contracts (types, signatures) and 
purpose statements.

  (2) unless students are truly familiar with loops (map, filter), I 
suggest they should write out their function via recursion and then 
step/debug them individually.

Unless you already know about it, I recommend a thorough look at How to 
Design Programs (htdp://www.htdp.org).

Come back if you have more questions -- Matthias



Posted on the users mailing list.