Created
June 9, 2020 04:21
-
-
Save criloz/873ebbb80eb9e11b1d49ac7bc1b07931 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn with_email(x){ | |
x.email is r/^[\w\.\+\-]+\@[\w]+\.[a-z]{2,3}$/; | |
return with_email(x); | |
} | |
fn person(x){ | |
x.name is str; | |
x.age is #nat number; | |
return person(x) | |
} | |
fn young(x:person){ | |
x.age < 30; | |
return young(x) | |
} | |
fn old(x:person){ | |
x.age >= 60; | |
return old(x) | |
} | |
fn middle(x:person){ | |
x.age >= 30; | |
x.age < 60; | |
return middle(x) | |
} | |
let patricia = person{name=`patricia`, age=35}; | |
console.log(patricia); | |
patricia.age = 13; | |
console.log(patricia); | |
patricia.age = 70; | |
console.log(patricia); | |
patricia.email = `[email protected]`; | |
console.log(patricia); | |
//when the hastag expression is used the object, the object can not leave the class | |
let arnold = #old person{name=`arnold`, age=70}; | |
//this should raise error because an old person age can only be greater than 60 | |
arnold.age = 50 | |
//output | |
#middle person({'name': 'patricia', 'age': 35}) | |
#young person({'name': 'patricia', 'age': 13}) | |
#old person({'name': 'patricia', 'age': 70}) | |
#old #with_email person({'name': 'patricia', 'age': 70, 'email': '[email protected]'}) | |
#person old({'age': #nat number(60), 'name': 'arnold'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment