Skip to content

Instantly share code, notes, and snippets.

@arakov
Last active August 29, 2015 14:19
Show Gist options
  • Save arakov/295bb07c3bddd1e1bb37 to your computer and use it in GitHub Desktop.
Save arakov/295bb07c3bddd1e1bb37 to your computer and use it in GitHub Desktop.
ELENA overload operators
#define system.
#define extensions.
#class MyNumber
{
#field theValue.
#constructor new : aValue
[
theValue := aValue.
]
#method add : aValue
[
#var x := theValue.
#var y := aValue.
#loop (y != 0)?
[
#var carry := x && y.
x := x ^^ y.
y := carry shift &index:-1.
].
^ MyNumber new:x.
]
#method => theValue.
}
#symbol program =
[
consoleEx writeLine:"Sum............: 20+20=":(MyNumber new:20 + 20).
].
@arakov
Copy link
Author

arakov commented Apr 16, 2015

Statement "#method => theValue" means that incoming messages are redirected to
theValue if no mapping exists in MyClass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment