source code: https://github.com/AlexKnauth/my-object
syntax
( object [field-idexpr]...)
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 objoption...[field-idexpr]...)
option = #:inherit(inherit-id...)| #:super([super-id1super-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-exprmethod-idarg...)
The second form allows the method to be determined at run time, and is equivalent to (dynamic-send obj-exprmethod-exprarg... ).
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-exprmsg...)
msg = (method-idarg...)| field-id
syntax
( send+ obj-exprmsg...)
msg = (method-idarg...)| field-id
procedure
( dynamic-send objmethodarg...)→any
obj:object?arg:any/c
syntax
This is based on the examples from Programmer-Defined Datatypes.
> p(object [x 1] [y 2])
#t
> (p'x);by the way, you can use #'x here instead of 'x1
> (p'y)2
> p2(object [x 3] [y 2])
'(4 6)
'(3 2)
#:inherit(xy)[zz0]> (3d-posn123)(object [x 1] [y 2] [add #<procedure>] [->list #<procedure>] [z 3])
This is based on the examples from Classes and Objects.
10
16
#:inherit(eat)(eatfish1)(eatfish2))]))32
#:super([super-growgrow])32