Browse thread
Efficiency of let/and
[
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: | -- (:) |
| From: | Marius Nita <marius@c...> |
| Subject: | Re: Ant: [Caml-list] Efficiency of let/and |
Martin Chabr wrote: > As it appears to me, there is no semantic difference > between both alternatives. I've always thought that there was. In the `and' form, the bindings cannot depend on each other. The program you pasted shouldn't run in any (recent) OCaml toplevel. Are you using a really old one or something? -marius It can be shown with two > dependent expressions y = 1 and z = y + 2: > > # let y = 1 in > let z = y + 2 in > z;; > - : int = 3 > > # let y = 1 > and z = y + 2 in > z;; > - : int = 3 > > The order is important in both cases: > > # let z = y + 2 in > let y = x + 1 in > z;; > Characters 8-9: > let z = y + 2 in > ^ > Unbound value y > > # let z = y + 2 > and y = 1 in > z;; > Characters 8-9: > let z = y + 2 > ^ > Unbound value y > > So the "and"-form depends on the order as well and I > think the syntactic difference can be just used for > documentation. A good idea, by the way. > > I hope this helps > > Martin > > > > --- Brian Hurt <bhurt@spnz.org> schrieb: > >> Say I have two variables I want to set- variable a >> to the value expr1 and >> variable b to the value expr2. The two expressions >> are pure (no side >> effects), and neither one depends upon the other >> (neither expr1 nor expr2 >> contain either a or b as a value), so they can be >> evaluated in either >> order or in parallel with no harm. With expressions >> like these, I've >> gotten into the habit of using let/and to express >> the parallelism, that is >> I go: >> >> let a = expr1 >> and b = expr2 >> in >> ... >> >> rather than: >> let a = expr1 in >> let b = expr2 in >> >> So my question is: is there any value (other than >> the documentation value) >> in doing this? >> >> Just wondering. >> >> Brian >> >> _______________________________________________ >> Caml-list mailing list. Subscription management: >> > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >> Archives: http://caml.inria.fr >> Beginner's list: >> http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs >> > > > > > > ___________________________________________________________ > Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs