caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Marius Nita <marius@cs.pdx.edu>
To: Martin Chabr <martin_chabr@yahoo.de>
Cc: caml-list@inria.fr
Subject: Re: Ant:  [Caml-list] Efficiency of let/and
Date: Mon, 26 Sep 2005 10:05:56 -0700	[thread overview]
Message-ID: <43382A74.309@cs.pdx.edu> (raw)
In-Reply-To: <20050926043240.24009.qmail@web26809.mail.ukl.yahoo.com>

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


  parent reply	other threads:[~2005-09-26 17:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-25 13:31 Brian Hurt
2005-09-25 14:47 ` [Caml-list] " Jon Harrop
2005-09-26  4:32 ` Ant: " Martin Chabr
2005-09-26  5:24   ` Fernando Alegre
2005-09-26  5:56   ` William Lovas
2005-09-26  7:17     ` Bill Wood
2005-09-26 20:59     ` Ant: " Martin Chabr
2005-09-26 13:22   ` Brian Hurt
2005-09-26 16:05     ` Ant: " Stefan Monnier
2005-09-26 16:30       ` [Caml-list] " Brian Hurt
2005-09-27  5:52         ` skaller
2005-09-27 13:06           ` Brian Hurt
2005-09-27 13:24             ` Alan Falloon
2005-09-27 15:24             ` Stefan Monnier
2005-09-27 16:11               ` Brian Hurt
2005-09-27  5:32       ` skaller
2005-09-27 15:21         ` Stefan Monnier
2005-09-26 17:04     ` Ant: [Caml-list] " Mackenzie Straight
2005-09-26 17:05   ` Marius Nita [this message]
2005-09-26 17:36     ` David McClain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43382A74.309@cs.pdx.edu \
    --to=marius@cs.pdx.edu \
    --cc=caml-list@inria.fr \
    --cc=martin_chabr@yahoo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).