I don't understand this example. What does C[ ] do? Does it package up the quotation with the dynamic scope or something?
Dan On Thu, Jun 26, 2008 at 8:33 AM, Eduardo Cavazos <[EMAIL PROTECTED]> wrote: > Hello, > > This example is a notable use of fry; it would be awkward without it. > > I wanted to monitor a directory and update some variables in the current > namespace upon changes made to the directory or it's contents. > > The help for 'with-monitors' mentions that the quot is run inside a new scope. > This signals to me that I need to turn my quot into a namespace closure > (vocab: rewrite-closures). > > In this example, I'll increment the value of a variable 'a' when changes to a > directory "/tmp/test-dir-105" are made. > > Here's some setup: > > ---------------------------------------------------------------------- > USING: threads io.monitors rewrite-closures fry ; > > SYMBOL: a > > 0 a set > > : action ( monitor -- monitor ) > [ next-change 2drop a get 1 + a set ] [ action ] bi ; > ---------------------------------------------------------------------- > > The code to start monitoring often resembles something like this: > > [ > [ "/tmp/test-dir-105" t <monitor> action ] with-monitors > ] > in-thread > > The problem there is that 'action' is run in the scope provided > by 'with-monitors'. > > Here's an attempt: > > C[ "/tmp/test-dir-105" t <monitor> action ] > > [ with-monitors ] curry in-thread > > Now the 'action' is inside a quot closed over the current namespace, but this > still doesn't work. The problem is that '<monitor>' needs to be run in the > namespace provided by 'with-monitors'. > > So finally, we have this: > > C[ action ] > '[ > [ "/tmp/test-dir-105" t <monitor> , call ] with-monitors > ] > in-thread > > This does the job and depends on fry's ability to embed items into nested > quotations. > > 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
