From 3d7b35bb37c066489546751e100c2c2b823ccba3 Mon Sep 17 00:00:00 2001
From: Paul Buetow
@@ -311,7 +311,7 @@ not.
Each variable can have as many synonyms as wished. A synonym is another name to access the content of a specific variable. Here is an example of how to use synomyms:
my foo = "foo";
@@ -321,6 +321,28 @@ not.
# The synonym variable should now also set to "bar"
assert "bar" == bar;
Synonyms can be used for all kind of identifiers. It's not limited to normal variables but can be also used for function and procedure names etc.
+
+ # Create a new procedure baz
+ proc baz { say "I am baz"; }
++ # Make a synonym baz, and undefine baz + my bay = \baz;+
+ undef baz;+
+ # bay still has a reference of the original procedure baz + bay; # this prints aut "I am baz"+
The syms keyword gives you the total number of synonyms pointing to a specific value:
++ my foo = 1; + say syms foo; # Prints 1+
+ my baz = \foo; + say syms foo; # Prints 2 + say syms baz; # Prints 2+
+ undef baz; + say syms foo; # Prints 1