🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fa.caml
Article #77

Re: camlp4 in toplevel

#77
From: jdn
Date: Sun, 23 Sep 2012 01:11
147 lines
5006 bytes
On Saturday, September 22, 2012 8:09:39 PM UTC-4, Max Mouratov wrote:
> On Friday, September 21, 2012 12:10:26 AM UTC+6, jdn wrote:
> 
> > I'm interested in using camlp4 for a DSL.  To get up to speed I was hoping to use camlp4 in the toplevel to expand quotations to help with the learning curve.  I can't seem to get this to work so I must be missing something, apologies if this is a very simple question.  Here is a snippit of what I'm doing and the error:
> 
> >
> 
> >
> 
> >
> 
> > utop $ #camlp4o;;
> 
> >
> 
> > utop $ open Camlp4.PreCast;;
> 
> >
> 
> > utop $ let q = <:str_item< let f x = x >>;;
> 
> >
> 
> > Error: While finding quotation "str_item" in a position of "expr": There is no quotation expander available.                                                               Camlp4: Uncaught exception: Not_found
> 
> >
> 
> >
> 
> >
> 
> > I've tried many different things and done a google search but I can't figure out the problem.  Any hints are greatly appreciated.
> 
> 
> 
> 
> 
> Greetings.
> 
> 
> 
> To be able to refer to the OCaml's str_item quotation you need to load the
> 
> corresponding findlib package (camlp4.quotations.o). An example of how to do it
> 
> in the vanilla toplevel:
> 
> 
> 
>     # #use "topfind";;
> 
>     - : unit = ()
> 
>     Findlib has been successfully loaded. Additional directives:
> 
>       #require "package";;      to load a package
> 
>       #list;;                   to list the available packages
> 
>       #camlp4o;;                to load camlp4 (standard syntax)
> 
>       #camlp4r;;                to load camlp4 (revised syntax)
> 
>       #predicates "p,q,...";;   to set these predicates
> 
>       Topfind.reset();;         to force that packages will be reloaded
> 
>       #thread;;                 to enable threads
> 
> 
> 
>     - : unit = ()
> 
>     # #camlp4o;;
> 
>     /usr/lib/ocaml/dynlink.cma: loaded
> 
>     /usr/lib/ocaml/camlp4: added to search path
> 
>     /usr/lib/ocaml/camlp4/camlp4o.cma: loaded
> 
>     	Camlp4 Parsing version 3.12.1
> 
> 
> 
>     # #require "camlp4.quotations.o";;
> 
>     /usr/lib/ocaml/camlp4/Camlp4Parsers/Camlp4QuotationCommon.cmo: loaded
> 
>     /usr/lib/ocaml/camlp4/Camlp4Parsers/Camlp4OCamlOriginalQuotationExpander.cmo: loaded
> 
> 
> 
>     # open Camlp4.PreCast;;
> 
>     # let _loc = Loc.ghost;;
> 
>     val _loc : Camlp4.PreCast.Loc.t = <abstr>
> 
> 
> 
>     # <:str_item< 42 >>;;
> 
>     - : Camlp4.PreCast.Ast.str_item =
> 
>     Camlp4.PreCast.Ast.StSem (<abstr>,
> 
>      Camlp4.PreCast.Ast.StExp (<abstr>, Camlp4.PreCast.Ast.ExInt (<abstr>, "42")),
> 
>      Camlp4.PreCast.Ast.StNil <abstr>)
> 
> 
> 
> 
> 
> Notice how we first bind a dummy location to _loc, because the expanded
> 
> quotation expects _loc to be available in the current lexical context.
> 
> 
> 
> Have fun hacking your DSL with Camlp4, and be prepared to face a lot of bizarre
> 
> black magic, since the official Camlp4 documentation leaves much to be desired.
> 
> 
> 
> Just read the source, Luke, and get enlightenment (or maybe brain damage) :-)

Many thanks Max.  I've been using camlp4of to do the expansions as I couldn't figure out what I wasn't loading.  Thank you very much for your assistance as this will make my life much easier.  I will not hold you responsible for any brain damage that I may incur due to your help ;-).
Technical Details
Message-ID: <0fa80bb1-082a-47d7-8d05-fcdc4cd4ed23@googlegroups.com>
Path: arc1-ca.pugleaf.net!e10ni13434282qan.0!nntp.google.com!l8no6282170qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
References: <d4509b2c-c577-4566-965e-e624c28e32a0@googlegroups.com> <29a24b20-6711-4326-bd9a-23bb15f83783@googlegroups.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: c0fe4b917e,8acb4113c0ae4e0f
X-Google-Attributes: gidc0fe4b917e,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.224.213.1 with SMTP id gu1mr7016072qab.7.1348362670165;
        Sat, 22 Sep 2012 18:11:10 -0700 (PDT)
Received: by 10.52.28.83 with SMTP id z19mr1496152vdg.20.1348362670126; Sat,
 22 Sep 2012 18:11:10 -0700 (PDT)
Path: arc1-ca.pugleaf.net!e10ni13434282qan.0!nntp.google.com!l8no6282170qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: fa.caml
Date: Sat, 22 Sep 2012 18:11:10 -0700 (PDT)
In-Reply-To: <29a24b20-6711-4326-bd9a-23bb15f83783@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.26.2.173; posting-account=pCqrygoAAAAcjeMuMdoGvJo842XBQl0u
NNTP-Posting-Host: 70.26.2.173
References: <d4509b2c-c577-4566-965e-e624c28e32a0@googlegroups.com> <29a24b20-6711-4326-bd9a-23bb15f83783@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0fa80bb1-082a-47d7-8d05-fcdc4cd4ed23@googlegroups.com>
Subject: Re: camlp4 in toplevel
From: jdn <drjdnielsen@gmail.com>
Injection-Date: Sun, 23 Sep 2012 01:11:10 +0000
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable