Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] camlp4 'loc' variable
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-02-23 (08:24)
From: Aleksey Nogin <nogin@c...>
Subject: Re: [Caml-list] camlp4 'loc' variable
On 22.02.2004 10:06, J. Garrett Morris wrote:

> Hello,
> I'm currently writing a set of camlp4 quotations, and I'm running into the "Unbound value 'loc'" error that's been discussed on this list before.  I'm curious about exactly when the loc variable needs to be present, though.  I've got a fair number of helper routines like:
> let processList (l:MLast.expr list):MLast.expr =
>       List.fold_right (fun x l -> <:expr<[$x$ :: $l$]>>) l <:expr<[]>> 
> which are used both in antiquotations and in let statements surrounding expr quotations ... when do I need to take 'loc' as a parameter?

Basically, whenever you have an <:expr< ... >> quotation used an 
expression, it will use the "loc" variable for the "location" part of 
the expression. For example, in your case

<:expr<[$x$ :: $l$]>>
   expands to
MLast.ExApp (loc, MLast.ExApp (loc, MLast.ExUid (loc, "::"), x), l)


   expands to
MLast.ExUid (loc, "[]")

You can find out how camlp4 expands things by running, for example, 
"camlp4 q_MLast.cmo pa_o.cmo pr_o.cmo" - the output will 
contain the "plain" ML code.

Hope this helps.

Aleksey Nogin

Home Page:
E-Mail: (office), (personal)
Office: Jorgensen 70, tel: (626) 395-2907

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: