From: Matt Gushee <matt@gushee.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] revised syntax and immediate objects
Date: Tue, 04 Jul 2006 16:53:24 -0600 [thread overview]
Message-ID: <44AAF164.20406@gushee.net> (raw)
In-Reply-To: <ad8cfe7e0607041443k7e337b14h31d77a18999d865a@mail.gmail.com>
Jonathan Roewen wrote:
> What is the syntax for immediate objects in ocaml when using revised
syntax?
Not sure offhand, but ...
> I'd like to try make a camlp4 syntax extension that uses immediate
> objects,
I've done that. I'll show you the key section of the code below, and I
can send you the complete file if you like. It may not be 100% correct,
but I've been using it in an application and so far it works. I don't
know if I can *explain* it, though ... I wrote it several months ago,
and I'm coming to think that CamlP4, like Perl, is a write-only language ;-)
[BTW, *_si in function names means "structure item", and *_csi means
"class structure item"]
let object_body loc decls =
let sub_objects =
let sos =
List.fold_right
( fun idat lst ->
match idat.sub_obj with
| None -> lst
| Some so -> so::lst )
decls [] in
<:class_str_item< declare $list:sos$ end >>
and accessors =
let accs =
List.fold_right
( fun idat lst ->
match idat.setter with
| None -> idat.getter :: lst
| Some se -> idat.getter :: se :: lst )
decls [] in
<:class_str_item< declare $list:accs$ end >> in
(sub_objects, accessors)
let subconf_csi loc key decls =
let sub_objects, accessors = object_body loc decls
and pself = <:patt< self >>
and inheritance =
<:class_str_item<
inherit sub_config data defaults path as super
>> in
let obj_expr =
MLast.ExObj
(loc, Some pself, [inheritance; sub_objects; accessors]) in
let keylist_expr = <:expr< [$str:key$] >> in
let path_bind_expr =
<:expr<
let path = path @ $keylist_expr$ in $obj_expr$
>>
and oname = key ^ "_" in
Some <:class_str_item< value $lid:oname$ = $path_bind_expr$ >>
let rootconf_si loc cname decls =
let sub_objects, accessors = object_body loc decls
and pself = <:patt< self >>
and inheritance =
<:class_str_item<
inherit root_config srcs dest data defaults as super
>> in
let oe =
MLast.ExObj
(loc, Some pself, [inheritance; sub_objects; accessors]) in
<:str_item<
value $lid:cname$ srcs dest =
let data = Dict.create ()
and path = [] in $oe$
>>
let main_si loc cname decls =
write_example decls;
let os = <:str_item< open Rascl >>
and oc = <:str_item< open ConfigObject >>
and od = <:str_item< open Dict >>
and defcreate = <:str_item< value defaults = create () >>
and defsetup0 = top_doin_expr loc [] decls in
let defsetup = <:str_item< $exp:defsetup0$ >>
and cl = rootconf_si loc cname decls in
let all = [os; oc; od; defcreate; defsetup; cl] in
<:str_item< declare $list:all$ end >>
--
Matt Gushee
: Bantam - lightweight file manager : matt.gushee.net/software/bantam/ :
: RASCL's A Simple Configuration Language : matt.gushee.net/rascl/ :
next prev parent reply other threads:[~2006-07-04 22:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-04 21:43 Jonathan Roewen
2006-07-04 22:28 ` Martin Jambon
2006-07-04 22:53 ` Matt Gushee [this message]
2006-07-04 23:07 ` Jonathan Roewen
2006-07-04 23:20 ` Matt Gushee
2006-07-05 8:19 ` Nicolas Pouillard
2006-07-05 7:29 ` Nicolas Pouillard
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=44AAF164.20406@gushee.net \
--to=matt@gushee.net \
--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