-
Notifications
You must be signed in to change notification settings - Fork 1
Decorator
Liu Siwei edited this page Nov 19, 2017
·
2 revisions
Decorators dynamically alter the functionality of a function or class.
The name of the decorator should be prepended with an #
symbol.
func hello(f) {
print("Hello!")
return f
}
#hello
func welcome() {
print("Welcome!")
}
Hello!
is printed when welcome
is defined.
func hello(f) {
return func() {
print("Hello!")
f()
print("Bye!")
}
}
#hello
func welcome() {
print("Welcome!")
}
If the decorated function has arguments:
func hello(f) {
return func() {
print("Hello!")
f.$apply($args)
print("Bye!")
}
}
#hello
func welcome(name) {
print("Welcome! " + name)
}
func hello(f) {
args := $args.tail
return func() {
print("Hello! " + args.head)
f.$apply($args)
print("Bye!")
}
}
#hello("World")
func welcome(name) {
print("Welcome! " + name)
}
Introduction
Langauge Guide
Libraries
- Utility
- ListUtil
- StringUtil
- Math
- Data Structure
- LinkedList
- Stack
- Heap
- HeapList
- HashMap
- HashSet
- Others
- UnitTest
- Tokenizer
Dev Reference
- Syntax Sugar