From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Mike Gran Newsgroups: gmane.lisp.guile.user Subject: Re: Guile assert macro Date: Mon, 22 Apr 2019 12:36:25 -0700 Message-ID: <20190422193625.GA30071@spikycactus.attlocal.net> References: <5017489f-1e55-a3db-07c9-c1158c3160f8@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nFreZHaLTZJo0R7j" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="216466"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.11.3 (2019-02-01) Cc: guile-user@gnu.org To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Apr 22 21:37:05 2019 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIekR-000uAJ-NO for guile-user@m.gmane.org; Mon, 22 Apr 2019 21:37:03 +0200 Original-Received: from localhost ([127.0.0.1]:43326 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIekQ-00015J-Pg for guile-user@m.gmane.org; Mon, 22 Apr 2019 15:37:02 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56009) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hIek1-000146-Tx for guile-user@gnu.org; Mon, 22 Apr 2019 15:36:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hIek0-0008ES-UP for guile-user@gnu.org; Mon, 22 Apr 2019 15:36:37 -0400 Original-Received: from sonic303-22.consmr.mail.ne1.yahoo.com ([66.163.188.148]:45940) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hIek0-0008DU-Pc for guile-user@gnu.org; Mon, 22 Apr 2019 15:36:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1555961795; bh=hHi9Iwmin1ou1YhD5F7rCr3l9jHUCGl9kVsoL6+rtr0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=Q8QA3n6W5Dp4/8wNX2rPl5A7pPBNHLr76r/5sXQ0OKRxN6fLgjrApMzUVvIQ7NMg86jiSNcK0e7BI7W+Pmen7v77dRItfTKtI0XuLjmCTlkwHWtSpRPIZHHjVuKfCWXK54mybkgo7B8Bn99KxfMC6yanlCHHTVuZjAKRpxtwrm41rO+dp4EWINSEQIP1hCRIJm/NcBAYKH3huXiAlYawlWjbRG6XyvNFkIhOpBsGKcsJhqPeZPONxSTgkulzvGk6RshKob9GMPOyPxguEF3aIdXznmYbzxMP6uGM/cztI0kh/1Cboo+N+0EXhvwEUrwUoAFgVfHwszznJ7T+Yn+UHA== X-YMail-OSG: QlHthnIVM1nLbL8pFSQiPTCDAJCW_D9mveteWI0vL7ZxdnWLB8LzID9q4rbh1aQ 9m9tvGQZj6ZXllIL5vxWW2iYijdRt.WXpLnYkU.rgawgFtv8jWwGfd8.bmQ7kaHMAZpZBb.5vTyh JfqFyCaSHdcLEfOUqKP4OO6Bw9.ALndeXeuIHVBlYsl5ul4m13r_23KZK5dh6b8a7E2rcEfkG0QX BEb6VokU57Ac2P8Zz_wXgQQtaS3u5C0E5IvfMYzGRZCAwJ55L4pZrixuuG._dw8lYrAAJ2_KDP4C XBNgIK_5Ry8YtwBQYCiKnFjsHPJ1kKzYl208eksZHkPa2qEW_6SMYbezdiM1unN7RTXLrPvhdQ9B ssY24auv5Q8U3in9zcTFNbGI3z76MEJ1hjQMbm4JgJtJaiM8u.2HwGW6an_2EGPkzITNwxbHUN_F I.3pJ2mA4TtMJ564304wZ_7ZHnNcjp9h.H_AKwMCD2PQhv5GqorvKdnDXNgcWKDwprH5cN1TdJ48 fAYDXLRzW.GYFfyRwBAzBaXWw3gl38Kstl0s9pzhHQw0IbBHjwt4iIFsVl8RFzitQGvyjPdJCLdh KmK.w2wJZzzare6Bt9dTpM3o9dQzUBjKiSE6oF97.32Jqh13CpaI0ZngurU.nwY9e3Hxg5eqYKWU GN9QND8YmZfFQs6waWqQJhYMdWX1xlvck1LhR46IFo.Dd9DxaEsANls8yWBxRw625NCAj6xFKDfy uxqD4u21QOZAnrCUpf5ZzmG.aqE0nS1wb4oX1lTvijWhQWoRh8Ojfrj_3G.uSUevOPNUoLC0kdeS MAwaHg6LWZ17U6Bw4sOQjhVu6v7MAvsFF6Gv2tYz5Q Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic303.consmr.mail.ne1.yahoo.com with HTTP; Mon, 22 Apr 2019 19:36:35 +0000 Original-Received: from 75-54-112-187.lightspeed.irvnca.sbcglobal.net (EHLO spikycactus.attlocal.net) ([75.54.112.187]) by smtp427.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID d735ff3466457ff98a758e950cdcd380; Mon, 22 Apr 2019 19:36:31 +0000 (UTC) Content-Disposition: inline In-Reply-To: <5017489f-1e55-a3db-07c9-c1158c3160f8@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 66.163.188.148 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.lisp.guile.user:15412 Archived-At: --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Apr 22, 2019 at 08:57:32PM +0200, Zelphir Kaltstahl wrote: > Hello Guile users, > > I was looking for an assert facility in Guile and found the following: > > https://www.gnu.org/software/guile/manual/html_node/rnrs-base.html#rnrs-base > > (Search for assert there to find it on the page.) > > However, while searching, I also found something that looks even better: > > http://okmij.org/ftp/Scheme/assert-syntax-rule.txt This is my assert macro. I'm sure there are dozens of other versions. --- --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="assert.scm" (define-module (mlg assert) #:export (assert assert-type)) (define-syntax __FILE__ (syntax-rules () ((_) (or (assv-ref (current-source-location) 'filename) "(unknown file)")))) (define-syntax __LINE__ (syntax-rules () ((_) (or (assv-ref (current-source-location) 'line) "(unknown line)")))) (define-syntax assert (lambda (x) (syntax-case x () ((_ expression) #'(let ((ret expression)) (unless ret (error (format #f "~a:~a: assertion failed: ~a = ~s" (__FILE__) (__LINE__) 'expression expression)))))))) (define-syntax assert-type (lambda (x) (syntax-case x () [(_ type var) #`(if (not (#,(datum->syntax #'var (string->symbol (string-append (symbol->string (syntax->datum #`type)) "?"))) var)) (scm-error 'wrong-type-arg #f (string-append "not type '" #,(symbol->string (syntax->datum #`type)) "': ~s") (list var) (list var)))]))) --nFreZHaLTZJo0R7j--