Skip to content

Instantly share code, notes, and snippets.

@criloz
Created June 9, 2020 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save criloz/873ebbb80eb9e11b1d49ac7bc1b07931 to your computer and use it in GitHub Desktop.
Save criloz/873ebbb80eb9e11b1d49ac7bc1b07931 to your computer and use it in GitHub Desktop.
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 = `patricia@nebtex.com`;
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': 'patricia@nebtex.com'})
#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