Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] camlp4: LIST1 construct on record patterns
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jeff Henrikson <jehenrik@y...>
Subject: RE: [Caml-list] camlp4: LIST1 construct on record patterns
I actually tried magicing it into what I wanted it to be before, but was unable to guess it's real type.  Apparently I still can't:


open Printf;;

let try_extend _ =
  let cons = "Bogus" in
  let lbl_expr_list =
    (Obj.magic (Grammar.Entry.find expr "lbl_expr_list") :
       (MLast.patt * MLast.expr) (* not list *) Grammar.Entry.e) in
  EXTEND
    expr: LEVEL "simple"
    [ [ $cons$; "{"; memb = LIST1 lbl_expr_list SEP ";" ; "}" ->
          <:expr<{$list:memb$}>> ] ]
    ;
  END;;

try_extend 7;;

Bogus{foo="happy";bar="sad"};;


This segfaults.  Let's see if memb is even a list:


let try_extend _ =
  let cons = "Bogus" in
  let lbl_expr_list =
    (Obj.magic (Grammar.Entry.find expr "lbl_expr_list") :
       (MLast.patt * MLast.expr) (* not list *) Grammar.Entry.e) in
  EXTEND
    expr: LEVEL "simple"
    [ [ $cons$; "{"; memb = LIST1 lbl_expr_list SEP ";" ; "}" ->
          (printf "Do we get here %d\n" (List.length memb); flush stdout;
          <:expr<6>>) ] ]
    ;
  END;;

try_extend 7;;

Bogus{foo="happy";bar="sad"};;


This prints "Do we get here 1", regardless of how many terms I add in Bogus{}, regardless of whether such constructors are defined
or not.

But despite all this the source code looks convincing enough:

pa_o.ml:
      | "{"; test_label_eq; lel = lbl_expr_list; "}" ->
          <:expr< { $list:lel$ } >>

> Sorry, Luke, you entered the dark side of Camlp4... :-)

Apparently the force is not strong enough within me.  ;-}


Jeff

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr