IRC channel logs

2014-10-03.log

back to list of logs

<davexunit>I asked this question last night and I'm asking again because I'm too lazy to just mail the list right now: is it bad practice to export record type identifiers e.g. <foo> in modules?
<davexunit>from reading other guile code, I see that they are typically not exported. however, when they are exported it allows the user to destructure that type with 'match'.
<mark_weaver>davexunit: I think it's okay, but just beware that you are effectively making the specific order of the slots part of your API when you allow users to destructure your records with 'match'. (language tree-il) is an example of a guile module that exports the record type identifiers, fwiw.
<davexunit>mark_weaver: that's a good point. thanks.
<davexunit>I am okay with that for my situation.
<mark_weaver>okay. you should still be able to add more slots to the end, if needed.
<davexunit>the slots won't change. it's a euclidian vector math module for 2d, 3d, and 4d vectors.
<mark_weaver>oh yeah, it's very reasonable to make those record layouts part of your API, indeed.
<davexunit>thanks for confirming that it's an okay idea. :)
<mark_weaver>np!
<mark_weaver>rlb: you should cherry-pick 1baa2159307c34683e8ede54f38f65010fc594b0 into debian, I think. nasty memory corruption bug in get-bytevector-n.
<mark_weaver>well, really the bug is in scm_c_shrink_bytevector, which is itself an API function, but 'get-bytevector-n' uses it.
<mark_weaver>well, I can see some others such as 8442211. I should look through the commits and give you a complete list of suggested commits to cherry-pick.
<rlb>mark_weaver: by all means -- if you like -- we have about 20 days (or less) before the freeze deadline (need 10 days to migrate from unstable to testing)
<mark_weaver>rlb: okay, thanks. there aren't that many commits since 2.0.11, so it's not a big job.
<mark_weaver>(to look through them)
<mark_weaver>rlb: can you remind me where I can find the current set of patches for Debian's Guile 2.0.11 package?
<rlb>if you "apt-get source guile-2.0" (and have unstable in your sources.list), it'll unpack it and all the patches will be in guile-2.0*/debian/patches. Alternately: http://anonscm.debian.org/cgit/users/rlb/guile.git/tree/debian/patches?h=deb/guile-2.0/d/sid/master
<mark_weaver>thanks
<mark_weaver>rlb: okay, here's my suggested set of commits to cherry-pick: http://paste.lisp.org/+331S
<rlb>brilliant -- thanks
<mark_weaver>np!
<civodul>Hello Guilers!
<nalaginrut>well, seems several commits appear in master, nice~
<nalaginrut>seems gmail was DNS polluted again here...
<lloda>would be nice to have (exact n)
<ft>What would it do?
<lloda>alias for (inexact->exact n), but it's clear that n can be either
<lloda>either exact or inexact I mean
<lloda>it seems it's in R(6|7)RS
<dsmith-work>Happy Friday, Guilers!!
<trashbird1240>hello
<trashbird1240>I'm trying to translate from a list of symbols to strings, modify those strings to get a list of procedure names and then get procedure information
<trashbird1240>I have a list of options in an option-spec and I take the car, then map symbol->string across the result
<trashbird1240>then I append "get-" to each one
<trashbird1240>Now I have a list of the names of procedures used to access those options
<trashbird1240>Then I want to get the docstrings from them using `procedure-documentation'
<mark_weaver>trashbird1240: see <http://www.gnu.org/software/guile/manual/html_node/Module-System-Reflection.html>. You probably want either (module-ref <module> <name>). You need to specify the module, because each module has its own symbol->variable mapping.
<mark_weaver>s/either //
<mark_weaver>to get the module object from the module name, use 'resolve-module'
<mark_weaver>you could also use 'module-variable' to look up the variable object, and then the procedures in <http://www.gnu.org/software/guile/manual/html_node/Variables.html>
<trashbird1240>mark_weaver: okay, if I use (module-variable (current-module) 'get-mean) then it returns the variable
<trashbird1240>but it appears I can't use that directly with procedure-documentation
<trashbird1240>I will try using variable-ref
<trashbird1240>This works : (procedure-documentation (variable-ref (module-variable (current-module) (string->symbol "get-mean"))))
<mark_weaver>trashbird1240: right, or you can just do (procedure-documentation (module-ref (current-module) (string->symbol "get-mean")))
<mark_weaver>btw, there's also 'symbol-append' to append symbols directly, e.g. (symbol-append 'get- 'mean) => 'get-mean
<mark_weaver>(it works by converting to strings, appending, and then converting back, but it might make your code look a bit nicer)
<trashbird1240>mark_weaver: thanks
<trashbird1240>that might be my next revision
<trashbird1240>I need to get back to slightly less fun work :)
<trashbird1240>I did get it working
<trashbird1240>it's printing a relatively GNU-ish help message
<paroneayea>what does "a ``field '' of an object" in relation to (match) mean? does that include goops fields?
<davexunit>a field is a property of a record type.
<paroneayea>so, no :)
<davexunit>(define-record-type <foo> (make-foo bar) foo? (bar foo-bar)) ;; bar is a field
<davexunit>I actually don't know how it works with GOOPS
<davexunit>not sure if a GOOPS object can be destructured with match, but maybe?
<paroneayea>hm
<taylanub>actually I think for any (foo x) => y, y is the foo field of x.
<taylanub>(match 0 ((= zero? x) x)) => #t
<taylanub>that's why it uses the scare quotes around ``field'' in the documentation I think
<paroneayea>taylanub: aha, interesting... huh!
<davexunit>oh, maybe I'm misinterpreting then.
<paroneayea>fields! they're more than just fields (???)
<davexunit>let's test... I have never used = yet
<taylanub>davexunit: well it works with record field accessors too of course, just much more generalized
<davexunit>yeah
<davexunit>yup, taylanub is right
<davexunit>(match 2 ((= square x) x)) ;; => 4
<davexunit>where 'square' is (lambda (x) (* x x))
<davexunit>should've used a built-in procedure, oops. :)
<davexunit>that's really cool, actually.
<davexunit>(match "foo" ((= string-length l) l))
*tadni totally forgot Emacsy was a thing, till like 10 minutes ago.
<davexunit>tadni: dead project, I'm afraid.
<tadni>davexunit: Yeah, some weird design choices to. Literate programming via noweb is a bit odd.
<davexunit>yes
<tadni>Still might be fun to play with a bit. :^P
<paroneayea>you can't put a lambda in the (= )
<paroneayea>but
<taylanub>paroneayea: I can here...
<davexunit>yeah, it needs to be an identifier
<paroneayea>you can (let) define the lambda just outside it
<paroneayea>and that's fine
<davexunit>taylanub: oh really? testing...
<taylanub>using 2.0.11
<davexunit>I can as well.
<paroneayea>oh
<paroneayea>okay, what did I do wrong the first time :)
<davexunit>I didn't think that would work.
<paroneayea>oh
<paroneayea>hahahahahaha
<davexunit>match continues to impress me.
<paroneayea>I saw what I did.
<paroneayea>nm, I'm being an idiot
<paroneayea>AS USUAL
<davexunit>match is one of those life-changing macros.
<paroneayea>I still don't understand it totally yet... I need to play with it more.
<paroneayea>so in the match example in the docs
<paroneayea>what's going on with the '_' character?
<davexunit>it means that you aren't binding a variable for that matched item
<paroneayea>oooic
<paroneayea>kind of like an else
<davexunit>(match '(foo bar) ((x _) x))
<davexunit>a 2 element list is matched, but only the first element is bound to a variable
<davexunit>the presence of the element is important, but it's value is not.
<davexunit>oh, and it matches anything.
<davexunit>so you'll see match forms with a final case like: (_ (lol-idunno))
<paroneayea>I was reading some other docs, forgot for a small moment about this window, and literally lol'ed at lol-idunno :)
<davexunit>sometimes I use it to display a more specific error message so the user doesn't see the standard match error.
<davexunit>heh
<nalaginrut>92 people ;-) zzzZZZ...
<dca>can i haz multiple guile instances in my C program ?
<dsmith-work>dca: No.
<dca>dsmith-work: but i can run my different functions with scm_with_guile and each time the function will be computed in fresh environment?