From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.lisp.guile.user Subject: Re: built-in procedural logical operator Date: Tue, 01 Sep 2015 18:21:40 +0200 Organization: Organization?!? Message-ID: <877foa3yaz.fsf@fencepost.gnu.org> References: <20150901234435.7d1c4384@debian> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1441124548 25775 80.91.229.3 (1 Sep 2015 16:22:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Sep 2015 16:22:28 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Sep 01 18:22:12 2015 Return-path: Envelope-to: guile-user@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 1ZWoK0-0007rr-F5 for guile-user@m.gmane.org; Tue, 01 Sep 2015 18:22:08 +0200 Original-Received: from localhost ([::1]:55721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWoK0-00056A-9t for guile-user@m.gmane.org; Tue, 01 Sep 2015 12:22:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWoJo-00055N-66 for guile-user@gnu.org; Tue, 01 Sep 2015 12:21:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZWoJl-0008OW-Gk for guile-user@gnu.org; Tue, 01 Sep 2015 12:21:56 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:45651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWoJl-0008O5-9o for guile-user@gnu.org; Tue, 01 Sep 2015 12:21:53 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZWoJi-0007eW-SU for guile-user@gnu.org; Tue, 01 Sep 2015 18:21:50 +0200 Original-Received: from x2f4b122.dyn.telefonica.de ([2.244.177.34]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 01 Sep 2015 18:21:50 +0200 Original-Received: from dak by x2f4b122.dyn.telefonica.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 01 Sep 2015 18:21:50 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 55 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: x2f4b122.dyn.telefonica.de X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) Cancel-Lock: sha1:7uAdntzNpRBKfJxV+fdLpmmYQTE= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:11976 Archived-At: Alex Vong writes: > Hi everyone, > > I am learning scheme, please bear with me if I am wrong. > > I try to define a new function LIST-OF-STRING? > > (define (list-of-string? lst) > (reduce and #f (map string? lst))) > > and I get the error > > While compiling expression: > ERROR: Syntax error: > unknown location: source expression failed to match any pattern in form and > > It seems it is because AND is implemented as a macro, > so I try to implement my own RECURSIVE-AND > > (define (recursive-and . arg-lst) > (cond ((null? arg-lst) #t) > ((not (car arg-lst)) #f) > (else (apply recursive-and (cdr arg-lst))))) > > and now > > (define (list-of-string? lst) > (reduce recursive-and #f (map string? lst))) > > works as intended. > > Is it a leaking implementation detail that AND is implemented as a > macro? No. It cannot be a function since it stops evaluation after the first false argument > Do we have a built-in procedural logical operators so that we don't > that error? >From (srfi srfi-1): (and ...) -> (every identity ... (or ...) -> (any identity ... (define (list-of-string? lst) (every string? lst)) Of course, this definition returns #t for '() while your definition returns #f for '(). I'd argue the former is more correct. But of course you can just write (define (list-of-string lst) (and (pair? lst) (every string? lst))) if you want the latter. -- David Kastrup