IRC channel logs

2019-09-07.log

back to list of logs

<lispmacs>hi, is there a way to run an action upon collection of an object?
<lispmacs>make-guardian?
<lispmacs>why are there both procedure properties and object properties? Is there some reason you wouldn't just use object properties for everything, even procedures?
<wingo>lispmacs: guardians are a good option, yes. also search for finalizers in the manual
<wingo>the whole property situation is a bit historical. however some procedure properties can be compiled into the procedure itself, like the name, arity, docstring, so there is an implementation difference
<wingo>my advice would be to ignore them unless you are writing reflective code
<wingo>what would it take to have an r6rs mode, i wonder
<wingo>i wonder if language=r6rs is sufficient
<wingo>i.e. guile --language=r6rs
<weinholt>i see three areas where guile has a problem with r6rs: (1) .guile.sls is not in %load-extensions by default; (2) some read-enable calls are needed to get r6rs support in read (3) identifiers like else and => and not bound and exported
<weinholt>--language=r6rs seems like a big hammer
<wingo>yeah
<weinholt>point 2 could be fixed if read recognized #!r6rs and saved it on a per-port basis, but i think there was some objection to that
<wingo>given the global flags needed (the read options) i think an --r6rs command (but not a --language) might be the right thing; would add .sls, .guile.sls, and .sps (?) to the extensions list
<weinholt>.sps is just programs, i don't think it needs to be in that list
<wingo>and set the read/print flags, and set up the initial environment so that only "import" and "library" are available
<wingo>true
<weinholt>the problem with the global read flags is that r6rs code might want to load some native guile modules
<wingo>that's fine, modules in guile itself don't depend on a particular read flag afaiu
<wingo>it would just be third-party modules
<weinholt>ok
<wingo>probably we should issue deprecation warnings when the incompatible escapes are used, so we can migrate everybody to one syntax
<wingo>supporting multiple syntaxes is possible of course but would be nice to avoid it
<weinholt>makes sense
<wingo>incompatible == guile's historical syntax
<wingo>regarding "else", it could be that we should make it bound in guile's definition too
<wingo>i.e. to avoid incompatibilities between guile's case and r6rs's case
<wingo>the 3.0 release would be a good time to make that change i think. has an incompatibility risk but maybe it is manageable
<weinholt>it's nice to be alive to see this change :)
<wingo>hehe :)
<wingo>r6rs is 12 years old at this point :)
<wingo>incidentally i would like to add --r7rs too
<wingo>would make peoples' lives easier
<wingo>but, i was hoping someone would get to it before i did :)
<weinholt>guile can run r7rs code with the help of akku, but it would indeed be nice with native support
<wingo>yeah it would make sense. we have all the code, we just need the module definitions
<wingo>i wonder if racket's unparenthesized thing is going to work
<wingo>i am very happy to follow racket in many things but that is an interesting and speculative change that i am happy to let them experiment with :)
<wingo>the honu paper is v interesting btw if you haven't read it
<wingo> https://www.cs.utah.edu/~rafkind/papers/honu-2012.pdf
<weinholt>here are the module definitions from akku, could be reusable for guile: https://gitlab.com/akkuscm/akku-r7rs/
<weinholt>i haven't; will check out it
<wingo>er, https://www.researchgate.net/profile/Matthew_Flatt/publication/262349592_Honu_Syntactic_Extension_for_Algebraic_Notation_through_Enforestation/links/5464ba3b0cf267ed84f259c3/Honu-Syntactic-Extension-for-Algebraic-Notation-through-Enforestation.pdf rather
<wingo>^ that was the one i was thinking of
<wingo>weinholt: thanks!!
<wingo>i didn't know about akku
<weinholt>oh, i see :)
<wingo>neat :)
<weinholt>i accounced it in the basement of the internet: comp.lang.scheme (and also planet scheme)
<wingo>hehe
<wingo>i am totally out of the loop these days
<wingo>what guile time i have i spend noodling in the compiler instead of building applications :/
<weinholt>it is very appreciated work though
<weinholt>i'm doing my own r6rs compiler now as well: https://scheme.fail/ and https://gitlab.com/weinholt/loko
<wingo>i'm glad for that but it is also personally gratifying :)
<wingo>neat!
<wingo>did it change names at some point?
<weinholt>a few times, but i haven't made this particular one public before
<wingo>ah that looks delightful
<weinholt>i ripped off your fibers API and based the code on your blog articles :)
<wingo>i did a little work recently on https://github.com/google/schism recently, which was pretty fun
<wingo>weinholt: excellent!!
<wingo>i'm glad it works for you :)
<weinholt>it does. the plan is to build hardware drivers etc using fibers. i even made an operation that waits for an interrupt
<wingo>nice!
<wingo>that sounds really delightful
<weinholt>:)
<wingo>i am very much in favor of efforts that make this timeline the one where r6rs won :)
<heisenberg-25>Does guile support the index operator [] for hash-tables? If not, can I write a custom function to do so?
<heisenberg-25>Basically, instead of writing (hash-ref (hash-ref (hash-ref (hash-ref scm "aggs") "operations") "terms") "field") it is much readable to write scm["aggs"]["operations"]["terms"]["field"]
<chrislck>heisenberg: go back to python and never come back again :) (or, interesting question which someone may suggest a define-syntax macro)
<janneke>heisenberg-25: something like (define (hash-refn table key . rest) ...) should be doable
<heisenberg-25>chrislck: I am actually trying to write a macro to achieve that. I know my python roots is affecting my scheme programming :)
<heisenberg-25>janneke: can you please explain a bit/
<chrislck>(define (hash-refn table key . rest)
<chrislck> (let ((val (hash-ref table key)))
<chrislck> (if (null? rest)
<chrislck> val
<chrislck> (apply hash-refn val rest))))
<chrislck>(hash-refn scm "aggs" "operations" "terms" "field")
<str1ngs>daviid: (make <gtk-text-iter>) fails with ERROR: In procedure scm_i_foreign_call: Wrong type argument in position 1 (expecting POINTER_P): #f . GtkTextIter generally is not contructed as a pointer but like so. GtkTextIter iter; then usually passed as a pointer with &iter to receiving functions. I guess I'm not sure how to create a GtkTextIter other then with make.
<heisenberg-25>chrislck: oKay, this is better version than what I had in mind. Thank you!
<str1ngs>daviid here's my use case if it helps. http://git.savannah.nongnu.org/cgit/nomad.git/tree/guile/text.c?h=feature-g-golf#n84. note. source is a GtkSourceView which inherits GtkTextView
<lispmacs>is there a way to undefine a variable?
<heisenberg-25>lismacs: what do you mean by "undefine"? Also you can set it to #f if you want it to be "null"
<ft>There's (if #f #f) → #<unspecified> …but it sounds like lispmacs wants to remove something from the set of bound symbols.
<lispmacs>ft: yes, I was imagining the would be a way to remove a symbol from top level bound symbols
<lispmacs>which, i think is different from a let binding
<lispmacs>just something I wanted to do for garbage collection experiments and such like
<lispmacs>why doesn't this work as expected?:
<lispmacs>(let ((a (list 20 21 22))) (g a) (set-object-property! a 'cleanup (lambda () (display "AAAARRRgggh!\n"))))
<lispmacs>scheme@(guile-user)> (define k (g))
<lispmacs>scheme@(guile-user)> k
<lispmacs>$53 = (20 21 22)
<lispmacs>scheme@(guile-user)> (object-property k 'cleanup)
<lispmacs>$56 = #f
<lispmacs>I'm expecting the procedure to still be attached to the object-property
<lispmacs>`g' being a guardian
<heisenberg-25>How do I install and import in guile a r6rs library? like this one here https://github.com/weinholt/uuid
<mwette>Look at the section on modules in the ref manual. You may have to use the module programming API
<heisenberg-25>I used akku to install the package and did (import (uuid)) in guile shell, but guile can't find the code
<rain1>try asking #akku
<lispmacs>just curious, how big is an SCM object?
<lispmacs>scm_t_bits and SCM variables have at least 32 bits
<chrislck>lispmacs: found it: (define X 'x) (variable-unset! (module-variable (current-module) 'X)) (defined? 'X) -> #f
<lispmacs>chrislck: thanks, worked for me also
<lispmacs>I'm still trying to figure out why my object properties are not preserved when the object is pulled out of a guardian
<lispmacs>been reading through the manual -- seems like they should be, but I'm not sure I fully understand weak references
<lispmacs>(let ((x (list 1 'a 3 'b 102934342342342342342))) (set-object-property! x 'color 'white) (g x))
<lispmacs>(gc)
<lispmacs>(define w (g))
<lispmacs>w
<lispmacs>$18 = (1 a 3 b 102934342342342342342)
<lispmacs>(object-properties w)
<lispmacs>$19 = ()
<lispmacs>properties seem to disappear when the list goes out of scope in the original let expression
<lispmacs>well, I guess I don't have to use properties, but am curious what I am misunderstanding
<lispmacs>using guile-2.2.3
<janneke>what is `g'?
<lispmacs>(define g (make-guardian))
<jcowan>Most objects have either no references (numbers, strings, symbols) to other objects, or else they have strong reference (pairs, vectors, records). An object can be garbage collected if there are no strong references to it, because there's no way of getting to it.
<jcowan>Some objects (weak boxes, weak pairs, weak hash tables) hold weak references. These work exactly like strong references except that they do not prevent the referred-to object from being garbage collected. So a list made of weak pairs can be used to keep track of all objects used for a certain purpose, but if any of those objects become garbage, you'll no longer be able to get at them from the weak list. If you used a
<jcowan>strong list, they couldn't become garbage.
<jcowan>lispmacs: ^^
<lispmacs>jcowan: okay, thanks for the great explanation. I'm still not quite clear on why object properties disappear when the object is returned from the guardian. I would think that the reference to the object from the guardian would be enough to keep the object properties around also, even though they are implemented with a weak key hash table. But maybe the guardian uses some kind of special reference...?
<jcowan>What do you mean by "object properties"?
<lispmacs>jcowan: like, (define a (list 1 2 3)) (set-object-property! a 'color 'blue)
<lispmacs>(object-property a 'color)
<lispmacs>evaluates to 'blue
<lispmacs>section 6.11.2
<jcowan>Oh. Because the association between an object and its property list is weak, as it must be: you don't want the object -> plist association to hold a strong pointer to the object.
<cmaloney>3a
<jcowan>The point of a guardian is to give an object containing weak references to purge them when the weak references break. In a weak hash table, it's not enough that the value is held weakly by the association; you want the whole association to be removed from the hash table when the key is garbage.
<jcowan>s/give/allow
<jcowan>the hash table can poll the guardian: Anything to remove now?