Skip to content

Instantly share code, notes, and snippets.

@edcrypt
Last active November 16, 2016 02:09
Show Gist options
  • Select an option

  • Save edcrypt/962c83a559566b9bcb7ec794205119bd to your computer and use it in GitHub Desktop.

Select an option

Save edcrypt/962c83a559566b9bcb7ec794205119bd to your computer and use it in GitHub Desktop.
A simple bank account prototype.
( |
parent* = traits clonable.
balance<-0.
{'Category: transfer'
deposit: amount = ( balance: balance + amount ).
withdraw: = ( | :amount | balance: 0 max: balance - amount ).
}
| )
@edcrypt
Copy link
Copy Markdown
Author

edcrypt commented Nov 15, 2016

A Self language example to demonstrate:

  • slot-object literals
  • methods
  • automatic setter with <-
  • reflection

Insert into a shell and press "get it".

Then you can go further and enter () on another evaluator and get a new object, attribute it to a 'traits bankAccount' slot, set the creator path on annotations to this path, and refactor our bank account, moving methods to this "traits" object and resetting the parents of both objects.

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