Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Future of labels
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: William Chesters <williamc@p...>
Subject: Re: [Caml-list] How do I define prog1?
On Thu, 12 Apr 2001, Mattias Waldau wrote:
 > I would like to define a (prog1 a b) which first evaluates a, then b, and
 > returns the
 > value of a. (Would be nice if I could have arbitrary number of args.)

camlp4 is the natural tool here; I did it once:

  open Pcaml 
  open MLast

  EXTEND
    GLOBAL: expr ctyp patt class_str_item module_expr;

    expr:
      [[ res = expr (* LEVEL "expr1" *); "before"; post = LIST1 expr SEP ";" ->
           <:expr< let __it = $res$ in do $list:post$ return __it >> ]] ;

  END

I think this lets you write e.g.

  let a = ref 1 and b = ref 10 in
  !a + !b before incr a; incr b

    => 11

but I can't see any examples of it in my old code and I don't have
campl4 installed to test it, sorry ...
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr