8.18
top
← prev up next →

dotmethodπŸ”— i

This package provides both a dotmethod/dotmethod module to be required and a #lang dotmethod lang-extension.

Both of these provide functionality for obj.method(x)-style method definitions and method calls, but generalized to be used for all data types that can be distinguished by predicates.

1dotmethod/dotmethodπŸ”— i

A require module intended to be used along with the sweet-exp and postfix-dot-notation lang-extensions together, for example:
#lang postfix-dot-notation sweet-expracket
require dotmethod/dotmethod

syntax

dotmethod

#lang postfix-dot-notation sweet-expracket
require dotmethod/dotmethod
dotmethod pred-exprobj-id.method(args... )
method-body
...+
;or
dotmethod pred-exprobj-id.method
method-expr;afunctionexpression
Examples:

>

require dotmethod/dotmethod
 

>

dotmethod list? lst.ref(i)
(list-ref lsti)
 

>

dotmethod hash? hsh.ref
(case-lambda ;canusecase-lambdaoranyotherexpressionhere
[(key)(hash-ref hshkey)]
[(keyelse )(hash-ref hshkeyelse )])
 

>

let ([lox' (abcd)])
lox.ref(2);youcouldalsowrite(lox.ref2)orlox.ref2ifyouprefer
;thisactuallymeans((reflox)2)innormallispnotation
 

'c

>

let ([ht(hash ' a1' b2' c3)])
ht.ref(' a)
ht.ref(' d' not-found)
 

1

'not-found

>

define adder%
(+ ab)
 

>

dotmethod (is-a?/c adder%)adder.add(b)
(send adderaddb)
 

>

define five-adder(make-object adder%5)
 

>

five-adder.add(2)

7

syntax

dotmethods

#lang postfix-dot-notation sweet-expracket
require dotmethod/dotmethod
pred-exprobj-id.method(args... )
method-body
...+
...
Examples:

>

require dotmethod/dotmethod
 

>

list? lst.ref(i)
(list-ref lsti)
hash? hsh.ref
[(key)(hash-ref hshkey)]
[(keyelse )(hash-ref hshkeyelse )])
 

>

let ([lox' (abcd)])
lox.ref(2)
 

'c

>

let ([ht(hash ' a1' b2' c3)])
ht.ref(' a)

1

2#lang dotmethodπŸ”— i

A lang-extension for dotmethods so that
#lang dotmethod your-base-language
Is roughly equivalent to
#lang afl postfix-dot-notationsweet-expyour-base-language
(require dotmethod/dotmethod)

I say roughly, because unlike with just blindly adding a require, it still works properly if your-base-language doesn’t allow require forms to be inserted like that.

Example:
list? lst.ref(i)
(list-ref lsti)
hash? hsh.ref
[(key)(hash-ref hshkey)]
[(keyelse )(hash-ref hshkeyelse )])
let ([lox' (abcd)])
lox.ref(2)
let ([ht(hash ' a1' b2' c3)])
ht.ref(' a)

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /