View Cyan-in-20-minutes
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 main | |
// import a Cyan package | |
import cyan.math | |
import cyan.reflect | |
// import a Java package | |
import java.lang | |
@doc{* |
View RestrictTo
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 'type' should be attached to a type. It checks whether | |
the value of the type obeys the expression that is attached to | |
the annotation. Use 'self' as the value of the object that is | |
being restricted. Therefore, the expressions can be something like: | |
self >= 0 | |
self >= 0 && self < 5 |
View FSM_DSL_Methods.cyan
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 'fsmMethod' should be attached to a prototype. The parameter | |
name is optional. If present, it should be an identifer. The metaobject | |
creates a reset method with name 'resetFSM_Methods' or with the name | |
of the parameter. This method resets the FSM to the initial state. | |
q0, "q0q0:1" -> q0 |
View AddMethodTo.cyan
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 | |
@addMethodTo("func zero -> Int", "func zero -> Int = 0;") | |
@addMethodTo( | |
"""func len: String s less: Int -> Int""", | |
""" | |
func len: String s less: Int n -> Int { return s size - n} | |
""") | |
object AddMethodTo |
View AddCodeFromMetaobject.cyan
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 | |
/* | |
@addCodeFromMetaobject is in prototype Array. The annotation | |
addCodeToGenericPrototype gives the code to be added to the | |
array of prototype AddCodeFromMetaobject. | |
*/ | |
@addCodeToGenericPrototype("Array", " func sumAll -> Int"){* |
View AddBeforeMethod.cyan
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 | |
@addBeforeMethod("zero", "logStr = logStr ++ \"called zero\";") | |
object AddBeforeMethod | |
func run { | |
assert zero == 0; | |
assert logStr == "called zero"; | |
} |
View Helloworld.cyan
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 main | |
object Program | |
func run { | |
"Hello world" println | |
} | |
end |
View Action_afti_dsa.cyan
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{+* is used instead of @doc{* because '{*' is used | |
// in the text attached to @doc | |
@doc{+* | |
This metaobject can add fields and methods to the current prototype, | |
add code before methods, and add code inside methods (if the annotation | |
is inside a method). This text is in language Markdown. Unlike other | |
metaobjects, this one demands the understanding of the Cyan Metaobject |
View Shout.cyan
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 'shout' can be attached to a method. It changes | |
all strings to uppercase letters. This is a demonstration | |
metaobject, of course. | |
*} | |
object Shout |
View ReplaceCallBy.cyan
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 |
NewerOlder