Changes -> and -! to %-> and %-!, because of too many name clashes in racket for ->.

This commit is contained in:
2025-08-18 09:18:58 +02:00
parent 6ce0a99f15
commit 7fc601d33c
4 changed files with 92 additions and 92 deletions

View File

@@ -49,10 +49,10 @@ Methods and fields are always virtual. Superclass definitions are resolved based
@section{Object and Method Use}
@itemlist[
@item{@racket[(-> obj field)] — call getter for field.}
@item{@racket[(-> obj field! val)] — set field.}
@item{@racket[(-> obj method args ...)] — invoke method.}
@item{@racket[(->> obj name)] — retrieve method/field procedure.}
@item{@racket[(%-> obj field)] — call getter for field.}
@item{@racket[(%-> obj field! val)] — set field.}
@item{@racket[(%-> obj method args ...)] — invoke method.}
@item{@racket[(%->> obj name)] — retrieve method/field procedure.}
@item{@racket[(roos-object? x)] — is it a ROOS object?}
@item{@racket[(roos-class? x)] — is it a ROOS class definition?}
@item{@racket[(roos-classname obj)] — symbolic class name.}
@@ -63,11 +63,11 @@ Methods and fields are always virtual. Superclass definitions are resolved based
@subsection{Provided procedures}
@defproc[(-> [obj any/c] [name symbol?] ...) any/c]{
@defproc[(%-> [obj any/c] [name symbol?] ...) any/c]{
Invoke a getter, setter, or method on ROOS object @racket[obj] using name and arguments.
}
@defproc[(->> [obj any/c] [name symbol?]) procedure?]{
@defproc[(%->> [obj any/c] [name symbol?]) procedure?]{
Return the method or field procedure named @racket[name] from object @racket[obj].
Useful for higher-order usage.
}
@@ -105,7 +105,7 @@ Constructs a new ROOS object of the given @racket[class], optionally with argume
If the class defines @racket[init], that method is invoked automatically.
}
@defproc[(-! [class any/c] [args any/c] ...) any/c]{
@defproc[(%-! [class any/c] [args any/c] ...) any/c]{
Convenient shorthand for @racket[roos-new]. Also invokes @racket[init] if present.
}
@@ -236,12 +236,12 @@ This example builds an address book with persistent reference to persons, using
((add p)
(set! persons (vector-extend persons (+ (vector-length persons) 1) p))
(-> this ids! (vector->list (vector-map (lambda (o) (-> o roos-id)) persons))))
(%-> this ids! (vector->list (vector-map (lambda (o) (%-> o roos-id)) persons))))
((remove i)
(set! persons (vector-append (vector-take persons i) (vector-drop persons (+ i 1))))
(-> this ids! (vector->list
(vector-map (lambda (o) (-> o roos-id)) persons))))
(%-> this ids! (vector->list
(vector-map (lambda (o) (%-> o roos-id)) persons))))
((for-each f)
(letrec ((g (lambda (i n)
@@ -251,34 +251,34 @@ This example builds an address book with persistent reference to persons, using
(g 0 (vector-length persons))))
(init (begin
(-> this roos-id! 'book)
(%-> this roos-id! 'book)
(let ((ps (map (lambda (id)
(let ((p (roos-new person)))
(-> p roos-id! id)
(%-> p roos-id! id)
p))
(-> this ids))))
(%-> this ids))))
(set! persons (list->vector ps)))))
)
;; Create sample data
(define b (-! book))
(define b (%-! book))
(define (adder n t)
(let ((p (-! person)))
(-> p name! n)
(-> p tel! t)
(-> b add p)))
(let ((p (%-! person)))
(%-> p name! n)
(%-> p tel! t)
(%-> b add p)))
(adder "Alice" "123")
(adder "Bob" "456")
(adder "Jos" "982")
(adder "Rebecca" "363")
(-> b (for-each (lambda (p) (displayln (-> p name)))))
(%-> b (for-each (lambda (p) (displayln (%-> p name)))))
;; Reopen addressbook later from persistent storage
(define a (-! book))
(-> b (for-each (lambda (p) (displayln (-> p name)))))
(define a (%-! book))
(%-> b (for-each (lambda (p) (displayln (%-> p name)))))
]
@@ -295,14 +295,14 @@ For example, a doubly-linked list:
(next #f)
(prev #f))
(define a (-! node))
(-> a val! 1)
(define a (%-! node))
(%-> a val! 1)
(define b (-! node))
(-> b val! 2)
(define b (%-! node))
(%-> b val! 2)
(-> a next! b)
(-> b prev! a)
(%-> a next! b)
(%-> b prev! a)
]
To avoid resource leaks when such cyclic structures are finalized, make sure that any cleanup (e.g. persistence flush) is done in @racket[finalize] methods. Racket's garbage collector can collect cyclic references if there are no external references left.