reset password
Author Message
Amedrano
Posts: 80
Posted 21:38 Oct 23, 2015 |

here is  my function

(define (at-bottom? y-pos-pair)
  (>=(ball-y-pos(first y-pos-pair)) HEIGHT))

here is my error

ball-y-pos: contract violation
  expected: ball?
  given: 3

when i run "(my-animate ballList create-scene up-and-down at-bottom?)" the picture of 2 balls shows up but I get this error and they stay at their starting locations.  

Any tips?

 

jasonmz
Posts: 7
Posted 21:48 Oct 23, 2015 |

What does your up-and-down look like? That's the error I had when I first did it but then I rewrote it based off what Professor Abbott said here http://csns.calstatela.edu/department/cs/forum/topic/view?id=5185224:

rabbott wrote:

Not quite sure what you are asking, but the update function normally returns something that has the same structure as what it received. If it received a list with two numbers, it should return a list with two numbers. If it received a list with two ball objects it should return a list with two ball objects. The changes it makes is not in the stucture of the world state but in the values stored in it, e.g., the y-pos of the two balls.

 

rabbott
Posts: 1649
Posted 21:50 Oct 23, 2015 |

A couple of tips.

1. Add spaces to your code so that it's easier to read.

2. Describe what you intend the world state to be. Is it a list of two numbers? A list of two balls? Something else? Given what you expect it to be are you processing it consistent with that plan?

Last edited by rabbott at 21:53 Oct 23, 2015.
Amedrano
Posts: 80
Posted 21:51 Oct 23, 2015 |
jasonmz wrote:

What does your up-and-down look like? That's the error I had when I first did it but then I rewrote it based off what Professor Abbott said here http://csns.calstatela.edu/department/cs/forum/topic/view?id=5185224:

rabbott wrote:

Not quite sure what you are asking, but the update function normally returns something that has the same structure as what it received. If it received a list with two numbers, it should return a list with two numbers. If it received a list with two ball objects it should return a list with two ball objects. The changes it makes is not in the stucture of the world state but in the values stored in it, e.g., the y-pos of the two balls.

 

(define (up-and-down y-pos-pair)
  (list (add1 (ball-velocity (first y-pos-pair)))
        (sub1 (ball-velocity (second y-pos-pair))))

jasonmz
Posts: 7
Posted 21:57 Oct 23, 2015 |
Amedrano wrote:
jasonmz wrote:

What does your up-and-down look like? That's the error I had when I first did it but then I rewrote it based off what Professor Abbott said here http://csns.calstatela.edu/department/cs/forum/topic/view?id=5185224:

rabbott wrote:

Not quite sure what you are asking, but the update function normally returns something that has the same structure as what it received. If it received a list with two numbers, it should return a list with two numbers. If it received a list with two ball objects it should return a list with two ball objects. The changes it makes is not in the stucture of the world state but in the values stored in it, e.g., the y-pos of the two balls.

 

(define (up-and-down y-pos-pair)
  (list (add1 (ball-velocity (first y-pos-pair)))
        (sub1 (ball-velocity (second y-pos-pair))))

You might want to try the debug and see what function is causing the change. For me it was in my up-and-down function, but I had changed what the function looked like compared to what Professor Abbott put up on the wiki.

Amedrano
Posts: 80
Posted 21:57 Oct 23, 2015 |

Ok thanks :)

shewitt2
Posts: 5
Posted 20:58 Oct 24, 2015 |

(define (up-and-down y-pos-pair)
  (list (add1 (ball-velocity (first y-pos-pair)))
        (sub1 (ball-velocity (second y-pos-pair))))

 

I see a small problem with this.  It appears like you're passing in as a parameter a pair of balls (which I'm assuming is in the form of a list, since a cons pair would throw a contract violation at  (first y-pos-pair)), but you're returning a list of numbers.  Big bang does something like this:

draw(state) -> update(state) -> done?(state)

If the state changes type in the update stage, no wonder it throws an exception in the done? stage.