* camlp4: processing lists
@ 2007-03-20 10:27 Hugo Ferreira
2007-03-20 10:54 ` [Caml-list] " Nicolas Pouillard
0 siblings, 1 reply; 3+ messages in thread
From: Hugo Ferreira @ 2007-03-20 10:27 UTC (permalink / raw)
To: caml-list
Hello,
I have sent this post to the new ocaml-developer list but am resending
it here in the hopes that someone can help me. I have come across a
weirdness in camlp4. Maybe someone can explain this puzzle to me.
I have the following extension:
let expand_term_list loc l =
let nl = <:expr< [] >> in
let nl = List.fold_right (fun h t ->
<:expr< [$h$::$t$] >>
) l nl in
<:expr<
do {
List.iter (fun i -> print_endline i) $nl$
}
>>
EXTEND
Pcaml.expr: [
[
"|" ; "[" ; l = LIST0 Pcaml.expr SEP ";" ; "]" ; "|"->
expand_term_list loc l ] ];
END;;
I compile the source below with the camlp4 extension above:
....
let t1 =
List.iter (fun i -> print_endline i) ["1"; "f(X,Y)"; "g(X,Y)"; "4"]
in
()
And the execution gives me:
4
If I generate the original and revised syntax output using the extension
above using for example:
camlp4o -I . pr_o.cmo pa_$(NAME).cmo $(PROG).ml -o $(PROG).ppo
camlp4o -I . pr_r.cmo pa_$(NAME).cmo $(PROG).ml -o $(PROG).ppr
I get for $(PROG).ppo
...
let t1 =
List.iter (fun i -> print_endline i) ["1"; "f(X,Y)"; "g(X,Y)"; "4"]
in
()
which is what I expect for the original syntax... but for the revised
syntax $(PROG).ppr I get:
let t1 =
do {
print_string "Not implemented for list ";
List.iter (fun i -> print_endline i)
[do { "1"; "f(X,Y)"; "g(X,Y)"; "4" }]
}
in
()
which ... to say the least is *not* what I expected. I initially I
though I had but one Pcaml.expr and not a list of those. What seems
to be happening is that the revised syntax is used to generate the
code and this is wrong.
Can anyone tell me what mess I have done?
TIA,
Hugo Ferreira.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] camlp4: processing lists
2007-03-20 10:27 camlp4: processing lists Hugo Ferreira
@ 2007-03-20 10:54 ` Nicolas Pouillard
2007-03-20 11:14 ` Hugo Ferreira
0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Pouillard @ 2007-03-20 10:54 UTC (permalink / raw)
To: Hugo Ferreira; +Cc: caml-list
On 3/20/07, Hugo Ferreira <hmf@inescporto.pt> wrote:
> Hello,
>
> I have sent this post to the new ocaml-developer list but am resending
> it here in the hopes that someone can help me. I have come across a
> weirdness in camlp4. Maybe someone can explain this puzzle to me.
>
> I have the following extension:
>
> let expand_term_list loc l =
> let nl = <:expr< [] >> in
> let nl = List.fold_right (fun h t ->
> <:expr< [$h$::$t$] >>
> ) l nl in
> <:expr<
> do {
> List.iter (fun i -> print_endline i) $nl$
> }
> >>
>
> EXTEND
> Pcaml.expr: [
> [
> "|" ; "[" ; l = LIST0 Pcaml.expr SEP ";" ; "]" ; "|"->
Pcaml.expr is too greedy here. Since 1; 2 is a valid ocaml expression.
You need to choose another level ("expr1" in your case and "top" in 3.10).
> "|" ; "[" ; l = LIST0 Pcaml.expr LEVEL "expr1" SEP ";" ; "]" ; "|"->
> expand_term_list loc l ] ];
> END;;
>
[...]
>
> let t1 =
> do {
> print_string "Not implemented for list ";
Here you reached a bug (fixed for 3.10)
> List.iter (fun i -> print_endline i)
> [do { "1"; "f(X,Y)"; "g(X,Y)"; "4" }]
> }
> in
> ()
>
> which ... to say the least is *not* what I expected. I initially I
> though I had but one Pcaml.expr and not a list of those. What seems
> to be happening is that the revised syntax is used to generate the
> code and this is wrong.
The in revised 1; 2 is not a valid expression you need to add do { ...
} thus by printing it in the revised syntax you see that was not what
you want.
BTW it was a bug in camlp4 to print [1; 2] where it was [(1; 2)].
Hope this helps,
--
Nicolas Pouillard
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] camlp4: processing lists
2007-03-20 10:54 ` [Caml-list] " Nicolas Pouillard
@ 2007-03-20 11:14 ` Hugo Ferreira
0 siblings, 0 replies; 3+ messages in thread
From: Hugo Ferreira @ 2007-03-20 11:14 UTC (permalink / raw)
To: caml-list
Hi,
Nicolas Pouillard wrote:
> On 3/20/07, Hugo Ferreira <hmf@inescporto.pt> wrote:
>> Hello,
>>
>
> Here you reached a bug (fixed for 3.10)
>
>> List.iter (fun i -> print_endline i)
>> [do { "1"; "f(X,Y)"; "g(X,Y)"; "4" }]
>> }
>> in
>> ()
>>
So I take it that I either wait for 3.10 or circumvent this problem with
a non-revised syntax print.
>
> The in revised 1; 2 is not a valid expression you need to add do { ...
> } thus by printing it in the revised syntax you see that was not what
> you want.
> BTW it was a bug in camlp4 to print [1; 2] where it was [(1; 2)].
>
> Hope this helps,
>
It has indeed.
Thank you,
Hugo Ferreira.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-03-20 11:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-20 10:27 camlp4: processing lists Hugo Ferreira
2007-03-20 10:54 ` [Caml-list] " Nicolas Pouillard
2007-03-20 11:14 ` Hugo Ferreira
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox