caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* stupid q(2): camlp4
@ 2008-11-12 13:13 Anastasia Gornostaeva
  2008-11-12 22:49 ` [Caml-list] " Richard Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Anastasia Gornostaeva @ 2008-11-12 13:13 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-11-14 19:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-12 13:13 stupid q(2): camlp4 Anastasia Gornostaeva
2008-11-12 22:49 ` [Caml-list] " Richard Jones
2008-11-13 17:25   ` Anastasia Gornostaeva
2008-11-14 19:37   ` Anastasia Gornostaeva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).