This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

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: 2008-11-12 (13:13) From: Anastasia Gornostaeva Subject: stupid q(2): camlp4
```Hello.

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

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

```