unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Linus Björnstam" <linus.internet@fastmail.se>
To: "Olivier Dion" <olivier.dion@polymtl.ca>, guile-user@gnu.org
Subject: Re: Contract programming in Guile
Date: Sat, 17 Jul 2021 18:29:07 +0200	[thread overview]
Message-ID: <bc6aee72-5a00-4b3f-8dbd-435104412568@www.fastmail.com> (raw)
In-Reply-To: <87tukthqu9.fsf@clara>

I wrote this a billion million years ago: https://hg.sr.ht/~bjoli/misc/browse/contract.scm?rev=tip

Very basic. Contracts are just syntax and not first-class objects. 

-- 
  Linus Björnstam

On Sat, 17 Jul 2021, at 18:01, Olivier Dion via General Guile related discussions wrote:
> 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
> 
> 



  reply	other threads:[~2021-07-17 16:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-17 16:01 Contract programming in Guile Olivier Dion via General Guile related discussions
2021-07-17 16:29 ` Linus Björnstam [this message]
     [not found] <mailman.57.1626624015.30702.guile-user@gnu.org>
2021-07-18 16:50 ` Kjetil Matheussen
2021-07-19  6:34   ` Linus Björnstam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bc6aee72-5a00-4b3f-8dbd-435104412568@www.fastmail.com \
    --to=linus.internet@fastmail.se \
    --cc=guile-user@gnu.org \
    --cc=olivier.dion@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).