On Thu, Aug 21, 2008 at 3:39 PM, V. Glenn Tarcea <[EMAIL PROTECTED]> wrote:
> Hi,
>
>
>
> I've been working on an interface to BerkeleyDB for Factor.
>
Cool!
Say I have a tuple to hold my BerkeleyDB data like DB_ENV, DB, etc…. When I
> need to make a call I often end up with a stack that has the berkeleydb
> object on the bottom of the stack (denoted by <bdb>). When I make a call for
> example to open the database I'll end up with a call like:
>
>
>
> "/tmp/db" XXX bdb-open ! where XXX are flags or'd together.
>
>
>
> So my stack looks like:
>
> <bdb>
>
> "/tmp/db"
>
> XXX
>
Why doesn't bdb-open create a new berkleydb object and return it on the
stack?
> The code in the bdb-open word wants to grab the <bdb> object and pull a
> couple of items from it.
>
>
>
> I was ending up with code that looked like:
>
> >r >r [ dbenv>> ] [ db>> ] bi r> r>
>
You can use 2dip here.
> I'm working my way through supporting all the other operators. Would this
> be of use to anyone else? Is there perhaps a better way? I've noticed I'm
> doing a fair bit of stack shuffling in my code as I slowly get used to
> working with the stack.
>
You will find that you write less and less stack shuffling as you become
more experienced with Factor. So I encourage you to experiment with new
combinators, and so on; but always be on the lookout for tricks to simplify
your code so that you don't need to shuffle at all.
I'm working on a new compiler right now; in 11,000 lines of code, there are
less than a dozen usages of rot, -rot and pick combined. Even swap only
appears in 165 lines; so less than 1 in 50 lines of code needs a swap. This
is because I try to ensure that everything is already in the right order on
the stack.
Slava
-------------------------------------------------------------------------
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