unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Maxime Devos <maximedevos@telenet.be>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: Contracts macro example
Date: Wed, 20 Jul 2022 08:39:30 +0000	[thread overview]
Message-ID: <b580b558-9e07-d7b1-94bf-37f343bf0374@posteo.de> (raw)
In-Reply-To: <e8153fe2a13d0cfb719abbdeba5a462832fd936c.camel@telenet.be>

Hello Maxime!

On 7/19/22 17:20, Maxime Devos wrote:
> Zelphir Kaltstahl schreef op do 14-07-2022 om 23:55 [+0000]:
>>            (make-assertion-failure)
>>            (make-exception-with-message "assertion failed")
>>            (make-exception-with-irritants (quote (op args* ...)))))]
> Instead of a generic 'assertion failure', I believe a more specific
> &contract-failure to be better.
Ah yes, I'll do that!
> Also, define*-with-contract / lambda*-with-contract would be nice.
I am not sure how to pattern match optional arguments (maybe not any special 
way) an keyword arguments (probably a special notation or way to do it, I 
guess). But I do seem to remember, that there were some procedures for building 
keyword argument procedures and that I should have an example somewhere. Perhaps 
I need to pattern match on literally #:optional and #:key and combinations of these.
> It would also be nice to define a global 'require' and 'ensure' and
> '<?>' somewhere (e.g.: (define-syntax require (identifier-syntax
> (syntax-error "'require' can only be used as part of a contract
> construct")))), that way, require / ensure / <?> can be renamed during
> importing, so all contract things could be prefixed with, say,
> contract:.

I thought about implementing <?> for the insertion location of the result in a 
predicate, but initially wanted to keep it simple and get a simple version to 
work. I think I have seen this for pipelining in an SRFI before … *checks* … 
Maybe in https://srfi.schemers.org/srfi-197/srfi-197.html, or 
https://srfi.schemers.org/srfi-26/srfi-26.html, or maybe in some other repository.

Now that the basic version works, I can try to introduce the placeholder.

The idea is to define these globally in the module, so that they can be exported 
separately, so that they can be renamed upon import, correct?

How could a macro check, whether it is used inside something else? If the 
pattern matching only looks at the form of the macro itself, how can I get the 
"context", in which it was used and check, whether that is inside a 
`define-with-contract`? I think I have not yet unlocked that knowledge yet : )

>       ;; `#t`, the neutral element of `and`.
>
> Guile supports Unicode and UTF-8, so you can write ‘#t’ here instead of
> `#t`.  Additionally, maybe #t -> #true?
Do you think I should not use #t here, but another value? My idea was, that 
using #t would not influence the result of an "and operation" at all. But 
perhaps using another value can be useful for checking against it in some 
situation?
> Greetings,
> Maxime.

Thank you for the input!
Zelphir

-- 
repositories: https://notabug.org/ZelphirKaltstahl




  reply	other threads:[~2022-07-20  8:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14 23:55 Contracts macro example Zelphir Kaltstahl
2022-07-19 15:20 ` Maxime Devos
2022-07-20  8:39   ` Zelphir Kaltstahl [this message]
2022-07-20  8:55     ` Maxime Devos
2022-07-24  1:21       ` Zelphir Kaltstahl
2022-08-04 16:19         ` Maxime Devos

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=b580b558-9e07-d7b1-94bf-37f343bf0374@posteo.de \
    --to=zelphirkaltstahl@posteo.de \
    --cc=guile-user@gnu.org \
    --cc=maximedevos@telenet.be \
    /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).