* CamlP4 and Threads
@ 2007-01-27 23:21 Jonathan Bryant
2007-01-28 4:12 ` [Caml-list] " Martin Jambon
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Bryant @ 2007-01-27 23:21 UTC (permalink / raw)
To: caml-list
I'm think I'm finally understanding CamlP4 and I'm trying to make a
small syntax extension using it, but I can't find the rule I need to
extend. I want to turn this:
let f x y x = ....
let x = |f| x y z
into this:
let f x y z = ...
let x =
let c = Event.new_channel () in
let _ = Thread.create (fun c -> let x = f x y z in Event.sync
(Event.send c x)) in
Event.receive c
but, like I said, I can't seem to find the rule I need to extend. I
can do it for an arbitrary expression:
let x = |3 + 5|
to
let x =
let c = Event.new_channel () in
let _ = Thread.create (fun c -> let x = 3 + 5 in Event.sync
(Event.send c x)) in
Event.receive c
just not function application.
I've tried extending Pcaml.expr's "apply" but that doesn't seem to
work, and I can't see any other place to do it.
Also, it seems that the implementation of the Event module has an
error: the above code causes a space leak if x is not synchronized
upon. In CML (the basis for the Event module), threads are GCed when
they go out of scope, so this is not a problem. As a matter of fact,
it is cited as the way to go about things. But since OCaml doesn't
GC threads, this is a problem. Does anyone know of a workaround for
this? And/or should it be submitted as a bug report?
--Jonathan Bryant
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] CamlP4 and Threads
2007-01-27 23:21 CamlP4 and Threads Jonathan Bryant
@ 2007-01-28 4:12 ` Martin Jambon
0 siblings, 0 replies; 2+ messages in thread
From: Martin Jambon @ 2007-01-28 4:12 UTC (permalink / raw)
To: Jonathan Bryant; +Cc: caml-list
On Sat, 27 Jan 2007, Jonathan Bryant wrote:
> I'm think I'm finally understanding CamlP4 and I'm trying to make a small
> syntax extension using it, but I can't find the rule I need to extend. I
> want to turn this:
>
> let f x y x = ....
> let x = |f| x y z
>
> into this:
>
> let f x y z = ...
> let x =
> let c = Event.new_channel () in
> let _ = Thread.create (fun c -> let x = f x y z in Event.sync (Event.send c
> x)) in
> Event.receive c
>
> but, like I said, I can't seem to find the rule I need to extend. I can do
> it for an arbitrary expression:
>
> let x = |3 + 5|
>
> to
>
> let x =
> let c = Event.new_channel () in
> let _ = Thread.create (fun c -> let x = 3 + 5 in Event.sync (Event.send c
> x)) in
> Event.receive c
>
> just not function application.
>
> I've tried extending Pcaml.expr's "apply" but that doesn't seem to work, and
> I can't see any other place to do it.
You have to create a rule for your special function application, e.g.
"|"; f = expr; "|"; args = LIST0 expr LEVEL "." -> ...
Is it what you tried?
Martin
--
Martin Jambon
http://martin.jambon.free.fr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-01-28 4:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-27 23:21 CamlP4 and Threads Jonathan Bryant
2007-01-28 4:12 ` [Caml-list] " Martin Jambon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox