From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion via General Guile related discussions Newsgroups: gmane.lisp.guile.user Subject: Contract programming in Guile Date: Sat, 17 Jul 2021 12:01:34 -0400 Message-ID: <87tukthqu9.fsf@clara> Reply-To: Olivier Dion Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35028"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Jul 17 18:02:16 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 1m4mlc-0008zV-9t for guile-user@m.gmane-mx.org; Sat, 17 Jul 2021 18:02:16 +0200 Original-Received: from localhost ([::1]:46342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m4mla-0006Ni-Py for guile-user@m.gmane-mx.org; Sat, 17 Jul 2021 12:02:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4mlC-0006H2-4d for guile-user@gnu.org; Sat, 17 Jul 2021 12:01:50 -0400 Original-Received: from smtp.polymtl.ca ([132.207.4.11]:52611) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4ml9-00037S-TO for guile-user@gnu.org; Sat, 17 Jul 2021 12:01:49 -0400 Original-Received: from localhost ([89.36.78.252]) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 16HG1Y5V029456 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 17 Jul 2021 12:01:38 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 16HG1Y5V029456 X-Poly-FromMTA: ([89.36.78.252]) at Sat, 17 Jul 2021 16:01:34 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, 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:17649 Archived-At: Hi all, I'm a big fan of contract programming and was wondering if there's any SRFI or library that offers this in Guile? Here's an example of what I mean by contract: -------------------------------------------------------------------------------- ;; Given (define (sum x y z) "Return the sum of X, Y and Z." (#:pre-conditions (>= x 0) (>= y 0) (>= z 0)) (#:post-conditions (>= result 0)) (+ x y z)) ;; Would expand to something like (use-modules (ice-9 local-eval)) (define (sum x y z) " Return the sum of X, Y, and Z. pre-conditions: (>= x 0) (>= y 0) (>= z 0) post-conditions: (>= result 0) " (for-each (lambda (condition) (unless (local-eval condition (the-environment)) (begin (format #t "Failed pre-condition: ~a\n" condition) (exit 1)))) '((>= x 0) (>= y 0) (>= z 0))) (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)))) '((>= result 0))) result)) -------------------------------------------------------------------------------- -- Olivier Dion PolyMtl