From: Dmitry Lomov <dmitry.lomov@jetbrains.com>
To: Michael Alexander Hamburg <hamburg@fas.harvard.edu>
Cc: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] camlp4 and class values
Date: Mon, 23 Aug 2004 12:10:12 +0400 [thread overview]
Message-ID: <4129A664.8070302@jetbrains.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0408230033090.15745@ls02.fas.harvard.edu>
Michael,
please see my inline answer.
Michael Alexander Hamburg wrote:
> [skip]
> #load "pa_extend.cmo";;
> #load "q_MLast.cmo";;
>
> open Pcaml
> open MLast
>
> let addName n = "add_" ^ n
> let onName n = "on_" ^ n
>
> let o2b = function
> Some _ -> true
> | None -> false
>
> let genfunc loc params e =
> <:expr< Stack.apply (fun self $params$ -> $e$) >>
>
> let genval loc l params e =
> <:class_str_item< value $lid:onName l$ = $genfunc loc params e$ >>
>
> let genmeth loc pf l topt params =
> <:class_str_item< method $opt:o2b pf$ $l$ $opt:topt$ $patt:params$ =
> Stack.apply $lid:onName l$ self $params$>>
>
> let genadd loc pf l =
> <:class_str_item< method $opt:o2b pf$ $addName l$ f = Stack.append
> $lid:onName l$ f >>
>
>
> EXTEND
> class_str_item : LAST
> [[ "extmethod"; pf = OPT "private"; l = LIDENT; topt = OPT ctyp; params
> = LIST0 patt; "="; e = expr ->
> let meth = genmeth loc pf l topt params
> and add = genadd loc pf l
> and v = genval loc l params e in
> <:class_str_item< declare $v$; $meth$; $add$; end >>
Quotations has a very strict syntax. In particular, quotation
<:class_str_item< declare ... >>, which is a way to add multiple
declarations to a class body, expects a list of class_str_item's.
If you just write some code in revised syntax, it will construct the
list automatically, but it cannot construct the list from
antiquotations. So you have to do it yourself:
let csil = [v; meth; add] in
<:class_str_item< declare $csil:csil$ end >>
Hope this helps,
Friendly,
Dmitry
> ]];
> END;;
>
> which raises:
>
> File "extmethod.ml", line 22, characters 52-65:
> While expanding quotation "class_str_item":
> Parse error: [fun_binding] expected (in [class structure item])
> Uncaught exception: Pcaml.Qerror("class_str_item", 1, _)
> Preprocessor error
>
> The closest thing I've been able to find to documentation on fun_bindings
> is the camlp4 source, which does a much more direct translation.
>
> How do I write such an extenision? OR is there some reason that it's not
> possible?
>
> Thanks for your time,
>
> Mike Hamburg
>
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>
--
Dmitry Lomov
JetBrains Inc.
http://www.jetbrains.com
"Develop With Pleasure!"
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
prev parent reply other threads:[~2004-08-23 8:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-23 5:13 Michael Alexander Hamburg
2004-08-23 8:10 ` Dmitry Lomov [this message]
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=4129A664.8070302@jetbrains.com \
--to=dmitry.lomov@jetbrains.com \
--cc=caml-list@pauillac.inria.fr \
--cc=hamburg@fas.harvard.edu \
/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