Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread JmageK
Jun 7, 2019, 7:31 PM by a...@software-lab.de:

> On Fri, Jun 07, 2019 at 03:39:12PM +0200, JmageK wrote:
>
>> Why is the dot neccesary for the subexpression to be bound, is it a general
>> rule that's documented somewhere?
>>
>
> I would say it is a general rule, following from the (CAR . CDR) principle of
> Lisp data.
>
This cons thing gets me, always!
> In our case, the CAR is 'cond' and the CDR is @X
>
> Without the dot (cond @X) is filled to
>
> (cond (((match ...
>
Okay so this step is where it becomes mandatory to use a dot.
> while *with* the dot it becomes
>
> (cond . (((match ...
>
> which is the same as
>
> (cond ((match ...)))
>
> which in turn is what we need here.
>
>
Otherwise it won't work(previous version)
Now it makes sense. Apparently, it's the little stuff that bugs the most. 
Thanks for the explanation!

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread Alexander Burger
On Fri, Jun 07, 2019 at 04:01:15PM +0200, Alexander Burger wrote:
> In our case, the CAR is 'cond' and the CDR is (((match ...)))

Oops, not fully correct! I meant:

   ... the CAR is 'cond' and @X is ...

☺/ A!ex

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread Alexander Burger
On Fri, Jun 07, 2019 at 03:39:12PM +0200, JmageK wrote:
> Hope not bugging too much, haha .

No worry! I don't feel bugged, and I believe other readers here too 

☺/ A!ex

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread Alexander Burger
On Fri, Jun 07, 2019 at 03:39:12PM +0200, JmageK wrote:
> Why is the dot neccesary for the subexpression to be bound, is it a general
> rule that's documented somewhere?

I would say it is a general rule, following from the (CAR . CDR) principle of
Lisp data.

In our case, the CAR is 'cond' and the CDR is (((match ...)))

Without the dot (cond @X) is filled to

   (cond (((match ...

while *with* the dot it becomes

   (cond . (((match ...

which is the same as

   (cond ((match ...)))

which in turn is what we need here.

☺/ A!ex

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread JmageK



> Thus, '@X' gets bound to
>
>  (((match '("-" @X "." "h" "t" "m" "l") U)
>  (and *SesId (timeout *Timeout))
>  ... ) ) ) )
>
> Note the additional list level, as 'match' binds its parameters to lists!
>
> So we need the dot in
>
>  (out *HtSock (cond . @X))
>
> so that this subexpression gets properly restored.
>
Why is the dot neccesary for the subexpression to be bound, is it a general 
rule that's documented somewhere?

And thanks for the explanation & help. Now it works perfectly well. Hope not 
bugging too much, haha .


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread Alexander Burger
On Fri, Jun 07, 2019 at 02:36:20PM +0200, Alexander Burger wrote:
>(patch http '(out *HtSock (cond @X))
>   (fill
>  '(prog
> (ana)
> (out *HtSock (cond . @X)) ) ) )

The 'prog' is ugly. We should better avoid it. As logging
does its own 'out', we can move it like this:

   (patch http '(out *HtSock (cond @X))
  (fill
 '(out *HtSock
(ana)
(cond . @X)) ) )

☺/ A!ex

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread Alexander Burger
Hi JmageK,

> The patch is a nice function. I'm having a hard time understanding this entire
> code. Can you explain how it works? What gets bound to @X? Thanks!

Sure!

   (patch http '(out *HtSock (cond @X))
  (fill
 '(prog
(ana)
(out *HtSock (cond . @X)) ) ) )


The first argument to 'patch' is the value of 'http', i.e. the whole function
definition to be modified.

The second argument is the pattern. It matches to the expression

   (out *HtSock
  (cond
 ((match '("-" @X "." "h" "t" "m" "l") U)
(and *SesId (timeout *Timeout))
... ) ) )

Thus, '@X' gets bound to

 (((match '("-" @X "." "h" "t" "m" "l") U)
(and *SesId (timeout *Timeout))
... ) ) ) )

Note the additional list level, as 'match' binds its parameters to lists!

So we need the dot in

   (out *HtSock (cond . @X))

so that this subexpression gets properly restored.

☺/ A!ex

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread Alexander Burger
On Fri, Jun 07, 2019 at 02:17:46PM +0200, JmageK wrote:
> (patch http '(out *HtSock (cond @X))
>   (fill
>  '(prog
>     (ana)
>     (out *HtSock (cond @X)) ) ) )

Oops, sorry! I copied the wrong version into my mail.

The version I tested here had this as the last line:

 (out *HtSock (cond . @X)) ) ) )

☺/ A!ex

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread JmageK
Jun 7, 2019, 3:49 PM by a...@software-lab.de:

> Hi JmageK,
>
>> My question is how to have picolisp run the ana function whenever a request
>> for a file or another html page arrives when it's running as a generic 
>> server.
>>
>
> Usually I log only new sessions, by loading @lib/app.l in production
> applications. This logs with 'msg' calls at the end of that file, the first 
> one
> when the server is started, and then once for each new session.
>
I checked @lib/app.l it looks cool
> If you want to log *every* access, you could do that by patching 'http', e.g.
> with
>
I tried the patch it logs but gets some errors and fails to server any file

#This is f2.l file 
(load'@lib/http.l'@lib/xhtml.l)

(de ana ()
   (out "+log.txt" (prinl *Url " " (pack *Agent) " "*Referrer " "*Adr " " (time 
(time )
(patch http '(out *HtSock (cond @X))
  (fill
 '(prog
    (ana)
    (out *HtSock (cond @X)) ) ) )
(de main()
   (html 0 "title" "lib.css" ""
  ( () "header 1") (ana) ) )
(server (format (opt)) "!main")

#start server at port 8090
$ pil f2.l 8090 +

#Visit localhost in a web browser
localhost:8090

#I get no data sent error in browser and the connection stuck
#on the server side the following one

!? ((match '("-" @X "." "h" "t" "m" "l") U) (and *SesId (timeout *Timeout)) 
(apply try L 'html> (extern (ht:Pack @X T
NIL -- Undefined
?
I'm unable to properly check which one is NIL--data gets corrupt on terminal 
when typing, I think it's html> 


>  (patch http '(out *HtSock (cond @X))
>  (fill
>  '(prog
>  (ana)
>  (out *HtSock (cond @X)) ) ) )
>
The patch is a nice function. I'm having a hard time understanding this entire 
code. Can you explain how it works? What gets bound to @X? Thanks!

JmageK


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: Run a function whenever a request for a file arrives on the picolisp web server

2019-06-07 Thread Alexander Burger
Hi JmageK,

> My question is how to have picolisp run the ana function whenever a request
> for a file or another html page arrives when it's running as a generic server.

Usually I log only new sessions, by loading @lib/app.l in production
applications. This logs with 'msg' calls at the end of that file, the first one
when the server is started, and then once for each new session.

If you want to log *every* access, you could do that by patching 'http', e.g.
with

   (patch http '(out *HtSock (cond @X))
  (fill
 '(prog
(ana)
(out *HtSock (cond @X)) ) ) )

☺/ A!ex

-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe