aboutsummaryrefslogtreecommitdiff
path: root/amforth-6.5/examples/scope.frt
blob: d6a5d3148ff0a1b6f8efee14a3d62494cddab51d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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