From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: DanL Newsgroups: gmane.emacs.help Subject: Re: Partition for Emacs Lisp Date: Wed, 1 Jul 2009 15:32:00 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5031f6f3-147f-4a74-8157-2c83854518f4@g19g2000yql.googlegroups.com> References: <631809cb-3385-4429-9d65-ef504de6d68f@l12g2000yqo.googlegroups.com> <6e5e0d4c-0a47-4805-bc69-111fc0d1f20f@c36g2000yqn.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1246508078 21226 80.91.229.12 (2 Jul 2009 04:14:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 2 Jul 2009 04:14:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 02 06:14:31 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MMDgs-0007Ip-Kw for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jul 2009 06:14:30 +0200 Original-Received: from localhost ([127.0.0.1]:47368 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MMDgr-0007IT-Mq for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jul 2009 00:14:29 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!g19g2000yql.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.lang.lisp,comp.lang.scheme Original-Lines: 45 Original-NNTP-Posting-Host: 217.226.237.40 Original-X-Trace: posting.google.com 1246487521 17123 127.0.0.1 (1 Jul 2009 22:32:01 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 1 Jul 2009 22:32:01 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g19g2000yql.googlegroups.com; posting-host=217.226.237.40; posting-account=gsXeqwoAAACPD-5-xc5RrpRTkPxUZbii User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 GTB5 (.NET CLR 3.5.30729), gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:170502 comp.lang.lisp:270333 comp.lang.scheme:81596 X-Mailman-Approved-At: Thu, 02 Jul 2009 00:12:14 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:65716 Archived-At: > After learning a bit of Haskell I was surprised that CL doesn't have > functions like dropWhile, takeWhile etc. So naturally, I implemented > them asap (curiously, the existence of cons proved no hindrance) - and > then didn't really use them much. Using series (not CL, but in CLTL2), until-if provides takeWhile's functionality: DHL> (until-if #'plusp #z(-1 -2 3 4 -5 6)) #Z(-1 -2) I couldn't find a counterpart for dropWhile, but it could be implemented (naively) like this: (defun take-while (predicate series) (declare (optimizable-series-function)) (subseries series 0 (collect-length (until-if (complement predicate) series)))) Or maybe: (defun take-while (predicate series) (declare (optimizable-series-function) (off-line-port series)) (producing (out) ((in series) element) (loop (tagbody (setq element (next-in in (terminate-producing))) (unless (funcall predicate element) (terminate-producing)) (next-out out element))))) DHL> (take-while #'minusp #z(-1 -2 3 4 -5 6)) #Z(-1 -2) Regards, dhl Disclaimer: I am by no means a series expert, so any tips, especially concerning efficiency, are appreciated.