From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Re: Contracts macro example Date: Wed, 20 Jul 2022 08:39:30 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7888"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Maxime Devos Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Jul 20 10:39:52 2022 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 1oE5FI-0001pN-0d for guile-user@m.gmane-mx.org; Wed, 20 Jul 2022 10:39:52 +0200 Original-Received: from localhost ([::1]:52778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oE5FG-0006Ui-K0 for guile-user@m.gmane-mx.org; Wed, 20 Jul 2022 04:39:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oE5F2-0006UZ-Vt for guile-user@gnu.org; Wed, 20 Jul 2022 04:39:37 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:38489) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oE5F0-0005tn-Ha for guile-user@gnu.org; Wed, 20 Jul 2022 04:39:36 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 67AF924002D for ; Wed, 20 Jul 2022 10:39:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1658306371; bh=A32B9p1LoNb3siJvr8hBLRIpi40FZy4CeHLIBISAXsA=; h=Date:Subject:To:From:Cc:From; b=CnibOTs/39ODKBQTWfewYwSjhxUPYcUyRPFcBy14WtDBwdFamNsaMyQZkoKr8wEQq J7u0zjSO9S4UJzhukpJkGiP2oGxEFcGYz0Jus04ZrOwzJ+BI8ksAY/0wpIfujmi/Na iRTAVbK2xY8mHayFxFaDhnnawEQSn2QUqMEU2JXOT6/PW5YukqSK/1mdr+pmKIUAwO DiGFjMfTsRXvPokf6pZT7gJs9DpmRa/6pyZGHBzO7iAoL5ZtWtlauqU2tRmK6TrDIr J/nnD70Cb9r4PXTGlzyExsUcaGdeRhJb1PGCMCVr6uch985AH55NJ4vsmYIEpO0pTU imi8a+3OMWPWQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Lnpz64Sfmz6tmW; Wed, 20 Jul 2022 10:39:30 +0200 (CEST) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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:18436 Archived-At: 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