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 TAA30321; Thu, 8 Apr 2004 19:58:56 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA31005 for ; Thu, 8 Apr 2004 19:58:55 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mwinf0104.wanadoo.fr (smtp1.wanadoo.fr [193.252.22.30]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i38Hxmjq030841 for ; Thu, 8 Apr 2004 19:59:48 +0200 Received: from lexifi.com (ATuileries-105-1-1-57.w193-252.abo.wanadoo.fr [193.252.198.57]) by mwinf0104.wanadoo.fr (SMTP Server) with ESMTP id D9CFE1BFFF56; Thu, 8 Apr 2004 19:58:53 +0200 (CEST) Message-ID: <407592E8.6080500@lexifi.com> Date: Thu, 08 Apr 2004 19:59:04 +0200 From: Jean-Marc EBER User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: John Goerzen Cc: Ocaml Mailing List Subject: Re: [Caml-list] Dynamically evaluating OCaml code References: <20020104004356.GA1672@mev> <20040408133727.GC29195@excelhustler.com> <20040408145606.GA18473@fichte.ai.univie.ac.at> <20040408151427.GA740@redhat.com> <20040408152654.GB18473@fichte.ai.univie.ac.at> <20040408155833.GG30763@excelhustler.com> In-Reply-To: <20040408155833.GG30763@excelhustler.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 dynamically:01 varies:01 failwith:01 failwith:01 cygwin:01 arrays:01 inefficient:01 ocaml:01 ocaml:01 caml:01 trivial:01 eber:02 eber:02 match:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Keywords: X-UID: 170 John Goerzen wrote: > > Now, I know that I must ignore the first two and last three elements in > that list. I do not know in advance what size the list will be, and it > varies from line to line, but it always has at least five elements. I > also do not necessarily know the values for "2" and "3" at compile time, > though they are constant throughout execution of the program. The order > of the elements is significant and must not be altered. Each element is > the same type (ie, a String). There is nothing in the data itself that > differentiates it. > > Now, which OCaml data structure gives me the ability to easily pull out > such a slice? As far as I can tell, there are no standard functions for > any of Array or List to do that. I could write a function for either of > them to loop over it and get me what I want, but the point is that this > functionality is useful. > In the time you wrote the previous paragraph, its also possible to write following (of course horribly inefficient, because it inverts two times the argument list) prototype implementation of the function you need, so that you can continue to work on your problem. When you hit efficiency problems, you will probably later on replace it with a better one... let remove_2_3 = function | _ :: _ :: rest -> (match List.rev rest with | _ :: _ :: _ :: rest -> List.rev rest | _ -> failwith "error2") | _ -> failwith "error1";; remove_2_3 [1; 2; 3; 4; 5; 6; 7];; cd c:/cygwin/home/jmeber/mlfi/ ocaml eber.ml [3; 4] Compilation finished at Thu Apr 08 19:45:26 I don't need to mention that your previous particular problem is so trivial that it could easily be expressed with arrays as a "one liner" of caml code... Look at Array.sub... Jean-Marc ------------------- 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