From: Anastasia Gornostaeva <ermine@ermine.pp.ru>
To: caml-list@inria.fr
Subject: stupid q(2): camlp4
Date: Wed, 12 Nov 2008 16:13:00 +0300 [thread overview]
Message-ID: <20081112131300.GA67784@ermine.home> (raw)
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
next reply other threads:[~2008-11-12 13:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-12 13:13 Anastasia Gornostaeva [this message]
2008-11-12 22:49 ` [Caml-list] " Richard Jones
2008-11-13 17:25 ` Anastasia Gornostaeva
2008-11-14 19:37 ` Anastasia Gornostaeva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081112131300.GA67784@ermine.home \
--to=ermine@ermine.pp.ru \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox