Page 1 of 1

pumpkin-problem

Posted: Mon Oct 28, 2013 6:15 am
by jeltedeproft
Hello everyone,

for school i have to make a function that hangs pumpkins (= lampion in the code) on a horizontal line

we already have a few functions in place :


(define (lampion r l)
(vc-append (filled-rectangle 2 l) (pumpkin r))) which makes a pumpkin on a vertical line


(define (rijg-aan-draad lampionnetjes) which hangs all the pumpkins on a tread, in this function "lampionnetjes" = a collection of pumpkins
(vc-append (filled-rectangle (pict-width lampionnetjes) 2)
lampionnetjes))

these are the programs i made , i had to make it a few different ways and i am only having trouble with the last way
the first way wa through regular recursion

(define (slinger-simpel n r)
(define (lampionnetjes k)
(if (= k 1)
(lampion r 10)
(ht-append (lampion r 10)
(lampionnetjes (- k 1)))))
(rijg-aan-draad (lampionnetjes n)))

the second way was through iteration

where the "acc" was used as a blanco sheet to put the pumpkins on

now i have to do it again, but now i have to use the "do" function. I am really having trouble with this.
I know the body of a do funtion, where you first say which parameters and what they have to do evertyime.
And then you write how the program stops and at last you write the body's u need. This is the code i already got


(define (slinger4 n r l acc)
(do ((aantal n (- aantal 1))
(lengte-koord 1 (+ lengte-koord 1)))
((= aantal 0))
(ht-append (lampion r lengte-koord)

for your simplicity i will translate into english (its dutch)

(define (handle4 n r l acc)
(do ((amount n (- amount 1))
(length-string 1 (+ length-string 1)))
((= amount 0))
(ht-append (pumpkin r length-string)))

so i have

n = the amount of pumpkins
r = width pumpkins
l = length of the string connecting the pumpkins to the horizontal line
acc = the blanco list where all the pumpkins need to go

so to summarize my problem, i know how to use recursion and iteration, but i dont know how to impement a do function into this.

Many thanks for your help

i would upload a picture of how the function looks like, but i dont know how to do this :s