[plt-scheme] I miss end-of-time...

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Mar 12 11:43:15 EST 2010

1. I forgot the original problem, but I am sure it involves a  
conditional: a certain condition has to be met to stop the world.  
Otherwise it would go on forever.

2. Sorry, I had forgotten that I had responded to you many times  
before with the addition of 'stop-with'

#lang scheme

(require 2htdp/universe 2htdp/image)

(big-bang 0
           (on-tick (lambda (x)
                      (if (= x 2)
                          (stop-with 2)
                          (+ x 1))))
           (on-draw (lambda (x)
                      (circle 50 "solid" "red"))))


See docs.




On Mar 12, 2010, at 11:29 AM, Stephen Bloch wrote:

>
> On Mar 11, 2010, at 2:57 PM, John Clements wrote:
>
>>> With an "end-of-time" function, it's trivial: the key handler  
>>> ignores its parameters and calls "end-of-time".
>>
>> I think the conclusion here is that imperative interfaces allow  
>> hiding of state, and make certain programs appear much simpler; it  
>> sounds like you just need to wait on writing that program until  
>> you've got structures. No?
>
> In general, I like to aim for "the solution involves only concepts  
> that were present in the problem statement."  Not every good program  
> meets that test -- testing for primality by using the Little Fermat  
> Theorem springs to mind -- but it's a good initial goal.
>
> The animation I described obviously involves responding to time, and  
> responding to the keyboard, so tick handlers and key handlers are  
> justified.  It obviously involves stopping.  It obviously involves  
> circles of a specified radius, and it involves incrementing the  
> radius.  Those concepts are all present in the problem statement, so  
> they'll almost certainly appear in the solution.  Conditionals,  
> structs, and "cons" are NOT in the problem statement, so I'd like to  
> be able to solve the problem without them.  With "end-of-time", I  
> could.
>
> Even once I introduce conditionals (after Spring Break), the various  
> solutions proposed all involve special "quitting" values for the  
> model, which feel less natural than just saying "if the user has hit  
> the 'q' key, stop."
>
> "end-of-time" feels to me like throwing an exception.  If that's  
> what you mean by "imperative interfaces", then so be it....
>
> Stephen Bloch
> sbloch at adelphi.edu
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.