Factor/VocabularyFileout

Currently, vocabularies flow in one direction: from disk to
image. Hopefully someday, they'll flow in the other direction, from
image back to disk.

Let's suppose I'm working on some new project and I'm experimenting at
the listener. I switch to a new vocabulary for the project:

    IN: my-project

And I come up with a few words:

    : a 10 ;
    : b 20 ;

The current state of affairs is such that I can save the image,
restart Factor, and the 'my-project' vocabulary will be
available. However, there will be no sign of it in any of the
vocabulary roots.

So what should the semantics of vocabulary file out be? Let's suppose
there's a 'sync' word. It would "synchronize" the vocabularies in
image with those on disk.

        If a vocabulary exists in image but not in any roots, create a
        new vocabulary on disk.

        If the vocabulary exists in image and on disk, reconcile any
        differences based on the timestamps of the changes.

If I've added words to a vocabulary at the listener, but these don't
exist on disk, then the vocab on disk would be updated.

Programatically filing out vocabularies is an interesting task. We're
used to seeing a vocabulary file structured as follows:

     USING: ... ;

     IN: ... ;

     : a ... ;

     : b ... ;

     ...

A naive fileout mechanism would actually produce a file where each
word is accompanied by it's own 'USING:' statement instead of one
monolithic one at the top of the file. Perhaps there could be some
post-processing to consolidate all the individual USINGs into the
traditional style.

Finally, how to deal with expressions involving parsing words is still
an open problem. I.e. if you do this at the listener:

   TUPLE: abc x y z ;

quite a bit of work is done as a result of parsing the
statement. A fileout mechanism would have to notice the
existence of the 'abc' class and fileout the proper TUPLE statement.

Achiving the fileout capability is important. I think it will
encourage more experimentation with in image vocabulary editing
tools. Another interesting point is that vocabularies can be
viewed as a basic form of persistence. The nice thing is that
vocabularies are much more fine grained than whole images.

Let's say that Factor had a Mac Paint kind of application. I start it
up, draw a picture, and exit the tool. It leave the picture object on
the stack. I go into a new project vocabulary:

    IN: a-new-picture

I then "assign" the object to a word name:

	:> the-picture

At this point I can "synchronize" the system. I've created an object,
given it a name in a new "workspace" and done all of this without
dealing with any files.

http://paste.factorcode.org/paste?id=87

! Paste: Generate a USING: line
! Author: 	elasticdog
! Mode: 	factor
! Date: 	Fri, 31 Oct 2008 02:43:45

USING: arrays kernel sequences sets sorting tools.vocabs.browser ;

: using-line ( vocab -- str )
    dup ".private" append tuck [ vocab-uses ] bi@ append
    prune remove natural-sort "USING:" prefix ";" suffix " " join ;


! Annotation: tweak for edge case when private vocab uses the public vocab's words
! Author: 	elasticdog
! Mode: 	factor
! Date: 	Fri, 31 Oct 2008 03:32:26

USING: kernel sequences sets sorting tools.vocabs.browser ;

: using-line ( vocab -- str )
    dup ".private" append 2dup [ vocab-uses ] bi@
    append prune remove remove natural-sort
    "USING:" prefix ";" suffix " " join ;

This revision created on Tue, 4 Nov 2008 20:42:44 by mnestic