IRC channel logs

2016-02-21.log

back to list of logs

<davexunit>so the 'define-module' and other top-level forms are within that 'begin'
<davexunit>but if I remove them from the begin, the compiler things I'm compiling a procedure application form or something.
<davexunit>not sure how to properly construct a whole module that actually has the symbols available to it that it should.
<davexunit>compilation succeeds, which means that the symbols were available at compile time.
<davexunit>but at run-time it all blows up.
<mark_weaver>davexunit: I think you need to arrange for the 'define-module' to be outside of the begin.
<davexunit>mark_weaver: yeah, but I'm currently unsure how to do so.
<davexunit>because I need to compile to an expression, not a list of expressions.
<mark_weaver>the issue surely has to do with the fact that the 'define-module' sets the current module, and the macro expander needs the current module to be set correctly when expanding code.
<davexunit>yeah
<davexunit>I guess I would need to compile this in multiple passes
<davexunit>but it's not obvious to me how to do that, because there isn't a 1:1 correlation between top-level scheme expressions and what the reader produces
<mark_weaver>ArneBab_ had the same issue with wisp, and I suggested a hack, but it's suboptimal.
<mark_weaver>basically the idea is that the reader that you tell guile about has a built-in buffer, a list of top-level forms.
<davexunit>hmm alright
<mark_weaver>so the *real* reader can return a list of top-level forms, but the buffered reader has a buffer, and each time it's called it does this: if its buffer is empty, it calls the *real* reader until its result is not empty, and then sets the buffer to be that result list. and then it returns the first element from its buffer, and removes it.
<mark_weaver>of course, in most cases 'begin' can be used.
<davexunit>yeah
<mark_weaver>but that falls apart for things like 'define-module'.
<davexunit>okay, I will try this approach
<davexunit>I will add a dummy instruction to define the module
<davexunit>basically, my reader processes an XML file and produces a big list of lists with information about regular variables, structs, and procedures.
<mark_weaver>davexunit: you're implementing this as a 'language' in guile?
<davexunit>mark_weaver: yes
<davexunit>a la guile-xcb
<davexunit>it's an experiment
<davexunit>but seems to be going well
<mark_weaver>have you considered just writing a macro instead?
<mark_weaver>a macro a la 'include'?
<mark_weaver>see the definition of 'include' in ice-9/psyntax.scm
<davexunit>okay I'll look
<mark_weaver>most of the complexity there is due to trying to be clever about where to look for the file.
<mark_weaver>but the basic idea is that you can read a file and run 'datum->syntax' and then return that syntax object wrapped in 'begin'.
<mark_weaver>and if you do it this way, you don't need to generate the entire file, so you don't need to worry about generating the 'define-module'
<davexunit>so a macro instead of a language?
<davexunit>hmmmm
<mark_weaver>you could pass the name of the XML file, and it could generate the code you want.
<mark_weaver>just an idea :)
<davexunit>thanks :)
<Jookia>So I have this: `(do-thing ,((lambda () 'test))) = (do-thing test), but I want it to be (do-thing 'test)
<Jookia>Is there a better way to quote these things
<davexunit>Jookia: so you want (do-thing (quote test)) ?
<davexunit>you don't need lambda for this, but: `(do-thing ,((lambda () ''test)))
<Jookia>davexunit: In reality '(lambda () 'test)' is an access to a record, so I can't edit inside it
<davexunit>Jookia: why do you want the double quoting?
<davexunit>is it really significant in what you are doing?
<Jookia>Yes, I'm trying to return a function call to be eval'd to inserted in to a script
<Jookia>eval'd or*
<davexunit>why not use a macro?
<davexunit>eval should be avoided, in general.
<davexunit>unless you are writing something along the lines of a REPL
<Jookia>I'm not using a macro because I forgot about them
<Jookia>Can the output of macros be inserted in to an sexpr?
<davexunit>the "output" of a macro is Scheme code.
<davexunit>we say that a macro "expands" to this code
<Jookia>I see. Time to write a macro :)
<davexunit>so as long as the result of the expansion is valid in the context you use it in, you can do whatever you want.
<Jookia>Oh cool
<davexunit>define-syntax-rule is a good place to start
<davexunit>here's a simple one
<davexunit>(define-syntax-rule (push! var val) (set! var (cons val var)))
<davexunit>with this, the code (push! foo 1) expands into (set! foo (cons 1 foo))
<Jookia>Oh, that's exactly what I need
<davexunit>a situation like this called for a macro because there is no way to accomplish with a plain procedure.
<davexunit>(or nothing that is terse, rather)
<davexunit>for most situations, procedures are the proper means of abstraction.
<Jookia>Yeah, I'm use to higher-order functions being the 'highest' abstraction in functional programs
<davexunit>but every now and again you'll encounter a situation where you want to extend the syntax of the language.
<davexunit>another example: if 'let' were not available, it could be trivially implemented using a macro.
<davexunit>(define-syntax-rule (let ((name value) ...) body ...) ((lambda (name ...) body ...) value ...))
<davexunit>well, trivial once you understand how ellipsis works.
<Jookia>Interesting, can define-syntax-rule employ #:key ?
<davexunit>that's a define* thing
<davexunit>so no
<davexunit>syntax-rules has its own syntax
<davexunit>but it makes me think of another example: procedure definition is just sugar for (define name (lambda args body))
<Jookia>Interesting
<davexunit>or maybe more accurately, it *could* be implemented this way. I actually don't know how Guile does it.
<Jookia>I'm not sure if define-syntax-rule is the right tool here because there's processing to be done in the function rather than just expanding
<davexunit>it's a good practice to figure out how to do the thing you want to do *without* macros first.
<davexunit>and then add the sugar afterwards.
<davexunit>so you'll want to write the procedures that do the operations you are interested in.
<davexunit>and then evaluate if new syntax will benefit you
<Jookia>Hmm. I'll have a shot, but here's the 7 lines I'm trying to fix (if you have time): http://sprunge.us/QGAQ
<davexunit>oh this is for guix?
<davexunit>is this generating build-side code?
<Jookia>Yeah
<davexunit>in that case, just using regular quasiquotation is what you want
<Jookia>That's what I thought but I've added a platform flag that isn't being quoted properly
<Jookia>'bios turns to bios
<Jookia>... Though I could just re-quote it since I know it'll be quoted.
<davexunit>instead of ,target try (quote ,target)
<Jookia>Thanks
***Korhoset is now known as Stanislav_Excell
<stis>hej guilers!
<amz3>hi
<artyom-poptsov>Hello everybody
<amz3>the dynamic-link* I posted on the mailling is different, it doesn't use ice-9 match
***Armand is now known as Guest16639
<davexunit>alright, I generated wrappers for the Vulkan API functions.
<Jookia>Nice!
<davexunit>now to wrap the structs.