dvanhorn / dpc Goto Github PK
View Code? Open in Web Editor NEWDesigning Programs with Class
Designing Programs with Class
The paragraph at line 386-388 of Chapter 17 is unclear.
Kill function application syntax for method calls within method definitions and bring back only after inheritance.
Right now, it's all horribly duplicated.
Big-bang breaks when given a union where one world implements an on-tick and another doesn't.
As in Chapter 17:
The functional style is slow, but easy.
The structural style is fast, but hard.
In chapter/06/exercise.scrbl there was a use of (image "book/chapter/06/tron1.png") but this path is not resolved correctly when building the web page. We need some way of inserting an image that works in both the book and on the class web page.
Allow students to use mechanisms they understand with universe
/big-bang
, once we have overrriding.
#lang class1
(define-class a%
(fields one))
(define-class b%
(super a%)
(fields one))
; Error msg: class*: superclass #<class:a%> already contains method: one for class: b%
; Desired error msg: class*: superclass #<class:a%> already contains field: one for class: b
If a universe server starts in a state without a on-msg
method and then transitions to one with an on-msg
, that method is never called.
Here is a simple client/server that should error once a message is relayed back to the client, instead the on-msg
method is never called, thus never sending a message back.
#lang class/0
(require class/universe)
(require 2htdp/image)
(define-class wait%
(define (on-new iw)
(new begin%)))
(define-class begin%
(define (on-msg iw msg)
(make-bundle this (list (make-mail iw msg)) empty)))
(define-class client%
(define (register) LOCALHOST)
(define (on-tick)
(make-package this 'tick!))
(define (on-receive msg)
(error "Got here!"))
(define (to-draw)
(empty-scene 20 20 "yellow")))
(launch-many-worlds
(universe (new wait%))
(big-bang (new client%)))
We've moved away from the (field f)
form of referencing fields and instead have used automatically generated accessor methods: (send this f)
.
We should do the same for (set-field! f x)
. I propose we generate mutator methods (send this f! x)
.
There is some potential for this going wrong, eg if you have a class with fields f
and f!
, then method f!
is ambiguous, but so long as this is a syntax error, it seems fine.
Right now, we've got nothing.
In class/0, there's no documentation for things like on-message
.
This just gives a "bad syntax" error and should do better:
#lang class/0
(define-class a%
(check-expect 5))
class/0
supports define-interface
, but it should be taken out.
#lang class/1
(define-class n)
(define-class m
(super n)
(super p))
define-class: There were multiple syntax errors. The first error follows:
expected the identifier `isl+:check-range' in: super
Universe methods should work like world methods and be allowed either to produce a new state, or a bundle.
#lang racket
(require class0)
(define-class A%
(define/public (ok)
(send 0 oops))
(define/public (bad)
(new A% 0)))
; Run each of these separately in DrRacket:
;(send (new A%) ok) ; Good error location: body of `ok' method
;(send (new A%) bad) ; Bad error location: call site of `bad' method
#lang class/0
(define x (new foo%))
(define-class foo%)
#lang class/1
(define x 0.1)
; define: bad syntax (multiple expressions after identifier) in:
; (define DT 0 |.| 1)
(define y ((λ (x) x) 0.1))
; .: not legal outside of method send syntax in: |.|
This gives a bad syntax error:
#lang class/0
(define-class a%
(define/asdf (m) 1))
which is
define-class: There were multiple syntax errors. The first error follows:
expected the identifier `isl+:check-range' in: define/asdf
Obviously the isl+:check-range
is a nasty implementation artifact.
First:
Page 138, first paragraph, sentence:
One natural design is to take write a method that encapsulates the similarities of
fast or old, say filter, and add a parameter that consumes the differences, that is,
the predicate, represented as a function [Runner -> Boolean].
(emphasis mine)
Should probably be
One natural design is to write a method...
Second:
Page 138, second paragraph, first sentence:
But what if we wanted to reresent these predicates with objects? Is such a thing
possible?
(emphasis mine)
The check-expect form is allowed within classes in later language levels, but it should be allowed starting with class/0.
The following code fails with an error:
#lang class/1
(define-class point%
(fields x y)
(define (move-x dx)
(new point%
(+ (send this x) dx)
(send this y))))
The error is "define-class: There were multiple syntax errors. The first error follows:
expected the identifier `isl+:check-range' in: define"
This is a problem since class/1 and higher are supposed to be supersets of class/0.
Currently, several "chapters" in the book are actually just exercises from 2011 homeworks. These should be integrated into other chapters.
class/0 shows two buttons but class/1 and on appear to be fine.
class/0
supports define/public
and define/private
. We can't take them out until after the semester, but then they should go.
from the textbook:
(define-class world%
(fields light)
(define (tick-rate) 5)
(define (to-draw)
(send (send this light) draw))
(define (on-tick)
(new world% (send (send this light) switch))))
switch is undefined; should be "next" instead
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.