Cached operations in EOL

To simulate derived properties, EOL supports cached operations. A cached operation – parameter-less operation annotated with a @cached annotation – is only executed once: subsequent calls return the same result without executing its body again. An example that calculates the Fibonacci number of a given Integer follows:

15.fib();

@cached
operation Integer fib() : Integer {
	if (self = 1 or self = 0) {
		return 1;
	}
	else {
		return (self-1).fib() + (self-2).fib();
	}
}
About these ads
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s