* 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
* Re: [Caml-list] stupid q(2): camlp4 2008-11-12 13:13 stupid q(2): camlp4 Anastasia Gornostaeva @ 2008-11-12 22:49 ` Richard Jones 2008-11-13 17:25 ` Anastasia Gornostaeva 2008-11-14 19:37 ` Anastasia Gornostaeva 0 siblings, 2 replies; 4+ messages in thread From: Richard Jones @ 2008-11-12 22:49 UTC (permalink / raw) To: Anastasia Gornostaeva; +Cc: caml-list On Wed, Nov 12, 2008 at 04:13:00PM +0300, Anastasia Gornostaeva wrote: > 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 You could cheat and have a look at pa_where ... http://bluestorm.info/camlp4/pa_where/list.php http://bluestorm.info/camlp4/pa_where/pa_where.ml.html (Is bluestorm running a gopher server?) Rich. -- Richard Jones Red Hat ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] stupid q(2): camlp4 2008-11-12 22:49 ` [Caml-list] " Richard Jones @ 2008-11-13 17:25 ` Anastasia Gornostaeva 2008-11-14 19:37 ` Anastasia Gornostaeva 1 sibling, 0 replies; 4+ messages in thread From: Anastasia Gornostaeva @ 2008-11-13 17:25 UTC (permalink / raw) To: caml-list On Wed, Nov 12, 2008 at 10:49:34PM +0000, Richard Jones wrote: [...] > > You could cheat and have a look at pa_where ... > > http://bluestorm.info/camlp4/pa_where/list.php > http://bluestorm.info/camlp4/pa_where/pa_where.ml.html It does not explain why RIGHTA in my code does not work as expected... and the implementation for let_binding in that pa_where is too complex for too simple task. ermine ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] stupid q(2): camlp4 2008-11-12 22:49 ` [Caml-list] " Richard Jones 2008-11-13 17:25 ` Anastasia Gornostaeva @ 2008-11-14 19:37 ` Anastasia Gornostaeva 1 sibling, 0 replies; 4+ messages in thread From: Anastasia Gornostaeva @ 2008-11-14 19:37 UTC (permalink / raw) To: caml-list On Wed, Nov 12, 2008 at 10:49:34PM +0000, Richard Jones wrote: [...] > You could cheat and have a look at pa_where ... > > http://bluestorm.info/camlp4/pa_where/list.php > http://bluestorm.info/camlp4/pa_where/pa_where.ml.html Ouch, I got it after reading http://brion.inria.fr/gallium/index.php/Syntax_extension_tutorial - it depends not only associative but even on level of adding the rule! Big thanks for excellent tutorials. :) 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