Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] my first questions about camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oleg Trott <oleg_trott@c...>
Subject: Re: [Caml-list] my first questions about camlp4
On Thursday 22 May 2003 01:16 pm, Basile STARYNKEVITCH wrote:
> >>>>> "Ed" == Ed L Cashin <ecashin@uga.edu> writes:
>
>     Ed> "Dont Bother" <dont_bother@whoever.com> writes:
>     >> 1. It's been said that Camlp4 is not as easy to use as Lisp
>     >> macros, but is it as powerful? Is there anything that can be
>     >> done with Lisp macros that can not be done using Camlp4 in the
>     >> context of their respective languages?
>
>     Ed> You might get a better answer to that question on
>     Ed> comp.lang.lisp. [...]
>
>
> I do know a tiny bit CL, and I do practice Ocaml with Camlp4. It seems
> to me that CommonLisp macros can -for example- interact with CL object
> system, while Camlp4 is purely syntactic (in that sense, it is more
> like Scheme macros). For example, I tend to believe that you can make
> a commonlisp macro which, given a class name C, extract all the fields
> F of this class C such that F name ends with a suffix S and generate a
> printing routine which prints only those fields. I think that this is
> not possible in Camlp4 (unless you redefine in Camlp4 the syntax
> defining Ocaml classes).

I think Lisp is too huge for anyone to make statements as to what's NOT in it 
with certainty, but I suspect that to do what you are describing, one would 
need a non-standard function like CLASS-SLOTS. In any event, whether this is 
the case is incidental. More interestingly, if you were to have to augment 
DEFCLASS with this functionality, would it be easier than redefining OCaml 
class syntax in Camlp4? The former is fairly easy, because you know exactly 
where to find field names within DEFCLASS form :

      - take the fourth element of the form, which has to be a list;
      - for each of its elements, do:
             - if the element is a list, its head is one of the field names
             - otherwise, it's a field name itself

I imagine this would probably be harder to do with OCaml & Camlp4 (Unless, 
perhaps, you happen to be the author of "camlp4/meta/pa_o.ml" )

> In a more general way, I do think that Ocaml still lacks some
> reflective abilities (which could help for other things,
> e.g. persistency).

It does seem like integrating Camlp4 into the compiler could offer interesting 
possibilities. 

> Also, macros are an essential part of CommonLisp; for example, they
> are repeatedly used for CommonLisp advocacy,

:-)


-- 
Oleg Trott <oleg_trott@columbia.edu>

-------------------
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