IRC channel logs

2024-06-08.log

back to list of logs

<sneek>Yey! chrislck is back
<cpli>i don't think i understand `list->array`.. shouldn't this simply return a 3x3 array filled with 7s? (list->typed '(3 3) '(7 7 7 7 7 7 7 7 7))
<dsmith>sneek, botsnack
<sneek>:)
<dsmith>!uptime
<sneek>I've been serving for 2 months
<sneek>This system has been up 12 weeks, 4 days, 29 minutes
<haugh>cpli, list->array doesn't tabulate your dimensions for you; your provided LIST must already be composed of appropriately sized lists, e.g. (list->array '(3 3) '((0 1 2) (3 4 5) (6 7 8)))
<rlb>haugh: in C at least, they are in the end, just integers, typically/often(?) not even actual variables, i.e. they're C preprocessor defines (think "sed-ish" s/ENOMEM/12/ at compile time) and it's roughly a global namespace. Of course guile could have a some way to map symbols back to those integers, but just defining the names with integer values is a fairly straightfoward approach.
<haugh>thanks!
<rlb>certainly
<cpli>`syntax-case` starts complaining about `a` being undefined if it's being generated by another macro: https://paste.sr.ht/~cpli/b76e0fdee1a6caa80c0fb3ab71486463d01e0cff
<cpli>i.e. in this example `(let-array-indexes.1 (a (3 3)) body ...` works and populates `body` with `a11 a12 .. a33` wheras if i write `(let-array-indexes ((a (3 3)) (b (3 3))) body ...` it tells me it can't resolve `a`..
<mwette>I believe syntax-rules will rename symbols generated within it's scope
<mwette>can rename, I guess
<mwette>(define-syntax f ((_ x) (let ((t 1) (+ x t))))) ; then ,expand (foo t) =>
<mwette>(let ((t-1 1)) (+ t t-1))
<cpli>mwette, sure but `a` comes from outside of your `f`
<cpli>i.e. `(define (matrix-3x3-* a b) (let-array-indexes ((a (3 3)) (b (3 3))) body ...` complains
<cpli>ohhh... you mean that it thinks `a` is `syntax-rules` internal..
<cpli>hmm
<cpli>how would i convince it otherwise?
<mwette>maybe; and there used to be a bug in guile (it could still be there) where Guile's syntax-rules would not do the right thing, trying to deal with creating unique identifiers, IIRC
<mwette>there are two `t's in my case: one from outsize and one from inside
<mwette>so it renames the inside `t' to `t-1'
<mwette>at the repl try to ,expand (matrix-* a b)
<cpli>mwette: matrix-* is a procedure, i'd have to ,expand (let-array-indexes ((a (3 3)) (b (3 3)) body ...)
<rlb>cpli: without having looked, by default, yeah, I'd assume "proper hygene" is treating two bindings that happen to share the same name as independent (as you'd normally want), and if that's right, then the "fix" is probably to be explicitly unhygenic via syntax->datum and datum->syntax, etc. Or, if "the whole thing" is mostly unhygenic, I suppose you could consider define-macro.
<cpli>rlb: look because i'm using `datum->syntax` and passing the syntax-id into a procedure. it works! but i don't know how to recursively deconstruct binding lists
<cpli>i'm trying to template the unhygienic macro multiple times, and then it starts complaining
<cpli>if i shouldn't do what i'm about to, tell me in future:
<cpli>(let ((a-1 (list->array (quote (1 1)) (quote ((9 2) (5 8))))) (b-1 (list->array (quote (1 1)) (quote ((2 3) (0 7)))))) (let ((a11 (array-ref a 1 1)) (a12-1 (array-ref a 1 2)) (a21 (array-ref a 2 1)) (a22 (array-ref a 2 2))) (let ((b11 (array-ref b 1 1)) (b12 (array-ref b 1 2)) (b21 (array-ref b 2 1)) (b22 (array-ref b 2 2))) a12)))
<cpli>mwette: that's (tree-il->scheme (macroexpand x)) and if you look closely, it turns a12 into a12-1 such that body can't bind it anymore.. o-o
<rlb>cpli: sorry, not sure I should have piped up -- may not have time to delve today.
<cpli>no worries >~< but thanks nonetheless
<mwette>cpli: if you want to dig, this may be it:
<mwette><cpli> how would i convince it otherwise?
<mwette><mwette> maybe; and there used to be a bug in guile (it could still be there)
<mwette> where Guile's syntax-rules would not do the right thing, trying to
<mwette> deal with creating unique identifiers, IIRC [11:53]
<mwette><mwette> there are two `t's in my case: one from outsize and one from inside
<mwette> [11:54]
<mwette><mwette> so it renames the inside `t' to `t-1' [11:55]
<mwette><mwette> at the repl try to ,expand (matrix-* a b) [11:56]
<mwette><cpli> mwette: matrix-* is a procedure, i'd have to ,expand (let-array-indexes
<mwette> ((a (3 3)) (b (3 3)) body ...) [12:05]
<mwette><rlb> cpli: without having looked, by default, yeah, I'd assume "proper
<mwette> hygene" is treating two bindings that happen to share the same name as
<mwette> independent (as you'd normally want), and if that's right, then the
<mwette> "fix" is probably to be explicitly unhygenic via syntax->datum and
<mwette> datum->syntax, etc. Or, if "the whole thing" is mostly unhygenic, I
<mwette> suppose you could consider define-macro. [12:06]
<mwette><cpli> rlb: look because i'm using `datum->syntax` and passing the syntax-id
<mwette> into a procedure. it works! but i don't know how to recursively
<mwette> deconstruct binding lists [12:08]
<mwette><cpli> i'm trying to template the unhygienic macro multiple times, and then it
<cpli>uhh mwette
<mwette> starts complaining [12:09]
<mwette><cpli> if i shouldn't do what i'm about to, tell me in future: [12:11]
<mwette><cpli> (let ((a-1 (list->array (quote (1 1)) (quote ((9 2) (5 8))))) (b-1
<cpli>you're dumping log
<mwette> (list->array (quote (1 1)) (quote ((2 3) (0 7)))))) (let ((a11
<mwette> (array-ref a 1 1)) (a12-1 (array-ref a 1 2)) (a21 (array-ref a 2 1))
<mwette> (a22 (array-ref a 2 2))) (let ((b11 (array-ref b 1 1)) (b12 (array-ref
<cpli>oh no
<mwette> b 1 2)) (b21 (array-ref b 2 1)) (b22 (array-ref b 2 2))) a12)))
<mwette><cpli> mwette: that's (tree-il->scheme (macroexpand x)) and if you look
<mwette> closely, it turns a12 into a12-1 such that body can't bind it
<mwette> anymore.. o-o [12:12]
<mwette><rlb> cpli: sorry, not sure I should have piped up -- may not have time to
<mwette> delve today. [12:13]
<mwette><cpli> no worries >~< but thanks nonetheless [12:14]
<mwette>ERC> cpli: i
<mwette><cpli> how would i convince it otherwise?
<mwette><mwette> maybe; and there used to be a bug in guile (it could still be there)
<mwette> where Guile's syntax-rules would not do the right thing, trying to
<mwette> deal with creating unique identifiers, IIRC [11:53]
<mwette><mwette> there are two `t's in my case: one from outsize and one from inside
<mwette> [11:54]
<mwette><mwette> so it renames the inside `t' to `t-1' [11:55]
<mwette><mwette> at the repl try to ,expand (matrix-* a b) [11:56]
<mwette><cpli> mwette: matrix-* is a procedure, i'd have to ,expand (let-array-indexes
<mwette> ((a (3 3)) (b (3 3)) body ...) [12:05]
<mwette><rlb> cpli: without having looked, by default, yeah, I'd assume "proper
<mwette> hygene" is treating two bindings that happen to share the same name as
<mwette> independent (as you'd normally want), and if that's right, then the
<mwette> "fix" is probably to be explicitly unhygenic via syntax->datum and
<cpli>q-q
<haugh>RIP
<cpli>ouch
<mwette>sorry about that. I think I had a copy/paste malfunction.
<cpli>happens.
<mwette>anyhow here is a paper on workings of syntax-case etc: https://legacy.cs.indiana.edu/~dyb/pubs/LaSC-5-4-pp295-326.pdf
<cpli>i remember pasting the google home-page html into #commonlisp
<mwette>haha
<cpli>(syntax-object->datum x) is horrendeous, but i don't know if this'll properly help here.. i haven't found anywhere how nested `syntax-case` is supposed to behave
<cpli>ALSO NESTED syntax-case SHOULDN'T BEHAVE ANY DIFFERENTLY
<cpli>hmm
<mwette>IIRC, roughly, symbols are painted red and blue, and at scope changes they flip
<mwette>cpli: section 4 of the paper referenced above
<haugh>cpli, is this specifically a syntax exercise for you or do you just need a matrix product in scheme ASAP?