aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/examples/scope.frt
diff options
context:
space:
mode:
Diffstat (limited to 'amforth-6.5/examples/scope.frt')
-rw-r--r--amforth-6.5/examples/scope.frt21
1 files changed, 21 insertions, 0 deletions
diff --git a/amforth-6.5/examples/scope.frt b/amforth-6.5/examples/scope.frt
new file mode 100644
index 0000000..d6a5d31
--- /dev/null
+++ b/amforth-6.5/examples/scope.frt
@@ -0,0 +1,21 @@
+\ The following example shows how to create a library of words under a special
+\ wordlist (can_lib). This example also shows how to chain scope calls safely.
+
+wordlist constant can_lib
+
+get-order 1+ can_lib swap set-order \ can_lib would be searched first
+
+: can_scope ( addr len -- addr' len' wid )
+ 2dup
+ 4 > if \ name length check
+ s" can_" tuck icompare if \ name prefix check
+ 4 /string \ drop prefix from created word
+ can_lib exit
+ then
+ else
+ drop
+ then
+ [ ' wlscope defer@ ] literal execute
+;
+
+' can_scope is wlscope