Hi Henrik,

> I've just reviewed
> http://www.mail-archive.com/picolisp@software-lab.de/msg00097.html again in
> order to move a word index to a separate database file that I want to access
> through the remote/ext mechanism. I know some of the below has been

That post was a little problematical, as it - as we discussed here (or
was it in IRC?) recently - contained some errors, most notably the usage
of the undefined variable 'P'.

Anyway, after that, I corrected and extended the reference
documentation, so that I believe that it is now the most accurate and
up-to-date explanation of the matter.

   (doc '*Ext)
   (doc 'remote/2)

Especially 'remote/2' contains an extensive example. (tested here :)

The critical part is what is the 'rsrc' function in that example. It
must provide a list of cons pairs, each with an "out" and an "in"
function. For now, I would recommend just to use that function, but for
a production application more robustness is needed, to handle closing or
failed connections.


> I've always had a hard time translating examples using ? into something I
> can use, how would I first do in this case:
> 
> (solve
>       (quote @Str Str
>          (select (@Feeds)
>             ((title +Feed @Str))
>             (part @Str @Feeds title)))
>       @Feeds )
> 
> If we pretend that the @Feeds were located in a remote DB and the Str comes
> from a form field in the local process?

The above (local) 'solve' looks all right. However, just as a side note,
if only a single index (here 'title') is searched, you don't need the
full machinery of 'select', and a simple 'db' should do:

   (solve
      (quote
         @Str Str
         (db title +Feed @Str @Feeds) )
      @Feeds )

Assuming the above 'rsrc' and '*Ext' from the reference, the
corresponding remote access would be

   (solve
      (quote
         @Str Str
         @Rsrc (rsrc)
         (remote (@Feeds . @Rsrc)
            (db title +Feed @Str @Feeds) ) )
      @Feeds )

That is, you just embed the normal Pilog query into a 'remote' call.

With 'select' it would be

   (solve
      (quote
         @Str Str
         @Rsrc (rsrc)
         (remote (@Feeds . @Rsrc)
            (select (@Feeds)
               ((title +Feed @Str))
               (part @Str @Feeds title) ) ) )
      @Feeds )


> (collect 'word '+WordCount W W 'article)
> 
> What would the above have to look like if the +WordCounts are located
> remotely?

You mean, without using Pilog? Then you can also send the executable
s-expr directly. I'll try it here with the 'app' demo:

   : (setq Sock (connect "localhost" 4040))
   -> 17
   : (out Sock (pr (list 'collect ''nr ''+Item 2 5 ''nr)))
   -> (collect 'nr '+Item 2 5 'nr)
   : (in Sock (rd))
   -> (2 3 4 5)


> really applicable, a simple custom handler is better. But how do I build it?
> The following is from the article linked to above:
> 
> (task (port 4000)  # Set up the object server in the background
>          (when (setq Sock (accept @))
>             (unless (fork)  # Child process
>                (task P)
>                (close P)

As this is not correct (see above), better use the example in the
reference of '*Ext'. It is also a little bit simpler.

>                (in Sock
>                   (let Data (rd)
>                      (setArticleWords (car Data) (cdr Data))))

While this would work, it would tie the server to a single special
purpose. I would go with the above "standard" server, and just send the
whole command (like the 'collect' example above).

On the local machine, let's assume that the variable 'Art' holds an
article that was received from the remote machine with one of the above
methods ('remote' query, or direct call). Then you can do

   (out Sock (pr 'setArticleWords (lit Art) "Data String"))

The 'lit' is necessary to have the article quoted (and not evaluated) on
the remote side.

Also, you need to read the result after each command, with

   (in Sock (rd))

because the server is set up in such a way that it always sends a
result. If I want to avoid that, I sometimes also set up a server task
that doesn't return anything. This has the advantage that the process
sending the command doesn't have to wait for the answer, so the
throughput is higher.


> On IRC we were discussing remote put> et. al. and you wrote down some
> examples, care to do it again?

The above 'setArticleWords' might be replaced by a simple

   (out Sock (pr 'put!> (lit Art) "Data String"))

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to