Browse thread
Handling include files using ocamllex
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2007-08-05 (12:17) |
From: | Erik de Castro Lopo <mle+ocaml@m...> |
Subject: | Re: [Caml-list] Handling include files using ocamllex |
Jacques GARRIGUE wrote: > Interesting, because the example you describe here is precisely the > reason it is not allowed (at least as Jerome Vouillon explained to > me.) > That is, you intend the instance variable lexbuf to be the one > associated to the current (mutable) chan, but if you change chan this > will no longer be true. > So, in order to avoid this kind of ambiguity, you have to use let > defined variables. For instance: > > class lexstack top_filename = > let init_chan = open_in top_filename in > object > val mutable filename = top_filename > val mutable chan = init_chan > val mutable lexbuf_chan = init_chan > val mutable lexbuf = Lexing.from_channel init_chan > method lexbuf = > if chan == lexbuf_chan then lexbuf else > (lexbuf <- Lexing.from_channel chan; lexbuf_chan <- chan) > ... > > Note that this restriction applies also to immutable instance > variables, because you can modify them through functional update > (the {< chan = ... >} notation.) Thanks for the excellent explanation Jacques. I must admit, this is one of my first real forays into OO side of ocaml, but I quickly found that my aims could be acheived just as easily using the technique I posted. Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "A programming language is low level when its programs require attention to the irrelevant." -- Alan Perlis