Skip to content

Commit

Permalink
added cxSetParent example
Browse files Browse the repository at this point in the history
  • Loading branch information
reginaldford committed Feb 18, 2024
1 parent de1d3e1 commit 572f91a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sms_src/examples/cxSetParent.sms
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/local/bin/sms -qm1
# Demonstrates cxSetParent
# fnSetParent sets the parent scope of a context,
# overriding the lexical scope.
{
# Making a person
let personA = { age -> 22; name -> "George" };
# Making an older person
let personB = { age -> 56; name -> "Martha"; phone_number->5555555555; };
# Setting George's parent to Martha (functional design)
personA = cxSetParent(personA,personB);
# Show both objects:
putln("George: " str+ toStr(personA) str+ " . Martha: " str+ toStr(personB));
# Printing the result
putln("The parent of " str+ personA.name str+ " is " str+ parent(personA).name);
# Test the automatic parent searching
putln("George.phone_number gives " str+ toStr(personA.phone_number));
};
File renamed without changes.

0 comments on commit 572f91a

Please sign in to comment.