From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Newsgroups: gmane.lisp.guile.user Subject: Re: Contract programming in Guile Date: Sat, 17 Jul 2021 18:29:07 +0200 Message-ID: References: <87tukthqu9.fsf@clara> Mime-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1159"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.5.0-alpha0-533-gf73e617b8a-fm-20210712.002-gf73e617b To: "Olivier Dion" , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Jul 17 18:30:04 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4nCT-000Ac9-TY for guile-user@m.gmane-mx.org; Sat, 17 Jul 2021 18:30:03 +0200 Original-Received: from localhost ([::1]:56062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m4nCR-00065Y-6y for guile-user@m.gmane-mx.org; Sat, 17 Jul 2021 12:29:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4nC2-000652-Gi for guile-user@gnu.org; Sat, 17 Jul 2021 12:29:34 -0400 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:38065) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4nC0-0004kl-HX for guile-user@gnu.org; Sat, 17 Jul 2021 12:29:34 -0400 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id A251C5C014B; Sat, 17 Jul 2021 12:29:29 -0400 (EDT) Original-Received: from imap44 ([10.202.2.94]) by compute5.internal (MEProxy); Sat, 17 Jul 2021 12:29:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.se; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type:content-transfer-encoding; s=fm3; bh=sggzz UaKOEjVHyeOtNTHaBcUUzn76pCBOWwJLeH1gtg=; b=jhQZyVTHZ/ytc7ecVlQg1 2U1M3kZp+82OsWLu0QYx+tBUnsaUBmQaptxWXlbaywcNMWDchUAsugh6jL2VzqQU P5GhszctIUB1NqMCHYAt7FWNtLL0WKtrF6Tl56JE217swPuoL8GbsbtjNwrtVgiF w1aP+jSfOV7AQ0soqPb9MazJ5B1GsMIOmFRgF6glSnMPnClohWrYHMentiyIShUE uxZUaok7vsDfNj668VFcrjjGDtqUwnwgxOWqtKpMm8b/Jlezz8xnmRW+0L8LBDa9 o91iNJtHeSHi5xiPC+waPYKa2yf1udOKoakrQsxYJnGe1rNq9DNUgQG6ZInmrhch g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=sggzzUaKOEjVHyeOtNTHaBcUUzn76pCBOWwJLeH1g tg=; b=p9cmTXf6qn/t93u6XmMYXeTW0fz/0BAhBbyyVlrv2URyNs+HpdrXfXcUE 70eBRtH8ZOHLLxqaTqvV8TO+AlXXB/0bs32U0R/iZjpUTmmaIFsZwZxFgG2IxY3n BNJwtwBMxG5THn0vSnaWBXkV3E5SqD28enobXAnzdZexY9C+5FNyHxQQSkvM/fKI M3x5iorSyRObfG1jcT5+LIlWP/ViZmvp4O9lNDJXjs7ns4eMb0k9VJq9WzxRerD5 li/8r33yyxFe0X2a5ucYv6TSH7J3n3FXxFMHLv8xQuTtPv8NX6AuplvI0cItBWam WbQaqsLlXYFJH9cePRoW6TqhGiaOQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvdehgdehudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepnfhinhhu shgpuehjnphrnhhsthgrmhcuoehlihhnuhhsrdhinhhtvghrnhgvthesfhgrshhtmhgrih hlrdhsvgeqnecuggftrfgrthhtvghrnhepieekkeeguddvheejtdeuleeutdekfefgveeh tdefjeekieehhfffteefudeiiefgnecuffhomhgrihhnpehsrhdrhhhtnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhhinhhushdrihhnthgv rhhnvghtsehfrghsthhmrghilhdrshgv X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 5E014FA0AA5; Sat, 17 Jul 2021 12:29:29 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: <87tukthqu9.fsf@clara> Received-SPF: pass client-ip=66.111.4.25; envelope-from=linus.internet@fastmail.se; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17650 Archived-At: I wrote this a billion million years ago: https://hg.sr.ht/~bjoli/misc/b= rowse/contract.scm?rev=3Dtip Very basic. Contracts are just syntax and not first-class objects.=20 --=20 Linus Bj=C3=B6rnstam On Sat, 17 Jul 2021, at 18:01, Olivier Dion via General Guile related di= scussions wrote: > Hi all, >=20 > I'm a big fan of contract programming and was wondering if there's any= > SRFI or library that offers this in Guile? >=20 > Here's an example of what I mean by contract: > ----------------------------------------------------------------------= ---------- > ;; Given > (define (sum x y z) >=20 > "Return the sum of X, Y and Z." >=20 > (#:pre-conditions > (>=3D x 0) > (>=3D y 0) > (>=3D z 0)) >=20 > (#:post-conditions > (>=3D result 0)) >=20 > (+ x y z)) >=20 > ;; Would expand to something like > (use-modules (ice-9 local-eval)) >=20 > (define (sum x y z) >=20 > " > Return the sum of X, Y, and Z. > =20 > pre-conditions: > (>=3D x 0) > (>=3D y 0) > (>=3D z 0) > =20 > post-conditions: > (>=3D result 0) > " >=20 > (for-each (lambda (condition) > (unless (local-eval condition (the-environment)) > (begin > (format #t "Failed pre-condition: ~a\n" condition) > (exit 1)))) > '((>=3D x 0) > (>=3D y 0) > (>=3D z 0))) >=20 > (let ((result (begin (+ x y z)))) > (for-each (lambda (condition) > (unless (local-eval condition (the-environment)) > (begin > (format #t "Failed post-condition: ~a\n" condition= ) > (exit 1)))) > '((>=3D result 0))) > result)) > ----------------------------------------------------------------------= ---------- >=20 > --=20 > Olivier Dion > PolyMtl >=20 >=20