Accidentally sent as private mail, forwarded to list.
-------- Original Message --------
Subject: Re: [Alice-users] HttpServer
Date: Thu, 22 Nov 2007 07:16:21 +0100
From: Michele Simionato <[EMAIL PROTECTED]>
To: Andreas Rossberg <[EMAIL PROTECTED]>
References:
<[EMAIL PROTECTED]>
<[EMAIL PROTECTED]>
On Nov 21, 2007 2:12 PM, Andreas Rossberg <[EMAIL PROTECTED]> wrote:
> But if anybody wants to grab the sources from CVS and extend its
> functionality, then we will be happy to incorporate it. The HTTP stuff is
> relatively straightforward.
I am looking at the source code. At first sight it looks actually
shorter and more understandable that I expected.
Certainly it is a good way to learn tricks for programming in Alice.
For instance, now I am looking at the
stream implementation using promises, which is definitely very cool. I
have a question about the 'send'
function:
fun send (stream, x) =
let
val new = Promise.promise ()
val old = Ref.exchange (stream, new)
in
Promise.fulfill (old, x::Promise.future new)
handle Promise.Promise =>
(Promise.fulfill (new, nil); raise Closed)
(*FIXME: this is not thread-safe! *)
end
What does it mean "this is not thread-safe"? It means that two threads
could try to call the
expression (Promise.fulfill (new, nil); raise Closed) at the same
time, raising another Promise
error which is not trapped? In general, is there a rule of thumb to
know which operations are
thread safe and which are not (the rule could be everything is unsafe
unless stated otherwise,
of course, but I hope not). Also, could you suggest an understandable
reference describing Alice concurrency
model (I mean something for programmers, not a research paper)?
BTW, I have also written my first lazy-list-valued procedure:
(*converts a binary file into a lazy list of chunks*)
fun lazy binfile (fname, chunksize) = let
val inp = BinIO.openIn fname
fun loop acc = let
val vec = BinIO.inputN (inp, chunksize)
in
if Word8Vector.length(vec) = 0 then (BinIO.closeIn inp; rev acc)
else loop (vec :: acc)
end
in
loop []
end
val s = app (print o Byte.bytesToString) (binfile (myfile, 1024))
It seems fine, but I just wanted to make sure that my expectations are
correct. I expect "app" to loop
on the lazy list without first building it entirely in memory, right?
Idem for" fold", correct?
On the other hand, "map" would return a regular list, unless I define
a lazy version of it, as
described in the tutorial. I assume lazy versions of "map" and
possibly other utilities are
somewhere in the Alice library, right? Where should I look?
Thanks for your time,
Michele Simionato
_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users