Re: [Chicken-users] inter-thread communication

2005-05-26 Thread Michele Simionato
On 5/27/05, felix winkelmann <[EMAIL PROTECTED]> wrote:
> On 5/27/05, Michele Simionato <[EMAIL PROTECTED]> wrote:
> > I am starting to look at multithreading in Chicken and it is not clear to me
> > how to do inter-thread communication. Here is my use case: I have multiple
> > writers and a single reader; I would like the writers to write on a port and
> > the reader to read from it, blocking while the data are not arriving.
> > Is there a specific  mechanism to manage this typical situation? (i.e.
> > in Python I have a Queue class for this).
> 
> You should use the `mailbox' extension for this:
> 
> http://www.call-with-current-continuation.org/eggs/mailbox.html
> 
> (these are just thread-safe queues)

Just what I needed! :-)

   Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] inter-thread communication

2005-05-26 Thread felix winkelmann
On 5/27/05, Michele Simionato <[EMAIL PROTECTED]> wrote:
> I am starting to look at multithreading in Chicken and it is not clear to me
> how to do inter-thread communication. Here is my use case: I have multiple
> writers and a single reader; I would like the writers to write on a port and
> the reader to read from it, blocking while the data are not arriving.
> Is there a specific  mechanism to manage this typical situation? (i.e.
> in Python I have a Queue class for this).

You should use the `mailbox' extension for this:

http://www.call-with-current-continuation.org/eggs/mailbox.html

(these are just thread-safe queues)


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] an ode to Spiffy

2005-05-26 Thread felix winkelmann
On 5/26/05, Mario Domenech Goulart <[EMAIL PROTECTED]> wrote:
> 
> It may look a bit silly and ugly, but some time ago I made something
> that looks like that (if my guess about what LAML is is correct --
> couldn't read the papers yet).
> 
> It's at http://www.inf.ufrgs.br/~mario/english/utils/web-scheme
> 
> Disclaimer:
> 
> - I made it without looking for previous work about this topic. So, if
>   some ideas are badly implemented or if there things that just look too
>   silly, it's my fault.
> 
> - The code is far from being good (horrible, in fact :-))
> 
> Originally it was just an attempt to get rid of some even more ugly
> scripts I use to generate headers and footers to some of my html pages
> and to use some programming stuff embedded in web pages with a cleaner
> syntax.  Now it's not even that because I didn't convert those
> pages. :-)
> 

Well, I think this looks (and works) pretty well. Would it be ok for you if
we turn this into an egg?


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] inter-thread communication

2005-05-26 Thread Michele Simionato
I am starting to look at multithreading in Chicken and it is not clear to me 
how to do inter-thread communication. Here is my use case: I have multiple 
writers and a single reader; I would like the writers to write on a port and
the reader to read from it, blocking while the data are not arriving.
Is there a specific  mechanism to manage this typical situation? (i.e.
in Python I have a Queue class for this). 

 Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] an ode to Spiffy

2005-05-26 Thread Mario Domenech Goulart
On Thu, 26 May 2005 11:35:16 +0200 felix winkelmann <[EMAIL PROTECTED]> wrote:

> On 5/26/05, Peter Busser <[EMAIL PROTECTED]> wrote:
>> 
>> BTW, while talking about SXML, has anyone looked at getting LAML to work on
>> Chicken? (http://www.cs.auc.dk/~normark/laml/)
>> 
>
> I have started once but lost interest. It shouldn't be too hard to port,
> though...
>
> (Hint, hint!)

It may look a bit silly and ugly, but some time ago I made something
that looks like that (if my guess about what LAML is is correct --
couldn't read the papers yet).

It's at http://www.inf.ufrgs.br/~mario/english/utils/web-scheme

Disclaimer:

- I made it without looking for previous work about this topic. So, if
  some ideas are badly implemented or if there things that just look too
  silly, it's my fault.

- The code is far from being good (horrible, in fact :-))

Originally it was just an attempt to get rid of some even more ugly
scripts I use to generate headers and footers to some of my html pages
and to use some programming stuff embedded in web pages with a cleaner
syntax.  Now it's not even that because I didn't convert those
pages. :-)

Best whishes,
Mario



___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


RE: [Chicken-users] an ode to Spiffy

2005-05-26 Thread Dominique Boucher
Felix, 

> Hm. Could you try this, please:
> [...]
> $ ./repltest
> #;> (thread-start! (lambda () (let loop ((i 0)) (print i) 
> (thread-sleep! 1) (loop (add1 i) ; from now on you should 
> still be able to eval expressions...
> 

That worked out of the box for me.

> [This is normally done in srfi-18.scm, but is disabled on Windows.
> Should this work with cygwin (requires select(2)), I'll 
> disable it exclusively for Windows/MSVC (which doesn't have 
> select(2) on file/stdio fd's)]

Please, do so!

Thanks a lot, 

Dominique





___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] session handling with Spiffy

2005-05-26 Thread Michele Simionato
On 5/26/05, Peter Bex <[EMAIL PROTECTED]> wrote:
> On Thu, May 26, 2005 at 05:31:10AM -0400, Michele Simionato wrote:
> > I see that spiffy-utils has functions to manage cookies, so it should be 
> > easy to
> > set up a login/logout system. Are there examples already available? Also,
> > is there the equivalent of a session object?
> > Thanks for any pointer,
> >
> > Michele Simionato
> 
> I have created a simple login system, but unfortunately it isn't very generic
> and it's quite hacky since it was my second Scheme project ever :)
> It uses the PostgreSQL egg and cookies.  If you want, I could send you the
> code.

Yes, thank you, it is just to have examples of usage.


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] session handling with Spiffy

2005-05-26 Thread Peter Bex
On Thu, May 26, 2005 at 05:31:10AM -0400, Michele Simionato wrote:
> I see that spiffy-utils has functions to manage cookies, so it should be easy 
> to
> set up a login/logout system. Are there examples already available? Also,
> is there the equivalent of a session object?
> Thanks for any pointer,
> 
> Michele Simionato

I have created a simple login system, but unfortunately it isn't very generic
and it's quite hacky since it was my second Scheme project ever :)
It uses the PostgreSQL egg and cookies.  If you want, I could send you the
code.

Regards,
Peter
-- 
http://www.student.kun.nl/peter.bex
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
-- Donald Knuth


pgp73pyRU0hbQ.pgp
Description: PGP signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] session handling with Spiffy

2005-05-26 Thread Michele Simionato
I see that spiffy-utils has functions to manage cookies, so it should be easy to
set up a login/logout system. Are there examples already available? Also,
is there the equivalent of a session object?
Thanks for any pointer,

Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] an ode to Spiffy

2005-05-26 Thread felix winkelmann
On 5/26/05, Peter Busser <[EMAIL PROTECTED]> wrote:
> 
> BTW, while talking about SXML, has anyone looked at getting LAML to work on
> Chicken? (http://www.cs.auc.dk/~normark/laml/)
> 

I have started once but lost interest. It shouldn't be too hard to port,
though...

(Hint, hint!)


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] an ode to Spiffy

2005-05-26 Thread Peter Busser
> > A few things are missing  (for
> >instance form validation) but I can implement it in minutes with a nice
> >macro in a completely interactive way. Plus, I like SXML at least as
> >much as I hate HTML :) I think I will write a small tutorial about how
> >to use Spiffy for writing simple Web interfaces, which is the thing I
> >am interested in, since I want to use Scheme to do fast prototyping of
> >Web applications. Scheme is *extremely* suitable for this job, it sad
> >that most people don't realize that because of Scheme general attitude
> >to discourage users making things harder than needed (Chicken is maybe
> >an exception to this general rule, since Felix clearly shows some
> >concerns for usability and practicality).
>
> I'm sure you've read what Paul Graham has to say after using Lisp
> (almost as nice as Scheme :-) for web applications in ViaWeb?

BTW, while talking about SXML, has anyone looked at getting LAML to work on 
Chicken? (http://www.cs.auc.dk/~normark/laml/)

It contains also some papers about SXML and XML transformation in Scheme.

Groetjes,
Peter.


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] an ode to Spiffy

2005-05-26 Thread Sunnan
Magnus Therning <[EMAIL PROTECTED]> writes:

> I'm sure you've read what Paul Graham has to say after using Lisp
> (almost as nice as Scheme :-) for web applications in ViaWeb?

He used CPS because full continuations weren't available; maybe Scheme
could do it nicer.

-- 
.i mi'e snan .i mi rodo roda fraxu


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] url-encoded arguments et similia

2005-05-26 Thread felix winkelmann
On 5/26/05, Michele Simionato <[EMAIL PROTECTED]> wrote:
> BTW, I have another question about the code I just posted: I see that there is
> "handle-exceptions" macro whuch is not documented. Should I assume it is
> an internal facility I should not use, or just that you had no time to
> update the manual yet?
> 

It's SRFI-12 (there should be a link in the manual):

http://srfi.schemers.org/srfi-12


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] an ode to Spiffy

2005-05-26 Thread Magnus Therning
On Wed, May 25, 2005 at 07:54:26AM -0400, Michele Simionato wrote:
>As most people, I usually post to the mailing list when I get in
>trouble on when I have something to complain about. However, this does
>not mean that I am always unhappy with Chicken. So, just for love of
>equity, I have decided this time to write a support message for Spiffy.
>Great job, Felix! :-) Spiffy works pretty nice, in a morning I think I
>have got most of it without big issues (or maybe I am so happy only
>because it is so much better of http-server ;). I can run spiffy in a
>separate thread, add resources from the REPL, see what happens in real
>time,  correct the errors and use the interpreter for anything else,
>all without restarting the server.  A few things are missing  (for
>instance form validation) but I can implement it in minutes with a nice
>macro in a completely interactive way. Plus, I like SXML at least as
>much as I hate HTML :) I think I will write a small tutorial about how
>to use Spiffy for writing simple Web interfaces, which is the thing I
>am interested in, since I want to use Scheme to do fast prototyping of
>Web applications. Scheme is *extremely* suitable for this job, it sad
>that most people don't realize that because of Scheme general attitude
>to discourage users making things harder than needed (Chicken is maybe
>an exception to this general rule, since Felix clearly shows some
>concerns for usability and practicality).

I'm sure you've read what Paul Graham has to say after using Lisp
(almost as nice as Scheme :-) for web applications in ViaWeb?

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
[EMAIL PROTECTED]
http://magnus.therning.org/

Software is not manufactured, it is something you write and publish.
Keep Europe free from software patents, we do not want censorship
by patent law on written works.

Crypto is not mathematics, but crypto can be highly mathematical,
crypto can use mathematics, but good crypto can be done without a
great reliance on complex mathematics.
  -- W T Shaw


pgp5erSJclNPt.pgp
Description: PGP signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] url-encoded arguments et similia

2005-05-26 Thread Michele Simionato
On 5/26/05, felix winkelmann <[EMAIL PROTECTED]> wrote:
> That parameter is only bound in the "fallback-handler", that is, for special
> requests like .ssp pages.
> Here's a patch for spiffy.scm: 

Cool! Please make it

 (parameterize ((current-urlencoded-arguments ,args) (current-request ,req))

so that post-var works too. Actually I like a lot this function, which
I have extracted from define-http-resource:

 (define (add-dynamic-resource url thunk)   
   (http:add-resource url
 (lambda (request args)
   (parameterize ((current-urlencoded-arguments args)
  (current-request request))
   (let/cc return
 (let/ respond (http-resource:responder request return)
   (handle-exceptions exn
 (parameterize 
  ([http:error-response-handler (http-resource:error-handler exn)])
  (http:write-error-response 500 "Internal Server Error"))
(respond (thunk)

Maybe it would be a good idea to expose it directly, would do you think?

 Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] url-encoded arguments et similia

2005-05-26 Thread Michele Simionato
BTW, I have another question about the code I just posted: I see that there is
"handle-exceptions" macro whuch is not documented. Should I assume it is
an internal facility I should not use, or just that you had no time to
update the manual yet?

   Michele Simionato


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] url-encoded arguments et similia

2005-05-26 Thread felix winkelmann
On 5/26/05, Michele Simionato <[EMAIL PROTECTED]> wrote:
> After yesterday praise, let's come back to the usual posts of problems
> & issues ;)
> It seems I cannot get argument, current-urlencoded-arguments, post-var
> and get-var working. Here is an example of the issue:
> 
>  (define-http-resource (/get-a-b a b)
> `(div
>   (form (@ (method "get"))
>(input (@ (type "text") (name "a"))) (br)
>(input (@ (type "text") (name "b"))) (br)
>(input (@ (type "submit") (name "ok"
>,(format "a = ~s b = ~s args = ~a" a b 
> (current-urlencoded-arguments
> 
>  (current-urlencoded-arguments) gives the empty string all the time, no
> matter what is in the query string. For instance if I point my browser to
> 
> http://localhost:4242/get-a-b?a=1&b=2&ok
> 
> I get
> 
> a = "1" b = "2" args = ()
> 
> What am I missing?
> 

That parameter is only bound in the "fallback-handler", that is, for special
requests like .ssp pages.
Here's a patch for spiffy.scm:

cd /home/fwinkel/tmp/
diff -c /home/fwinkel/tmp/spiffy.scm\~ /home/fwinkel/tmp/spiffy.scm
--- /home/fwinkel/tmp/spiffy.scm~   2005-03-02 23:07:13.0 +0100
+++ /home/fwinkel/tmp/spiffy.scm2005-05-26 08:48:40.131738408 +0200
@@ -48,14 +48,15 @@
 `(http:add-resource
   ,url
   (lambda (,req ,args)
-   (call/cc
-(lambda (,ret)
-  (let ([respond (http-resource:responder ,req ,ret)])
-(handle-exceptions exn
-(parameterize ([http:error-response-handler
(http-resource:error-handler exn)])
-  (http:write-error-response 500 "Internal Server Error") )
-  (respond
-   (let ,(map (lambda (arg)
-`(,(string->symbol (car arg)) (alist-ref ,(car 
arg) ,args
string-ci=? ,(cdr arg))) )
-  rargs)
- ,@body) ) ) ) ) ) ) ) ) )
+   (parameterize ((current-urlencoded-arguments ,args))
+ (call/cc
+  (lambda (,ret)
+(let ([respond (http-resource:responder ,req ,ret)])
+  (handle-exceptions exn
+  (parameterize ([http:error-response-handler
(http-resource:error-handler exn)])
+(http:write-error-response 500 "Internal Server Error") )
+(respond
+ (let ,(map (lambda (arg)
+  `(,(string->symbol (car arg)) (alist-ref ,(car 
arg) ,args
string-ci=? ,(cdr arg))) )
+rargs)
+   ,@body) ) ) ) ) ) ) ) ) ) )


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] an ode to Spiffy

2005-05-26 Thread felix winkelmann
On 5/25/05, Dominique Boucher <[EMAIL PROTECTED]> wrote:
> 
> > I can run
> > spiffy in a separate thread, add resources from the REPL, see
> 
> How do you do that? Spiffy must be started in a separate thread, but it
> seems that the REPL blocks all other threads (at least under cygwin,
> AFAICT). I need to issue a (thread-sleep! 10) when I want to test a new
> resource handler. Am I missing something obvious?
> 

Hm. Could you try this, please:

$ cat repltest.scm
 (use srfi-18)

 (set! ##sys#read-prompt-hook
(let ([old ##sys#read-prompt-hook]
  [thread-yield! thread-yield!] )
  (lambda ()
(when (or (##sys#fudge 12) (##sys#tty-port? ##sys#standard-input))
  (old)
  (##sys#thread-block-for-i/o! ##sys#current-thread 0 #t)
  (thread-yield! ) 

(repl)  
$ csc repltest.scm
$ ./repltest
#;> (thread-start! (lambda () (let loop ((i 0)) (print i)
(thread-sleep! 1) (loop (add1 i)
; from now on you should still be able to eval expressions...

[This is normally done in srfi-18.scm, but is disabled on Windows.
Should this work with cygwin (requires select(2)), I'll disable it
exclusively for Windows/MSVC (which doesn't have select(2) on
file/stdio fd's)]


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users