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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 29881BC57 for ; Tue, 31 Aug 2010 00:55:04 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am8EAC7Te0xQW+UMgWdsb2JhbACgahUBARYiIr8vhTcEigk X-IronPort-AV: E=Sophos;i="4.56,294,1280700000"; d="scan'208";a="58003460" Received: from lo.gmane.org ([80.91.229.12]) by mail2-smtp-roc.national.inria.fr with ESMTP; 31 Aug 2010 00:55:03 +0200 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OqDFm-0005FW-Tz for caml-list@inria.fr; Tue, 31 Aug 2010 00:55:02 +0200 Received: from epiano.texitoi.eu ([88.164.18.122]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 31 Aug 2010 00:55:02 +0200 Received: from texitoi+news by epiano.texitoi.eu with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 31 Aug 2010 00:55:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: TeXitoi Subject: Re: While loop Date: 31 Aug 2010 00:53:17 +0200 Sender: texitoi@epiano.appart Message-ID: <87vd6rd86a.fsf@epiano.appart> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: epiano.texitoi.eu User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 X-Spam: no; 0.00; val:01 guillaume:01 prince:98 ribbon:98 campaign:98 int:01 int:01 writes:01 append:02 caml:02 seems:03 let:03 let:03 nth:05 nth:05 Mike Chen writes: > Hi, > > I am a caml rookie, and I need your help. > > (* pp is a very simple function *) > # let pp list = > let newList = ref [] in > let i = ref 0 in > let ele = ref (List.nth list !i) in !ele is an int, so it will only be calculated before entering the loop, and will not be updated. maybe you can try let ele () = List.nth list !i in and s/!ele/(ele ())/g > while (!ele) != 5 do > newList := List.append !newList [(!ele mod 3)]; > i := !i + 1; > done; > !newList;; > val pp : int list -> int list = > > # pp [ 3; 4; 5];; > > (* it seems it goes into a forever loop, but I expect it returns [ 0; > 1]. What is wrong? *) I've only ligthly read the code, it can be something else. -- Guillaume Pinot http://www.texitoi.eu « Les grandes personnes ne comprennent jamais rien toutes seules, et c'est fatigant, pour les enfants, de toujours leur donner des explications... » -- Antoine de Saint-Exupéry, Le Petit Prince () ASCII ribbon campaign -- Against HTML e-mail /\ http://www.asciiribbon.org -- Against proprietary attachments