From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.lisp.guile.bugs Subject: bug#17147: [PATCH] Add versions of and/or avoiding O(n^2) argument matching Date: Wed, 4 Jun 2014 16:18:29 +0200 Message-ID: <1401891509-29257-1-git-send-email-dak@gnu.org> References: <87k3ban107.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1401891558 15421 80.91.229.3 (4 Jun 2014 14:19:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 4 Jun 2014 14:19:18 +0000 (UTC) Cc: David Kastrup To: 17147@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Jun 04 16:19:12 2014 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WsC24-0005Fy-1A for guile-bugs@m.gmane.org; Wed, 04 Jun 2014 16:19:12 +0200 Original-Received: from localhost ([::1]:33697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsC23-0002U0-E6 for guile-bugs@m.gmane.org; Wed, 04 Jun 2014 10:19:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsC1z-0002T4-03 for bug-guile@gnu.org; Wed, 04 Jun 2014 10:19:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WsC1u-00071H-Hg for bug-guile@gnu.org; Wed, 04 Jun 2014 10:19:06 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsC1u-00071A-E3 for bug-guile@gnu.org; Wed, 04 Jun 2014 10:19:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WsC1u-00051x-14 for bug-guile@gnu.org; Wed, 04 Jun 2014 10:19:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <87k3ban107.fsf@fencepost.gnu.org> Resent-From: David Kastrup Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 04 Jun 2014 14:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17147 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 17147-submit@debbugs.gnu.org id=B17147.140189153819325 (code B ref 17147); Wed, 04 Jun 2014 14:19:01 +0000 Original-Received: (at 17147) by debbugs.gnu.org; 4 Jun 2014 14:18:58 +0000 Original-Received: from localhost ([127.0.0.1]:43901 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WsC1m-00051X-1E for submit@debbugs.gnu.org; Wed, 04 Jun 2014 10:18:58 -0400 Original-Received: from fencepost.gnu.org ([208.118.235.10]:46030 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WsC1f-00051D-U0 for 17147@debbugs.gnu.org; Wed, 04 Jun 2014 10:18:52 -0400 Original-Received: from localhost ([127.0.0.1]:53337 helo=lola) by fencepost.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsC1f-0003AD-1e; Wed, 04 Jun 2014 10:18:47 -0400 Original-Received: by lola (Postfix, from userid 1000) id A22F8DF3CC; Wed, 4 Jun 2014 16:18:46 +0200 (CEST) X-Mailer: git-send-email 1.9.1 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7494 Archived-At: Fixes * module/ice-9/boot-9.scm (and, or): Add syntax rules that only do one pattern matching operation per and/or rather than per argument. Signed-off-by: David Kastrup --- module/ice-9/boot-9.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 7f38c4b..d2f34d9 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -426,6 +426,8 @@ file with the given name already exists, the effect is unspecified." ;; The binding for `macroexpand' has now been overridden, making psyntax the ;; expander now. +;; quasisyntax requires simple definitions of and/or for bootstrapping. + (define-syntax and (syntax-rules () ((_) #t) @@ -440,6 +442,30 @@ file with the given name already exists, the effect is unspecified." (include-from-path "ice-9/quasisyntax") +;; Don't use syntactically recursive definitions of and/or for speed +;; reasons as they need to match the whole argument list for each +;; iteration. + +(define-syntax and + (lambda (expr) + (syntax-case expr () + ((_) #'#t) + ((_ x y ...) + (let loop ((x #'x) (y #'(y ...))) + (if (null? y) + x + #`(if #,x #,(loop (car y) (cdr y)) #f))))))) + +(define-syntax or + (lambda (expr) + (syntax-case expr () + ((_) #'#f) + ((_ x y ...) + (let loop ((x #'x) (y #'(y ...))) + (if (null? y) + x + #`(let ((t #,x)) (if t t #,(loop (car y) (cdr y)))))))))) + (define-syntax-rule (when test stmt stmt* ...) (if test (begin stmt stmt* ...))) -- 1.9.1