From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA03606; Sun, 26 Jan 2003 20:00:08 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA03596 for ; Sun, 26 Jan 2003 20:00:07 +0100 (MET) Received: from hirsch.in-berlin.de (hirsch.in-berlin.de [192.109.42.6]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h0QJ06r00253 for ; Sun, 26 Jan 2003 20:00:06 +0100 (MET) Received: from hirsch.in-berlin.de (localhost [127.0.0.1]) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with ESMTP id h0QJ054X011863 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT) for ; Sun, 26 Jan 2003 20:00:05 +0100 Received: from first.UUCP (uucp@localhost) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with UUCP id h0QJ05Yc011861 for inria.fr!caml-list; Sun, 26 Jan 2003 20:00:05 +0100 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: inria.fr!caml-list Received: by first.in-berlin.de via sendmail from stdin id (Debian Smail3.2.0.114) Sun, 26 Jan 2003 20:01:16 +0100 (CET) From: oliver@first.in-berlin.de (Oliver Bandel) Date: Sun, 26 Jan 2003 20:01:16 +0100 To: caml-list@inria.fr Subject: [Caml-list] Discarding elements from a list Message-ID: <20030126190116.GA360@first.in-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.28i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, after Remi has pushed my towards rewriting my "I do it like I know it, and therefore imperative" version of a program into a functional version of this program (thanks, Remi, I have explored a lot new things since then :)) I sometimes come to this problem: I have to use a partial list. In the reference manual I did not found any stdlib-function, and so I have two ideas, of how to perform e.g. a list, which is used without the head (throwing away first element): a) Converting the list to an array, shorten the array, converting back to a list, using the list in a functional manner. b) Using pattern match to throw away the first element, then working in the part after the "->" with a function, which works on the rest of the list. c) using a function, which uses an index, for counting, at which position we are inside of the list This problem arises, when a list, on which should be worked, will be created and it must be used a part of it (e.g. all elements but the last or all elements but the first), like creating a multiplication of the last and the current element... (like fibonacci uses addition, I need multiplication here) and when the first or last is necessary for some calculation, but should be thrown away for some other calculation. Because I have no criteria to decide, which solution I should prefer (and why), I always rethink the problem again, and the decision-process slows down. So, why should I use which solution? (And how to select parts of a list in general, not only throwing away the first or last element?) Any hints? Ciao, oliver ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners