* Guile assert macro @ 2019-04-22 18:57 Zelphir Kaltstahl 2019-04-22 19:36 ` Mike Gran 2019-04-23 0:54 ` Mark H Weaver 0 siblings, 2 replies; 5+ messages in thread From: Zelphir Kaltstahl @ 2019-04-22 18:57 UTC (permalink / raw) To: guile-user Hello Guile users, I was looking for an assert facility in Guile and found the following: https://www.gnu.org/software/guile/manual/html_node/rnrs-base.html#rnrs-base (Search for assert there to find it on the page.) However, while searching, I also found something that looks even better: http://okmij.org/ftp/Scheme/assert-syntax-rule.txt Is that anywhere implemented in Guile already? (In case it is not implemented: What are the reasons for not providing that one? It looks a little bit more useful than the one I found.) Regards, Zelphir ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Guile assert macro 2019-04-22 18:57 Guile assert macro Zelphir Kaltstahl @ 2019-04-22 19:36 ` Mike Gran 2019-04-22 21:52 ` Zelphir Kaltstahl 2019-04-23 0:54 ` Mark H Weaver 1 sibling, 1 reply; 5+ messages in thread From: Mike Gran @ 2019-04-22 19:36 UTC (permalink / raw) To: Zelphir Kaltstahl; +Cc: guile-user [-- Attachment #1: Type: text/plain, Size: 512 bytes --] On Mon, Apr 22, 2019 at 08:57:32PM +0200, Zelphir Kaltstahl wrote: > Hello Guile users, > > I was looking for an assert facility in Guile and found the following: > > https://www.gnu.org/software/guile/manual/html_node/rnrs-base.html#rnrs-base > > (Search for assert there to find it on the page.) > > However, while searching, I also found something that looks even better: > > http://okmij.org/ftp/Scheme/assert-syntax-rule.txt This is my assert macro. I'm sure there are dozens of other versions. --- [-- Attachment #2: assert.scm --] [-- Type: text/plain, Size: 1044 bytes --] (define-module (mlg assert) #:export (assert assert-type)) (define-syntax __FILE__ (syntax-rules () ((_) (or (assv-ref (current-source-location) 'filename) "(unknown file)")))) (define-syntax __LINE__ (syntax-rules () ((_) (or (assv-ref (current-source-location) 'line) "(unknown line)")))) (define-syntax assert (lambda (x) (syntax-case x () ((_ expression) #'(let ((ret expression)) (unless ret (error (format #f "~a:~a: assertion failed: ~a = ~s" (__FILE__) (__LINE__) 'expression expression)))))))) (define-syntax assert-type (lambda (x) (syntax-case x () [(_ type var) #`(if (not (#,(datum->syntax #'var (string->symbol (string-append (symbol->string (syntax->datum #`type)) "?"))) var)) (scm-error 'wrong-type-arg #f (string-append "not type '" #,(symbol->string (syntax->datum #`type)) "': ~s") (list var) (list var)))]))) ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Guile assert macro 2019-04-22 19:36 ` Mike Gran @ 2019-04-22 21:52 ` Zelphir Kaltstahl 0 siblings, 0 replies; 5+ messages in thread From: Zelphir Kaltstahl @ 2019-04-22 21:52 UTC (permalink / raw) To: Mike Gran; +Cc: guile-user Hi Mike, Thank you for sharing your assert version. I am more focused on finding out, whether the assert macro from Oleg Kiselyov's page is already in Guile somewhere (and thus in the standard and usable without installing libs or putting more code unrelated to other stuff inside an example project) and if not, why not. However, I guess your point is, that there are many implementations of some kind of assertion facility? If I see it correctly in the code you wrote, the type test assertion simply puts a question mark at the end of the type argument to the ~assert-type~ macro. I have a few questions about this: Q1: What happens, if there is no such predicate with a question mark at the end? Q2: Why not write the type assertion in terms of basic assert macro you wrote, instead of using another ~syntax-case~? Q3: Does such a type assertion make sense as a separate facility, compared to simply using ~(assert (number? x))~ for example? (Note, that I am not very experienced in macro writing myself. It is still something I need to get an intuition for. In the case of assert, it seems to me, that it is a natural case, where a macro would make sense. Finding Oleg Kiselyov's page going on about the assert macro seems to confirm this with at least an "authority argument".) Regards, Zelphir On 4/22/19 9:36 PM, Mike Gran wrote: > On Mon, Apr 22, 2019 at 08:57:32PM +0200, Zelphir Kaltstahl wrote: >> Hello Guile users, >> >> I was looking for an assert facility in Guile and found the following: >> >> https://www.gnu.org/software/guile/manual/html_node/rnrs-base.html#rnrs-base >> >> (Search for assert there to find it on the page.) >> >> However, while searching, I also found something that looks even better: >> >> http://okmij.org/ftp/Scheme/assert-syntax-rule.txt > This is my assert macro. I'm sure there are dozens of other versions. > > --- ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Guile assert macro 2019-04-22 18:57 Guile assert macro Zelphir Kaltstahl 2019-04-22 19:36 ` Mike Gran @ 2019-04-23 0:54 ` Mark H Weaver 2019-04-23 20:47 ` Zelphir Kaltstahl 1 sibling, 1 reply; 5+ messages in thread From: Mark H Weaver @ 2019-04-23 0:54 UTC (permalink / raw) To: Zelphir Kaltstahl; +Cc: guile-user Hi Zelphir, Zelphir Kaltstahl <zelphirkaltstahl@gmail.com> writes: > I was looking for an assert facility in Guile and found the following: > > https://www.gnu.org/software/guile/manual/html_node/rnrs-base.html#rnrs-base > > (Search for assert there to find it on the page.) > > However, while searching, I also found something that looks even better: > > http://okmij.org/ftp/Scheme/assert-syntax-rule.txt > > Is that anywhere implemented in Guile already? No. > (In case it is not implemented: What are the reasons for not providing > that one? It looks a little bit more useful than the one I found.) Well, no one has suggested it until now, and moreover I didn't even know it existed :) Do you know if it's seen much use? Do any other Scheme implementations include it? Correct me if I'm wrong, but I get the impression that this is something that Oleg hacked up in an hour and posted ~15 years ago, but that it's never seen much use. Also, I'm personally not fond of the API, which is quite unconventional. The thing about assertion macros is that (1) they are usually trivial, and (2) I'm not aware of any consensus in the Scheme community on what a non-trivial assertion API should look like. I suspect this is why there's no SRFI for assertion macros, despite the fact that anyone can write a SRFI. For those who find the R6RS 'assert' macro unsatisfactory, I'm inclined to suggest that each project should feel free to define their own assertion macro according to their needs and preferences. Having said that, if you think you know a non-trivial assert API that other Schemers would like to use, feel free to publish a library or write a SRFI. If it becomes popular, we could consider including it with Guile. Regards, Mark ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Guile assert macro 2019-04-23 0:54 ` Mark H Weaver @ 2019-04-23 20:47 ` Zelphir Kaltstahl 0 siblings, 0 replies; 5+ messages in thread From: Zelphir Kaltstahl @ 2019-04-23 20:47 UTC (permalink / raw) To: Mark H Weaver; +Cc: guile-user Hi Mark! Thanks for answering that question about the macro being implemented. I was maybe wrongly assuming, that, since it is on Oleg's website, many of the very proficient schemers know it. It seems to be a nice macro, but I have no idea how much time Oleg spent on it. I got the feeling though, that he sometimes revises articles on his website. I think this article about assertion macro also has been revised. It not being in Guile, I will have to make a choice of using that macro and adding it as a sort of dependency or simply using the standard library one's assert macro. It will probably not be a big issue to use a macro that is not in the standard library, as long as I note that somewhere and make it clear, that it might work differently, if one does not use that macro. I don't really find the R6RS assert macro unsatisfactory. It is only that I saw something else that looked nice ; ) Thanks! I also recently had a thought: "How can he just put the code like that on a website and not in some repository instead?" – I think the answer is, that the code is concise, short and works in most Schemes, since they mostly have a lot in common, so that he does not need to put much info there about "What if I use <some Scheme dialect here>?". Thanks to standardization of Scheme. Zelphir On 4/23/19 2:54 AM, Mark H Weaver wrote: > Hi Zelphir, > > Zelphir Kaltstahl <zelphirkaltstahl@gmail.com> writes: > >> I was looking for an assert facility in Guile and found the following: >> >> https://www.gnu.org/software/guile/manual/html_node/rnrs-base.html#rnrs-base >> >> (Search for assert there to find it on the page.) >> >> However, while searching, I also found something that looks even better: >> >> http://okmij.org/ftp/Scheme/assert-syntax-rule.txt >> >> Is that anywhere implemented in Guile already? > No. > >> (In case it is not implemented: What are the reasons for not providing >> that one? It looks a little bit more useful than the one I found.) > Well, no one has suggested it until now, and moreover I didn't even know > it existed :) Do you know if it's seen much use? Do any other Scheme > implementations include it? > > Correct me if I'm wrong, but I get the impression that this is something > that Oleg hacked up in an hour and posted ~15 years ago, but that it's > never seen much use. Also, I'm personally not fond of the API, which is > quite unconventional. > > The thing about assertion macros is that (1) they are usually trivial, > and (2) I'm not aware of any consensus in the Scheme community on what a > non-trivial assertion API should look like. I suspect this is why > there's no SRFI for assertion macros, despite the fact that anyone can > write a SRFI. > > For those who find the R6RS 'assert' macro unsatisfactory, I'm inclined > to suggest that each project should feel free to define their own > assertion macro according to their needs and preferences. > > Having said that, if you think you know a non-trivial assert API that > other Schemers would like to use, feel free to publish a library or > write a SRFI. If it becomes popular, we could consider including it > with Guile. > > Regards, > Mark ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-04-23 20:47 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-04-22 18:57 Guile assert macro Zelphir Kaltstahl 2019-04-22 19:36 ` Mike Gran 2019-04-22 21:52 ` Zelphir Kaltstahl 2019-04-23 0:54 ` Mark H Weaver 2019-04-23 20:47 ` Zelphir Kaltstahl
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).