example: hiding words

FossilOrigin-Name: 6364b578975dd03353f9138725de9779bbf8e581607e5a4283b10ccb17f1cf82
This commit is contained in:
crc 2021-04-22 15:15:15 +00:00
parent e82794ec72
commit f0257387d4
2 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,39 @@
# Hiding Words
It's often useful to be able to hide a word from the global
dictionary. This can be done with the lexical scope words,
but here I present a different approach.
To hide a word, it is sufficient to change its name to
something that will never be matched. Since strings are
null terminated, just replacing the first character with
a null suffices.
So all that needs to be done is to create an array of headers
we want to hide, then iterate over that to smudge out the
names.
# Code
~~~
'To-Hide d:create #65 allot
:private @Dictionary @To-Hide &To-Hide + n:inc store &To-Hide v:inc ;
:hide-private
&To-Hide [ d:name v:off ] a:for-each &To-Hide v:off ;
~~~
# Example
```
:a ;
:b ; private
:f ; private
:c ;
:d ; private
:e ;
hide-private
```

View file

@ -1,6 +1,14 @@
#include <stdint.h>
#ifndef CELL
#ifndef BIT64
#define CELL int32_t
#define CELL_MIN INT_MIN + 1
#define CELL_MAX INT_MAX - 1
#else
#define CELL int64_t
#define CELL_MIN LLONG_MIN + 1
#define CELL_MAX LLONG_MAX - 1
#endif
#endif
CELL ngaImageCells = 10220;
CELL ngaImage[] = { 1793,-1,10207,10219,202104,0,10,1,10,2,10,3,10,4,10,5,10,6,10,