IRC channel logs

2023-08-18.log

back to list of logs

<rlb>...fwiw, I've started poking at the relevant tests, with an eye toward adding additional non-ascii coverage. i.e. I suspect we may only have ascii in any number of places. That might be useful, whatever we decide about the prosposed utf-8 changes. (And I have an uneasy feeling that it may well expose problems in the new code that I wasn't aware of.)
<tromey>I'm looking at some code that I think last ran on guile 1.8, and I was wondering if anyone knows what 'defmacro:syntax-transformer' is supposed to have done and how it can be rewritten
<Arsen>does commit 275e00329555ce572fe9a68f7692dbecc52d8b34 help?
<Arsen>ACTION has only a cursory understanding of this, so cannot elaborate on what is going on there
<tromey>not really since I think procedure->syntax also doesn't exist
<tromey>and lol, gone for nearly 15 years now
<tromey>cgen is abandonware basically
<tromey>maybe I can replace this with an ordinary defmacro
<tromey>well, maybe that helped, but now I get an error about "source expression failed to match any pattern" -- but without any identifying location, so who knows which use of the macro is bad :-(
<RavenJoad>Can you handle a &non-continuable exception by aborting its computation and just moving on? I have a procedure call that does an "rm -r", but if the directory does not exist, then I get an exception from lstat. If this exception is raised, I want to do nothing.
<dthompson>RavenJoad: use with-exception-handler and the #:unwind? #t argument
<dthompson>that way you don't need to setup prompts or anything to abort from a non-continuable error
<RhodiumToad>unless you want the error handler to report on where the error is before unwinding
<dthompson>hopefully the exception captures the relevant context in that case, but it might not sometimes guile's exception data leaves much to be desired
<RavenJoad>This exception does not need to contain or report useful data. It is just checking for a path's existence at boot, and if the path is there, removes its contents. If the path is not there, it skips removing it.
<RavenJoad>Perfect. Adding #:unwind? #t made it do exactly what I want. I was not sure if unwinding the stack to run the exception handler meant the whole thing would be aborted.
<dthompson>yeah I think that section of the docs could be made more clear. it took me a bit to understand how to use with-exception-handler properly
<RavenJoad>Agreed. Some simple examples of doing common exception handling things would be very helpful.
<RhodiumToad>(guard (exc ((external-error? exc) #f)) (lstat "nonexists")) ;; simplest way to catch a filesystem error
<RhodiumToad>(guard) is from srfi-34
<dthompson>there's also good ol' false-if-exception
<dthompson>built-in to Guile
<dthompson>only good if you're okay with ignoring all exceptions
<RhodiumToad>using (guard) that way will catch and unwind the specified exception type(s) without affecting others
<RhodiumToad>it's like a (cond), you can have multiple clauses
<tromey>this code tries to locally define a macro like (let ((local-name some-macro)) ... (local-name blah))
<tromey>hmmmmm
<RhodiumToad>i.e. (guard (varname (pred handler...) (pred handler...) ...) body...)
<RhodiumToad>tromey: letrec-syntax ?
<dthompson>RhodiumToad: #:unwind-for-type does the same in with-exception-handler
<RhodiumToad>dthompson: last I checked that was rather more limited
<tromey>RhodiumToad: yeah, going to try it, thanks
<tromey>doesn't work for this scenario, where it is using define-macro
<tromey>that's where my "source expression failed to match any pattern" error comes from though
<RhodiumToad>some-macro is the name of an already defined macro?
<tromey>yeah
<tromey>removing all these bindings and replacing the names gets me a little further
<tromey>there's no real need for this, it seems to just be a brevity thing
<tromey>the new problem is that if I have (define-macro (mmm . args) ...), then (mmm 1 2 3 . 4) fails with "Apply to non-list"
<tromey>hmm not sure about this actually, I get a different answer from the real program as opposed to my interactive tests
<RhodiumToad>you can do that with define-syntax, not sure why define-macro barfs on it
<tromey>yeah, something here I really don't get
<RhodiumToad>ah. I see why it barfs
<RhodiumToad>the core of define-macro is this: (let ((v (syntax->datum #'args))) (datum->syntax y (apply transformer v)))
<RhodiumToad>where y is the invoking form and transformer is the macro definition
<RhodiumToad>but (apply) can't take an improper list
<tromey>yeah
<tromey>that was my simplified code, unfortunately my real bug is something else
<tromey>... which somehow I can't seem to reproduce interactively :(
<tromey>maddening!
<tromey>ok, I have a test case
<tromey> https://pastebin.com/s514CtYq
<tromey>guile -l /tmp/q.scm gives me an error about "source expression failed to match"
<tromey>but if I comment out the (define do-it () line and the final ")", it is ok
<tromey>time to learn define-syntax I guess
<RhodiumToad>what's the (define do-it () ...) supposed to do? did you mean (define (do-it) ...) ?
<tromey>sorry let me try that
<RhodiumToad>but define-syntax is always good to know
<tromey>I am more of an elisp person
<tromey>hmm I wonder if I ahve this mistake
<RhodiumToad>define in scheme is (define sym val) or (define (func args) body...)
<tromey>yeah
<RhodiumToad>whereas you had (define sym () (stuff)) which isn't either
<tromey>ok, I checked my real source and I don't have this mistake in it
<tromey>but I do get the same symptoms
<tromey>which seem mysterious to me
<tromey>sorry about that though
<tromey>I have a theory there's another hidden macro expansion somewhere and it doesn't like the dotted list
<tromey>no wonder nobody works on cgen
<RhodiumToad>what's the actual error?
<tromey>source expression failed to match any pattern in form (....)
<tromey>it's on a different machine so cut/paste is hard
<RhodiumToad>what form, though
<tromey>(reg &options &mode hw-elm . indx-sel)
<tromey>I suspect it's deeper in this code (which is pretty wack) and just hidden by the location reporting
<RhodiumToad>is reg a macro?
<RhodiumToad>and what is def-rtx-operand-node defined as?
<tromey>afaik reg is not a macro
<tromey>def-rtx-operand-node is complicated
<tromey>it's an ordinary function but calls eval, so who knows
<tromey>meh, I think I'm going to give up on this
<tromey>cgen is probably beyond repair
<tromey>RhodiumToad: ok, reproducer, I think correct this time: https://pastebin.com/MffANNdx
<tromey>run with "guile -l /tmp/q.scm"
<RhodiumToad>I think the basic problem here is that (foo . bar) is inherently not legal syntax unless it's inside a (quote) or unless foo is itself a macro
<RhodiumToad>so it expands to (def-rtx-operand-node (reg blah . blah) stuff) which isn't a legal construct
<RhodiumToad>i.e. it's not (proc arg arg...) because (reg blah . blah) isn't a valid form for arg
<RhodiumToad>are you sure there's not a (quote) missing somewhere?
<RhodiumToad>what args does def-rtx-operand-node expect?
<tromey>it's an ordinary define whose first arg is a "name-and-args" like 'define' takes
<tromey>so perhaps my define-macro ought to be quoting these
<tromey>I'll try that. thank you
<tromey>I wish the error were a bit more understandable somehow
<jab>if I have a gexp, how do I lower that a produce an actual file in the guile repl?
<jab>something like ,lower gexp
<jab>?