on-receive does not have to exist for a world to be a part of a universe, weird but feasible; Closes PR12401

This commit is contained in:
Matthias Felleisen 2011-11-28 17:42:30 -05:00
parent b40cc23f60
commit 19f8cacfcd
5 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,32 @@
#lang racket/load
(module client racket
(require 2htdp/universe 2htdp/image)
;; Color -> Boolean
(define (client c)
(big-bang #true
(to-draw (lambda (w) (text (if w "hello world" "good bye") 22 c)))
(register LOCALHOST)
(name c)
(on-receive (lambda (w msg) (not w)))))
(launch-many-worlds (client "blue") (client "red")))
(module server racket
(require 2htdp/universe)
(define (server tick-rate)
(universe '()
(on-new (lambda (w n) (make-bundle (cons n w) '() '())))
(on-tick
(lambda (w*)
(make-bundle w* (map (lambda (w) (make-mail w 'go)) w*) '()))
tick-rate)
(on-msg void)))
(thread server))
(require 'server)
(require 'client)

View File

@ -0,0 +1,15 @@
#lang racket
(require 2htdp/universe)
(require 2htdp/image)
(launch-many-worlds
(big-bang '*
(on-tick (lambda (w) w) 1/3 2)
(to-draw (λ (w) (empty-scene 200 200)))
(register LOCALHOST))
(universe '*
(on-tick (lambda (w) (make-bundle '* '() '())) 1/2 2)
(on-new (λ (u iw) (make-bundle '* (list (make-mail iw 'boo!)) '())))
(on-msg (λ (u iw msg) (make-bundle '* empty empty)))))

View File

@ -96,7 +96,7 @@
[on-release DEFAULT #f (function-with-arity 2)]
;; (U #f (World S-expression -> World))
;; -- on-receive must specify a receive handler
[on-receive DEFAULT #'#f (function-with-arity 2)]
[on-receive DEFAULT #'(lambda (w m) w) (function-with-arity 2)]
;; World -> Boolean
;; -- stop-when must specify a predicate; it may specify a rendering function
[stop-when DEFAULT #'False

View File

@ -37,4 +37,5 @@ run on-tick-universe-with-limit.rkt
run on-tick-with-limit.rkt
run on-release-no-key.rkt
run struct-universe.rkt
run universe-receive.rkt

View File

@ -1,4 +1,9 @@
------------------------------------------------------------------------
* on-receive doesn't have to exist for universe/world interactions
-- fixed
------------------------------------------------------------------------
Version 5.2 [Tue Oct 18 12:34:16 EDT 2011]
* bug fixes in 2htdp/universe