That "dump-words" word is enough for my needs most of the time. If I ever
need to improve on that (eg. by factoring out the "USE:") , I think I could
do that myself by looking at the implementation of "see" in the browser...

Thanks a lot! :)

On Tue, Sep 15, 2015 at 12:01 PM, John Benediktsson <mrj...@gmail.com>
wrote:

> Hi Joan,
>
> That looks handy.
>
> The "scratchpad" vocabulary is persisted in the image, so if you ``save``,
> then exit and restart Factor, all the words you had defined will be
> available.
>
> Your technique looks fine, only thing I might add is a newline for spacing
> between definitions and maybe sort them alphabetically instead of randomly,
> and to fix mutually recursive definitions potentially being ordered wrong,
> we DEFER: all words first.
>
>     : dump-words ( vocab path -- )
>         utf8 [
>             vocab-words [ name>> ] sort-with
>             [ "IN: scratchpad" print [ "DEFER: " write name>> print ] each
> nl ]
>             [ [ see nl ] each ] bi
>         ] with-file-writer ;
>
> To save a vocab's words:
>
>      "scratchpad" "~/dump.factor" dump-words
>
> To restore your words from a file:
>
>     "~/dump.factor" parse-file
>
> You'll probably get some "Already using ``...`` vocabulary" warnings,
> because each definitions is "complete" and that saving code doesn't
> aggregate the using list for all definitions that are being persisted.  We
> could work some better code to do that if you care.
>
> Best,
> John.
>
>
>
>
>
>
>
> On Mon, Sep 14, 2015 at 10:34 PM, Joan Arnaldich <jarnald...@gmail.com>
> wrote:
>
>> Hi there,
>>
>> I sometimes use factor as a shell replacement, and many times I define
>> helper functions directly in the listener. Sometimes I would find it
>> helpful to be able to "dump" the definitions into a file, eg. as a backup
>> in case something crashes or just to bootstrap a regular vocabulary with
>> those words as code grows...
>>
>> Is there a standard / recommended way to do this? I guess I could use
>> something like:
>>
>> "dump.factor" utf8 [ "scratchpad" words   [ see ] each  ] with-file-writer
>>
>> ... but before getting into it i'd like to know if it´s already there...
>>
>> Thanks!
>>
>> Joan.
>>
>>
>> ------------------------------------------------------------------------------
>>
>> _______________________________________________
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>>
>>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to