This is a cool idea.
To be even more useful, the contents of the variable could be stored in a
'model' object. This way, other code could receive notifications when the
model value changes using the existing framework, you could have a gadget
that displays this value in some manner, etc.
For those who couldn't infer it from context, a 'file-backed variable' is a
variable whose contents reflects a Factor expression stored in a file on
disk. When the file is changed, the contents of the variable are updated
automatically.
We haven't used this idiom anywhere yet, but it has potential to simplify
configurable network servers (such as Ed's DNS server), and so on.
Slava
On Fri, Jun 27, 2008 at 8:52 AM, Eduardo Cavazos <[EMAIL PROTECTED]>
wrote:
> Hello,
>
> Here's the main utility word:
>
> monitor-file ( file quot -- )
>
> 'quot' is called when 'file' is changed.
> 'quot' is passed a "file system change descriptor".
> The monitoring happens in a separate thread.
> If 'quot' throws an error, monitoring continues because 'quot' is
> run
> via 'try'.
>
> The 'quot' is run for any kind of change. Here's a word which only runs the
> quot when the file is modified:
>
> on-modify ( file quot -- )
>
> Now I can make this word:
>
> file-variable ( file var -- )
>
> Whenever the 'file' is modified, the file contents are evaluated and the
> resulting value is stored in the variable 'var'.
>
> If there are multiple expressions in the file, the result of evaluating the
> last one is used as the value.
>
> Parsing errors are handled; the old variable value is preserved.
>
> Here's an example:
>
> "/tmp/tbl" tbl file-variable
>
> Set the contents to: 20
>
> tbl get .
> 20
>
> Set the contents to: {
>
> An error appears in the listener. The old value is retained:
>
> tbl get .
> 20
>
> Set the contents to: { 10 20 30 }
>
> tbl get .
> { 10 20 30 }
>
> Implementation is at:
>
> http://paste.factorcode.org/responder/pastebin/show-paste?n=36
>
> Ed
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk