Version française
Home     About     Download     Resources     Contact us    
Browse thread
stupid q(2): camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Anastasia Gornostaeva <ermine@e...>
Subject: stupid q(2): camlp4
Hello.

Readihg http://martin.jambon.free.fr/extend-ocaml-syntax.html, I
attempt to solve the exercise from chapter 13: 

"Suggested exercise: implement and test a syntax extension which supports a
 where construct. For instance,

 a + b where a = 1 and b = 2

 means

 let a = 1 and b = 2 in a + b

 We decide that

 let a = 1 in a where a = 2

 should be read as

 let a = 1 in (a where a = 2) (* returns 2 *)

 and not

 (let a = 1 in a) where a = 2 (* returns 1 *)

 Also, the where construct is right-associative:

 x + y where x = y where y = 1

 means

 x + y where x = (y where y = 1) (* depends on an external y *)

 and not

 (x + y where x = y) where y = 1 (* returns 2 *)"

I wrote (for old camlp4/camlp5):

EXTEND
expr: LEVEL "expr1"
  [ RIGHTA
    [ x = SELF; "where"; lb = V (LIST1 let_binding SEP "and") ->
      <:expr< let $_list:lb$ in $x$ >> ]
  ];
END

but it does not satisfy the second suggestion. How can I have true RIGHTA
associative?

Thanks!

ermine