my-object
source code: https://github.com/AlexKnauth/my-object
1 Forms and Functions
syntax
(object [field-id expr] ...)
See also object-extend.
If an expr is a function, then that function can be used as a method for the object, but methods are not treated specially; they are just normal fields that happen to have functions stored in them.
Each field-id is public and immutable. Private mutable fields are also possible (see Fish example based on racket guide for objects).
syntax
(object-extend obj option ... [field-id expr] ...)
option = #:inherit (inherit-id ...) | #:super ([super-id1 super-id2] ...)
If the #:inherit option is provided, the inherit-ids are available as bindings within the exprs.
If the #:super option is provided, the super-id1s are available within the exprs, and a super-id1 refers to the super-id2 field of the super object.
procedure
(object-fields obj) → (hash/c symbol? any/c #:immutable #t)
obj : object?
syntax
(send obj-expr method-id arg ...)
(send obj-expr (identity method-expr) arg ...) (send obj-expr . field-id) send
The second form allows the method to be determined at run time, and is equivalent to (dynamic-send obj-expr method-expr arg ...).
The third form is equivalent to (obj-expr #'field-id), and is mainly provided so that send+ can use field-id as a msg.
When send is used as an identifier by itself, it expands to dynamic-send.
syntax
(send* obj-expr msg ...)
msg = (method-id arg ...) | field-id
syntax
(send+ obj-expr msg ...)
msg = (method-id arg ...) | field-id
procedure
(dynamic-send obj method arg ...) → any
obj : object? method : (or/c symbol? identifier?) arg : any/c
syntax
2 Examples
2.1 Posn example based on racket guide for structs
This is based on the examples from Programmer-Defined Datatypes.
Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
2.2 Fish example based on racket guide for objects
This is based on the examples from Classes and Objects.
Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||||
|