define new type with given prototype
Parameters
define type :type
fields :block
methods :block
Attributes
as |
:type |
inherit given type |
Returns
Examples
copy
define :person [name surname age][
init: [
this\name: capitalize this\name
]
print: [
render "NAME: |this\name|, SURNAME: |this\surname|, AGE: |this\age|"
]
compare: [
if this\age = that\age -> return 0
if this\age < that\age -> return neg 1
if this\age > that\age -> return 1
]
]
sayHello: function [this][
ensure -> is? :person this
print ["Hello" this\name]
]
a: to :person ["John" "Doe" 35]
b: to :person ["jane" "Doe" 33]
print a
print b
sayHello a
a > b
print join.with:"\n" sort @[a b]
print join.with:"\n" sort.descending @[a b]
Related