From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id D1459BC57 for ; Tue, 19 Oct 2010 21:54:42 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al4BAHKUvUxRZ90xkWdsb2JhbAChUxUBAQEBCQsKBxEDH8RmhUoEiks X-IronPort-AV: E=Sophos;i="4.57,351,1283724000"; d="scan'208";a="74067463" Received: from mtaout03-winn.ispmail.ntl.com ([81.103.221.49]) by mail4-smtp-sop.national.inria.fr with ESMTP; 19 Oct 2010 21:54:42 +0200 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20101019195441.TIHF3075.mtaout03-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com>; Tue, 19 Oct 2010 20:54:41 +0100 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout01-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20101019195441.KCIJ20122.aamtaout01-winn.ispmail.ntl.com@romulus.metastack.com>; Tue, 19 Oct 2010 20:54:41 +0100 Received: from remus.metastack.local ([172.16.0.1]) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id o9JJsZ45013162 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Tue, 19 Oct 2010 20:54:35 +0100 Received: from Remus.metastack.local ([fe80::547c:3c42:e1da:eda2]) by Remus.metastack.local ([fe80::547c:3c42:e1da:eda2%11]) with mapi; Tue, 19 Oct 2010 20:52:36 +0100 From: David Allsopp To: "'Oliver Bandel'" , "'caml-list@yquem.inria.fr'" Subject: RE: [Caml-list] Code-execution (evaluation) time Thread-Topic: [Caml-list] Code-execution (evaluation) time Thread-Index: AQHLb7yzVtqh8Rao8kq0DUlnFzkYKpNIrJAQ Date: Tue, 19 Oct 2010 19:52:36 +0000 Message-ID: References: <20101019203918.202612lacw5rse6u@webmail.in-berlin.de> In-Reply-To: <20101019203918.202612lacw5rse6u@webmail.in-berlin.de> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.1 cv=3ENABmdyEd/Fm7fR7+mZIuMDn6+IErAeEhlfWBImZFk= c=1 sm=0 a=ZLVCJmA3-5oA:10 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=ZOzjf2MOAAAA:8 a=p6rsRZ9daCpIvWi-vQ8A:9 a=mIu9ziciOhaOxP0eXnnQTQxCgVsA:4 a=CjuIK1q_8ugA:10 a=g1CcJgp8HkMA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 X-Spam: no; 0.00; bandel:01 ocaml:01 expr:01 cmo:01 cmx:01 ocamlc:01 ocamlopt:01 foo:01 unspecified:01 argv:01 iter:01 wrote:01 oliver:01 caml-list:01 expression:02 Oliver Bandel wrote: > Hello, >=20 > I want to refresh my OCaml knowledge after I (again) paused for a while. >=20 > I want to know, when certain parts of the code are executed, > for example if I have more than one let _ =3D ... > statement in my code (for example in different comp0ilaion units each one > of them). Expressions (as in, things listed in http://caml.inria.fr/pub/docs/manual-o= caml/expr.html) are evaluated in the order in which they appear in a source= file. If you have two files A.ml and B.ml which contain top-level statemen= ts, the order in which they execute will depend on the order in which you l= ink the resulting .cmo or .cmx files (which should be left-to-right as pass= ed to ocamlc/ocamlopt - don't know where that's specified). As far as I can see, in pretty much all contexts within an expression where= order of evaluation could matter including, but probably not limited to: * Record initialisation (e.g. let i =3D ref 0 in {a =3D (incr i; !i); b =3D= (incr i; !i)}) * Function application (similarly) * let foo =3D _ and bar =3D _ in _ are intentionally left as unspecified (in practice, application and record = initialisation are right-to-left and let x =3D _ and y =3D _ is left-to-rig= ht but the point is that you are never supposed to rely on that). > I also found an old code snippet with the following parts: >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D > let fnames =3D List.tl(Array.to_list Sys.argv) >=20 > (* some more code *) >=20 > let _ =3D > List.iter print_days_old fnames > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D >=20 > So, the value fnames contains the args from the command line and can be > used in the first statement of the code. [let fnames =3D ..] is a complete expression so it's evaluated before the [= let _] further down. David