
Example Using SID
Following on from the example on the previous page where we started to look at a simple set of words to control the on board LED of the BV511. This texts looks at the best ways for using the scope ID so that there will not be a clash of similar words.
At the start of the the p0.31.fth file is this:
// #URL-lib "http://pin1.org/forthlib/flb/general/pinsel.flb"
variable tog
// set p31 to an output, -ve numbers are used for port 1 and
// +ve for port 0
: p0.31-setup
31 io-out
// set p0.31 to o/p
0 tog !
// set variable to 0
;
The word used for setting up the on board LED is io-out, if you take a look at this in pinsel.flb, you will see that it is defined as follows.
// setting up the ports for i/o uses a
similar data technique
: <0>io-out
( port --- )
dup
0 <
if
abs io1-out else
io0-out then ;
Notice that the word is defined as <0>io-out. Both BV Forth and BVT recognise this as being the word io-out defined with a SID of 0, regardless of the current setting of SID. If you loaded just p0.31-setup using BVT, when BVT encountered io-out it will not only load this word but ALL of the other words that io-out needs and words that need those words and so on until complete.
By default all of these words will be defined using the current SID, whatever SID is set to when the file was encountered, this is 0 at reset. This means that all of the words that io-out needs will also have the default, current SID so although you have only defined p0.31-setup there will be lots of other words defined also.
Try this by loading the p0.31.fth file form the examples library (over to the left).

You will see that because io-out or one of the words it requires also requires PINSEL2, that word is now part of your code. The problem with this is, is that what there are many libraries you cannot be sure if you are redefining a library word with one of your own words.
Going back to pinsel.flb you will observe that only a handful of words begin with <0>, these are the words that are really needed, all of the other words simply support those words. In OOPS terms these would be the public functions. So as not to clutter your code with unwanted words a SID (Scope ID) can be specified for each library loaded, this is done thus:
// #URL-lib "http://pin1.org/forthlib/flb/general/pinsel.flb" sid=55
Now when BVT loads a word from this library it will set the SID to 55 first (SID can be any number between 0 and 254), so that all of the library words will have a SID of 55 and will not be visible from any other SID. Relating this back to p0.31.fth, if you place sid=55 next to the library directive as above, reset, reload. Only the words you have defined and io-out will be visible in your default SID which happens to be 0.
Note: you must clear the library and reload it
again when changing the SID
![]()

See now that PINSEL2 is not visible but has actually been used by io-out. It has in fact been compiled with a SID of 55, changing to SID 55 (55 sid !) will reveal that it is there.
Further
You can in fact take this even further. p0.31-setup is only needed by other words in this file, it is only a means to an end, lets say the word 'go' is the only word that you want from this file:
: <0>go
p0.31-setup
begin
100 ms
p0.31-toggle
key?
until
;
Place the <0> in front of this word and add // #currentSID sid=10 to the top of the file and // #currentSID sid=0 to the bottom of the file (see p0.31-sid.fth in examples). Now all of the file will be compiled with a SID of 10 except go which will have a SID of 0. This will effectively be the only user word in the system.

As can bee seen not even p0.31-setup is visible from a SID of 0, only go is. Just a note in case you get confused as I did once. A word defined with a SID of 0 is special in that it is visible from all SID's. The full SID description is in here, look for 'BVForth Supplement S1 - SID'. The BV Terminal manual that lists the available directives and how to use them is in here, you will need version 3.20 or greater.