Hello,

>From a Factor listener, you can establish a new vocabulary using
'IN:', and define words and classes to your heart's content in an
experimental fashion. You can also use 'save' and this vocabulary will
persist in your image.

The current state of affairs has a few drawbacks however.

Disorientation: I can create vocabularies in image, but when I restart
the image days or weeks later, I've forgotten about the vocabularies
and their contents.

No persistence via file-out: Let's say you define a tuple class and some
words. You're ready to formalize your work in a disk based vocabulary. You're
pretty much stuck copy and pasting stuff from the history or the
vocabulary browser.

Naming data on the stack: If I have a value on the stack that I want
to name, there's no good way to do it. I think we can do better than
setting a symbol's global value.

By exploring solutions to these three issues, we can enable
a workflow whereby we do more of our creative work in the listener.

Let's start with naming data on the stack. Suppose I have a color on
the stack:

        T{ rgba f 0.5 0 0 1 }

I'd like to name it 'light-red':

        sto light-red

There's now a word called 'light-red' which returns that value.

Let's move to the second point, persistence. This time I'll move into
a new vocabulary:

        IN: my-colors

Establish some values:

        T{ rgba f 0.5 0 0 1 } sto light-red
        T{ rgba f 0 0.5 0 1 } sto light-blue

Now I want to save my work in a file:

        store

What does 'store' do? It writes out the current vocabulary (i.e. the
'in' vocabulary) to disk. The vocabulary is placed in a root called
'store' so as to not overwrite any "system" vocabularies.

At this point I can close the Factor process, restart, and do:

        USE: my-colors

and I'll pick up where I left off. Note that I never did a 'save'.

Finally, let's look at the first point, navigating vocabularies and
viewing their contents.

There's a notion of a 'home' vocabulary. It's called 'home'. :-) I
want to keep track of some local bands. So I'll make a sub-vocabulary
called 'bands':

        ( home ) cd bands
        ( home.bands ) 

I'll define a tuple:

        TUPLE: band name genre ;

I use 'ls' to see what's been done so far:

        ( home.bands ) ls
        tuple classes: 
          band

Let's create some data:

        T{ band f "Waterbear" { "ambient" } }
        sto waterbear

        T{ band f "Combat Astronomy" { "progressive" } }
        sto combat-astronomy

Use 'ls' to check our progress:

        ( home.bands ) ls
        tuple classes: 
          band
        vals: 
          combat-astronomy
          waterbear

And now I feel like defining a 'cube' word:

        : cube dup dup * * ;

Let's see how that shows up in 'ls':

        tuple classes: 
          band
        words: 
          cube
        vals: 
          combat-astronomy
          waterbear

Cool, it didn't show up under 'vals'.

Alright, I'm ready to save my work:

        store

Later I start Factor and am back in the 'home' vocbulary. I use 'ls'
to get oriented:

        ( home ) ls
        subvocabularies: 
          bands

I'm reminded of my 'bands' project. But today I want to work on a
recipe collection:

        ( home ) cd recipe
        ( home.recipe ) : water "fill glass from tap" ;
        ( home.recipe ) store

Move back to the parent vocabulary and list the contents:

        ( home ) ls
        subvocabularies: 
          recipe
          bands

Code implementing these ideas:

        sto     http://paste.factorcode.org/paste?id=102
        store   http://paste.factorcode.org/paste?id=101
        vnav    http://paste.factorcode.org/paste?id=103

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

Reply via email to