[wg-camlp4] A new branch to experiment with extension points
Alain Frisch
alain.frisch at lexifi.com
Fri Mar 1 13:05:30 GMT 2013
On 03/01/2013 09:08 AM, Mark Shinwell wrote:
> 1. If possible, I'd rather see one new syntactic form, rather than
> three.
I've made the syntax more uniform, dropped prefix attributes, and added
attributes on type declarations.
The current syntax is:
Attributes:
On expressions: expr (:foo expr)
On type expressions: type (:foo expr)
On structure items: str_item ..(:foo expr)
On type declarations: type t = ... with (:foo1 expr1) (:foo2 expr2)
Extension nodes:
On expressions: (&foo expr)
On type expressions: (&foo expr)
On structure items: ..(&foo expr)
A type-conv like example (attributes on type expressions and type
declarations):
=================================================
type t = {
x : int (:default 42);
y : int (:default 3) (:sexp_drop_default);
z : int (:default 3) (:sexp_drop_if z_test);
} with (:sexp)
=================================================
A Bisect-like example (attributes on expressions and structure items):
=================================================
let f x =
match List.map foo [x; a x; b x] with
| [y1; y2; y3] -> tata
| _ -> (assert false) (:bisect visit)
let unused = ()
..(:bisect ignore)
=================================================
A Bolt-like example (extension nodes on expressions):
=================================================
let funct n =
(&log) "funct(%d)" n LEVEL DEBUG;
for i = 1 to n do
print_endline "..."
done
=================================================
or:
=================================================
let funct n =
(&log "funct(%d)" n LEVEL DEBUG);
for i = 1 to n do
print_endline "..."
done
=================================================
A map/fold generator (extension nodes on structure item):
=================================================
type variable = string
and term =
| Var of variable
| Lam of variable * term
| App of term * term
..(&generate_map map term)
=================================================
or, if we also add extension nodes on class expressions:
=================================================
type variable = string
and term =
| Var of variable
| Lam of variable * term
| App of term * term
class map = (&generate_map term)
=================================================
-- Alain
More information about the wg-camlp4
mailing list