Skip to content

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.

During function definition

func hello(f) {
	print("Hello!")
	return f
}

#hello
func welcome() {
	print("Welcome!")
}

Hello! is printed when welcome is defined.

During function execution

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)
}

Decorator arguments

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
Clone this wiki locally