Glenn Tarcea wrote:
> Thanks for the suggestion! If I did this could I have multiple
> databases open? That is, if my constructor was <bdb> and I did that
> twice, could I associate a variable with each <bdb> instance?
Sure, no problem.
The idea is that the words in your library would operate on the db handle
stored in a certain variable. Let's say you call it 'db'.
SYMBOL: db
Let's assume you use this word to open a database:
: open-db ( file -- db-handle ) ... ;
A user might open a few databases:
SYMBOL: db-1
SYMBOL: db-2
"/tmp/db-1" open-db db-1 set
"/tmp/db-2" open-db db-2 set
Now is they want to operate on 'db-1' they do:
db-1 get db set
... call some db words here ...
You can have a 'with-db' word:
: with-db ( db quot -- ) ... ;
Which calls quot with the db argument bound to 'db'. So code would look like:
db-1 get
[ ... operations on db-1 ]
with-db
db-2 get
[ ... operations on db-2 ]
with-db
Using a variable for cases like this is very common. That you were running
into some tricky stack situations is a hint that using a variable might be in
order.
Ed
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk