On Saturday, 1 October 2016 16:13:01 UTC+1, Ben Greenman  wrote:
> Maybe this will help:
> 
> 
> 
> 
> (struct interval (small big guesses))
> 
> creates 5 new functions
> interval, for making intervals. For example (interval 5 10 0) creates an 
> interval from 5 to 10 that has 0 guessesinterval?, for testing if a value is 
> an interval. For example (interval? 1) is #false and (interval? (interval 0 0 
> 0)) is #trueinterval-small, to get the value of the "small" field out of an 
> interval. For example, (interval-small (interval 8 9 10)) is 8interval-big, 
> to get the value of the "big" fieldinterval-guesses, to get the value of the 
> "guesses" field
> This is all described in the Racket docs for struct
> http://docs.racket-lang.org/reference/define-struct.html
> 
> 
> 
> 
> 
> The value of (+ (interval-guesses w) 1) is a number 1 greater than the value 
> of the "guesses" field in the interval w.
> Notice that you give this value as the 3rd argument to a call to (interval 
> ....)


Thanks for the responses.  My confusion was with the meaning of w.  I see now 
that functions such as on-tick etc return the current state of the world.  In 
my program case the type is interval.  So on-key returns a world state, ie an 
interval.

And the bigger function takes arguments w which is the current world state.  It 
is confusing for me I think because in C (and C like languages) the function 
would be defined as:

WorldState bigger(WorldState previous_state)

The types are less explicit in lisp.

And it is now more obvious to me that in:

(define (bigger w)
  (interval (min (interval-big w) 
                 (add1 (guess w)))
            (interval-big w) (+ (interval-guesses w) 1)))

The (interval... part is a constructor ? for an interval and that is what this 
function returns - the new state of the world.

It's interesting here that there is no assignment as such.  Although big-bang 
must somehow be dealing with mutating internal state somehow.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to