Last active
March 25, 2020 12:43
-
-
Save joseoliv/7eb42ac948df870c1ffd068b705c59ff to your computer and use it in GitHub Desktop.
replaceCallBy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package metaobjectTest | |
@doc{* | |
Annotation 'replaceCallBy' should be attached to a final method. It | |
replaces any message passings to the method by the attached DSL code. | |
The DSL code may use the parameters, which are re-calculated if | |
parameter 'once' to the annotation is not used. | |
All methods of the prototype ReplaceCallBy are final because it is a | |
final prototype. | |
*} | |
object ReplaceCallBy | |
func run { | |
var value = threeTimes: 3; | |
assert value == 9; | |
value = threeTimes: next; | |
assert value == 3; | |
nextValue = 0; | |
value = threeTimesOnce: 3; | |
assert value == 9; | |
nextValue = 0; | |
// value = 1 + 1 + 1 | |
value = threeTimesOnce: next; | |
assert value == 3; | |
} | |
@replaceCallBy{* 3*n *} | |
func threeTimes: Int n -> Int = n; | |
@replaceCallBy(once){* n + n + n *} | |
func threeTimesOnce: Int n -> Int = n; | |
func next -> Int { ++nextValue; return nextValue; } | |
var Int nextValue = 0; | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment