IRC channel logs


back to list of logs

<daviid>paroneayea: will read, thanks
<daviid>a bit busy with another thing right now...
<sapienTech>hi all, is this a good channel to chat about programming questions with guile?
<sapienTech>okay, cool just making sure its not guile development specific
<sapienTech>so I'm starting to learn about continuations, and wanted to use it to build a number generator
<sapienTech>this is the code I have:
<rain1>are you set on using call/cc? it might be easier with reset & shift
<sapienTech>rain1: definitely not set on it, just wanted to start there, and then move on to prompts
<sapienTech>the code creates a number generator, and each time the generator is called, it returns a value, and saves the current continuation to get the next value
<sapienTech>it works just how id like if the generator is tested alone, however when I add it to a procedure like in:
<sapienTech>it doesn't work, since the generator remembers the full stack, and gets stuck in an infinite loop.
<sapienTech>is there a way to keep the generator's saved continuation from remembering its larger context?
<rain1>i don't really understand what it does
<sapienTech>the second procedure?
<sapienTech>the first procedure creates these numbers:
<rain1>oh the lcm
<sapienTech>and the second procedure tests if the generated number's numerator has more digits than the denominator, solving the problem.
<rain1>scheme@(guile-user)> (lcm 1 2 3 4 5 6 7 8 9 10)
<rain1>$3 = 2520
<sapienTech>I know how to solve this problem using straightforward recursion, but wanted to try it with continuations
<rain1>it looks like a bad problem to apply continuations to
<sapienTech>i couldn't figure out how to create a generator that doesn't use continuations
<cojy> <sapienTech> is there a way to keep the generator's saved continuation from remembering its larger context?
<cojy>this is the poiont of delimited continuations
<sapienTech>cojy: very glad you said this :)
<rain1>(define generator (let ((v 1)) (lambda () (set! v (+ 2 (/ 1 v))) (+ 1 v))))
<rain1>try this out
<sapienTech>okay cool one sec
<cojy>continuations are really only needed for when it's some really complex thing that you cant make into a stream like that
<rain1>oh now im starting to see how you wanted to apply continuations there!
<sapienTech>yeah rain for sure!
<sapienTech>i thought it would actually be a decent use of it
<rain1>its so you cand write (+ 1 (let loop () (+ 2 (/ 1 (loop)))))
<rain1>to be the infinite expression
<sapienTech>yeah, but stops after each application
<rain1>1 + 1/(2 + 1/(2 + 1/(2 + 1/...)))
<rain1>then you can 'continuationize' it - that's a cool idea
<sapienTech>its like recursively building up itself
<rain1>you could use a choice operator
<rain1>(+ 1 (let loop () (+ 2 (/ 1 (CHOICE 1 (loop))))))
<rain1>basically AMB from the book
<sapienTech>rain1: are choice operators talked about in the guile manual?
<rain1>no idont think so
<sapienTech>whats the book? SICP?
<sapienTech>cojy: what i was doing wasn't a delimted continuation though right?
<sapienTech>thanks rain1
<sapienTech>cojy: okay, so looking in the guile manual, it says that using prompts are delimited because it is not the whole continuation of the program, just the computation initiated by call-with-prompt
<sapienTech>sounds exactly like my issue :)
<rain1>yeah it would be a god exercise to redo amb but using delimited conts. it will come out a lot nicer and simpler
<paroneayea>heya sapienTech !
<paroneayea>sapienTech: and are worth reading
<paroneayea>once you get into prompt / delimited continuation territory.
<paroneayea>happy hacking!
<sapienTech>rain1: looking over the code you sent me, and im just checking that this process would not yield the right solution?
<sapienTech>i tried something similar early on, but the problem is that I can't store a value, i have to store a contination to the recursive function, right?
<sapienTech>anyway, got to run, but thanks a lot rain1 paroneayea and cojy!
<paroneayea>I found quite the bug in goops in guile 2.2
<paroneayea>now let's see if I can fix it
<paroneayea>wingo: just reported a bug to bug-guile which makes GOOPS basically unusable in guile 2.2
<paroneayea>it will never finish
<paroneayea>recurses forever
<akkad>is full guile available in gnu make?
<paroneayea>wingo: btw, my paste was wrong, follow up to has the right thing though
<paroneayea> there
<janneke>morning guile!
<lloda>tail calls are great, but debugging is important. I have to work around this often by forcing tail calls not to be, so that I can follow what is going on. Something like that MIT/GNU Scheme strategy would be really really helpful. ,trace is no good because you can't set a depth so it prints way too much stuff.
<wleslie>you could create a notail macro that did some kind of (let ((x (...))) #f x)
<df_>it'd be nice not to have to modify the code to debug it though
<wingo>lloda: we could improve ,trace of course
<df_>that said personally I do that a lot anyway, adding peek calls etc
<wingo>,trace is implemented in scheme, it can keep a shadow stack without any problem
<wingo>ACTION finally working on ports in scheme....
<xieyuheng>will guile support r7rs ?
<random-nick>someone is working on it on a separate branch
<random-nick>they said it is mostly done but it is lacking some thing
<xieyuheng>I see a lot of wip-* in branch list
<wleslie>that's often what happens when a problem comes along
<xieyuheng>on branch r7rs-wip it says ::
<xieyuheng>2013-12-21 02:56 Mark H Weaver : Support R7RS.
<xieyuheng>last commit on that branch is from 2014-01-12
<xieyuheng>define-library can co-exist with define-module ?
<jmd>Can someone give me a simple example of how to use with-throw-handler?
<jmd>The example in the manual is _not_ simple.
<df_>what do you want to do with it? I can give you a trivial example but I'm not sure how helpful it'll be
<jmd>Thanks. Firstly suppose I don't know what type the exception is. I want to handle absolutely all exceptions?
<random-nick>jmd: yes, with #t
<random-nick>jmd: change the first 'foo into a #t
<random-nick>that will make it catch all exceptions
<jmd>Only the first 'foo?
<df_>the second one is just an example throw
<df_>it would be replaced with the actual body of code you want to execute
<random-nick>the first argument is what exception(s) to catch (if it is #t it catches all of them), the second argument is the procedure that throws the exception and the third argument is the handler procedure
<jmd>Ok. I'll try something on based on your example. Thanks.
<random-nick>in a syntax-case macro, if I get my syntax object that contains the macro arguments, and it is a list of things, how can I split that list into individual syntax objects?
<roelj>Is there an existing module that allows me to compute the SHA-256 checksum of a file in Guile?
<random-nick>guile doesn't have a GIL, right?
<taylan>random-nick: nope
<taylan>random-nick: assuming you mean Global Interpreter Lock
<random-nick>yes, global interpreter lock
<jmd>How do I represent the newline char in guile?
<janneke>try: (string->list "\\n")
<daviid>jmd: special [non-printing] chars are listed here 6.6.3 Characters
<random-nick>in a syntax-case macro, if I get my syntax object that contains the macro arguments, and it is a list of things, how can I split that list into individual syntax objects?
<daviid>OT: April the 14th, I sent a GNU Foliot 0.9.6-beta released email which made it to guile-user [], guile-gtk-general but never made it to info-gnu: I wonder why and if I should resend it?
<paroneayea>daviid: I had a similar issue recently with 8sync
<paroneayea>it didn't go through, so a week later I resent it
<paroneayea>and then it went through
<paroneayea>I'd resend itl.
<daviid>paroneayea: ok will send it again thanks!
<stis>paroneayea: was it you who submitted the recent bug report?
<paroneayea>stis: the GOOPS one?
<paroneayea>stis: oh the 8sync website repo one?
<paroneayea>ACTION not sure what bug you mean :)
<paroneayea>stis: yes I sent that
<stis>I think that the cache is shrinking so the finding is not it.
<stis>basically : match cache ((_ . cache) .... (refo with cache)
<stis>the name is the same but cache is rebounded
<stis>so it does shrink. The bug is probably somewhere else
<paroneayea>stis: I tried doing a (pk 'cache cache)
<paroneayea>and guess what
<paroneayea>it kept doing
<paroneayea>it kept printing a recursive structure
<paroneayea>and didn't stop, I think
<paroneayea>so I'm guessing the cache somehow has itself embedded in it
<paroneayea>or iirc that's what happened
<stis>hah teh setup of cache is broken. e.g. a self referencing list
<paroneayea>yeah that's my *guess*
<stis>so the error is where it is cinstructed
<paroneayea>but anyway, I'm quite certain that's where the error is: I had the truncated backtrace
<paroneayea>I had to cancel the backtrace
<paroneayea>because it had printed like 5k lines of that same repeated recursive call
<paroneayea>so yes, I'm pretty sure that's where it's broken
<paroneayea>unless that method *should* be recursing 5k times in a single operation
<paroneayea>in which case we have another problem :)
<stis>well if you setup the cache list as a self reffering list you get that behavior. But the error is not in that code but where the cache where constructed
<paroneayea>stis: yes that's probably true
<paroneayea>it's probably a self referencing list, so not that code that's broken
<paroneayea>but whatever is building the cache
<paroneayea>curiously if you saw my follow-up my first example was wrong (I tried to pair it down before sending to the list)
<paroneayea>it requires that you try sending an srfi-9 structure into define-method
<paroneayea>not just an integer or whateer
<paroneayea>so maybe it has something to do with the GOOPS and records compatibility tooling
<stis>paroneayea: ahh you are right it is a recursive call. my miss
<paroneayea>stis: I could be right or wrong about it being a aself referencing list
<paroneayea>but it's definitely recursing infinitely there, as in terms of the behavior
<stis>it looks like the only construction of the cache is in am idiom of the type
<stis>(slot-set gf 'a (acons k v (slot-ref gf 'a)))
<stis>I bet that slot-ref is returning the place-holder and not the value
<stis>why that is triggered by record is beond me though
<Marex>Hi, can anyone please take a look at ? It's a minor addition and would be nice to get this applied
<daviid>ACTION hopes wingo gives some love, asap, to goops on master, fix 20093 [then I can start to use/test master too], then 19770 and 20423, while he will look at paroneayea reported 23404, so guile-2.2 becomes both a performance and goops paradise
<janneke>ACTION has been using master as a goops paradise for over a year ;-)
<janneke>but i never use slot-set and also ditched most generics
<daviid>janneke: that is because you don't merge generics [which is the best we have to make goops actually working 'like' clos, so absolutely essential], you don't use setter inheritance and slot option inheritance
<daviid>janneke: so you don't use goops :)
<janneke>i sure do use slot option inheritance
<janneke>one of the reasons goops looks so much friendlier than records
<daviid>janneke: slot option inheritance is broken, so not sure what you use
<janneke>but yes, i use goops as a nicer way to specify immutable records :-)
<daviid>janneke: see 20423
<janneke>ah, sorry
<janneke>i'm using inheritance, inherited slots; not slot-option inheritance
<janneke>i don't even know what the double-list form means in
<janneke>(define-class <maths-teacher> (<teacher>)
<janneke> ((subject :init-form "Mathematics")))
<janneke>`((subject' ...
<daviid>janneke: slots are inherited, what is broken is the slot being redefined at subclass, for 1 or more options, see the bug report
<daviid>janneke: that is an Stklos example, as the title says...
<janneke>yes, i'm not using that
<daviid>surely not :)
<daviid>neither merge generics neitjer setter inheritance :)
<janneke>i used to, but didn't like it
<daviid>janneke: i won't start that kind of discussion
<daviid>that discussion does not interest me: i'm concerned that goops is unusable on master, till the 1st of these 3 serious bugs are fixed, and I just hope wingo will find paroneayea's goops related bug report an incentive to spend some time n it
<stis>paroneayea: cache is recursive by design you will always get stalled printouts although it is not an error
<janneke>i have no intention to start a discussion
<janneke>i can see there are serious bugs
<stis>looks like there is a recursion that grows the cahce
<janneke>and i'm sorry if they are blocking you
<random-nick>if I have a syntax object which represents a list of lists, if I use syntax->datum on it and then use datum->syntax on ever list of that list, will that preserve the hygiene of the elements?
<jmd>How can I make one object owned by another?
<mark_weaver>jmd: what does it mean to "own" an object?
<jmd>I don't want object A to be collected before object B
<rain1>because scheme is garbage collected you never have to worry about that
<jmd>rain1: On the contrary. Because scheme is garbage collected, it can be a very serious concern.
<mark_weaver>jmd: you can arrange that by having object B include a reference to object A, no?
<rain1>um ok
<jmd>mark_weaver: That's what I want to do. Yes.
<jmd>Is there a genereci way to make B reference A ?
<mark_weaver>by adding a field to B?
<jmd>(+ A B)
<cojy>jmd: it's done automatically, because it's garbage collected
<mark_weaver>or if that's inconvenient, I suppose you could use weak-key hash tables
<random-nick>aren't weak-key hashtables called so because they allow garbage collection?
<mark_weaver>or use object-properties, which are implemented in terms of weak-key hash tables
<jmd>cojy: Right. How can I stop that automatically happening?
<cojy>jmd: stop doing what? collecting or not collecting
<cojy>the garbage colelctor wont colelct anything that has a reference to it
<cojy>you don't need to do anything special
<jmd>cojy: Then it appears that there is no reference. How do I add one?
<cojy>can you give an example of where you are having a problem?
<cojy>you would have to be doing something tricky to have an issue with this in the first place
<cojy>the solution would depend on that tricky thing
<jmd> (let* ((outer (newwin h w sy sx))
<jmd> outer)
<jmd>inner may be collected before outer. But it ought not to be.
<jmd>Is that so tricky?
<jmd>The only "solution" I have found is to use (set! xx inner)
<jmd>where xx is global.
<jmd>But of course then I need an xx for every instance of that function.
<cojy>yes this is very tricky it looks like you are calling out to some other library with some tricky state
<cojy>it's really bad design for it to cause you an error if you don't control how things get gc'd yourself
<cojy>i'd have to see what newwin and derwin are
<cojy>if you actually are getting errors form this you probably want to either rewrite what is under, or wrap it with an interface that always puts these windows some table or list somewhere
***jyc_ is now known as jyc
<rain1>hate to say it but the guile-ncurses library is fundamentally broken
<mark_weaver>jmd: did you see my suggestion about weak-key hash tables and/or object-properties?
<rain1>search for the term 'garbage' in the docs
<mark_weaver>jmd: see 'make-object-property' in the guile manual
<cojy>yea jmd it looks like the library is realy broken ^
<cojy>i would wrap any window/etc. creation functions with your own that adds it to a table that you can delete manually later
<cojy>it's like having an sdl library that erases the shapes you drew on the screen every time the garbage collector runs
<jmd>What good can that do?
<mark_weaver>well, you need to keep the result of (make-object-property) alive by keeping a reference to it.
<mark_weaver>and that result actually contains a weak-key hash table.
<mark_weaver>(define my-hidden-field (make-object-property))
<mark_weaver>(set! (my-hidden-field win) inner)
<ft>rain1: What's broken about it, if I may ask. Haven't looked very closely yet, but was planning to use it.
<mark_weaver>now the weak-key hash table stored within 'my-hidden-field' has an entry with key 'win' and value 'inner'.
<rain1>ft: it puts effects into garbage collection callbacks
<mark_weaver>as long as 'win' is alive, the entry will be retained
<mark_weaver>and that will keep 'inner' alive.
<ft>rain1: Hum. What would it do that for?
<rain1>it's trying to make things easier for the library-user, but it actually causes an abstraction leak and forces one to do harder work
<cojy>giving a job to the garbage collector which it doesn't belogn attempting to do
<cojy>we open and close file ports ourselves, this should be done in the same way
<jmd>Is there a way I can make the gc a lot more aggressive, so I can test this stuff?
<mark_weaver>jmd: you can call (gc) to force a garbage collection
<jmd>How do I set more than one property on an object?
<mark_weaver>jmd: (define my-hidden-field-2 (make-object-property))
<mark_weaver>every time you call 'make-object-property', it makes a fresh property
<jmd>1. Then why why do I need a -2 version ?
<random-nick>jmd: because they are 2 variables?
<mark_weaver>jmd: just assign it to a different name
<mark_weaver>it doesn't have to have the names I gave
<mark_weaver>(make-object-property) returns a procedure that holds a reference to a private hash table.
<mark_weaver>both hash tables need to be kept alive
<mark_weaver>and both object properties need to be accessible so that you can set the properties
<rain1>ft: having looked at the code I would say that it would be better to make a new guile ncurses binding than use it
<mark_weaver>if the object property (hash table) is reclaimed by the garbage collector, then it will no longer be able to keep anything else alive by its references
<rain1>even if we fix the problem it is still 12597 lines of code, that isn't reasonable
<random-nick>why does guile-gnome-platform depend on a version of guile-cairo that hasn't been released yet since 2011?
<ft>rain1: Do you think it's possible to drive ncurses via the ffi?
<jmd>mark_weaver: So if my call to (set! (my-hidden-field-1 inner) win) is in a procedure, I cannot call that procedure more than once?
<rain1>sort of - you will need some C bits because ncurses is ancient and defines various things as macros instead of normal C functions
<ft>Ah yes. Annoying.
<rain1>yep but iit wont be too bad
<mark_weaver>jmd: you can call it more than once, but when you call (set! (my-hidden-field-1 inner) win) on 'inner' the second time, it will overwrite whatever what already in that object property for 'inner'.
<mark_weaver>think of 'make-object-property' as adding a new field to every heap-allocated object
<ft>rain1: Yeah, in guile-termios I got a scheme script that generates a C program that gets compiled and generates yet another scheme file that's a module containing all that macro stuff.
<rain1>hehe wanna se something fun
<rain1> /* This is going to break something */
<rain1> delwin (win);
<rain1>^ this is in gc handler that is breaking the code above
<mark_weaver>(define my-hidden-field (make-object-property))
<ft>rain1: Our definitions of "fun" seem to differ. :)
<mark_weaver>now I can call (my-hidden-field obj) on any object to retrieve that field, or (set! (my-hidden-field obj) <value>) to set the field.
<jmarcian`>what is in guile variable of current script?
<rain1>ft - that sounds neat! what does it generate both of them from?
<mark_weaver>jmd: 'make-object-property' is defined in ice-9/boot-9.scm. it is very short. hopefully looking at its code will clear up any confusion you have.
<mark_weaver>jmd: I don't have time to continue to explain right now, sorry.
<jmd>ok. Thanks for your help.
<ft>rain1: It's much more predestrian than it sounds. :) The first program just directly outputs some C that would be very repretitive to write, containing tons of #ifdefs. The C program directly outputs the scheme library from that.
<ft>Would be cool if the ffi had a C parser and peel that out of a header. :)
<random-nick>are C headers restricted to a subset of C or can you have code in the header?
<ft>There is nothing special to the C in a header file.
<random-nick>what if someone is crazy and leaves function definitions in the header?
<random-nick>how would you parse that?
<ft>That's not even that crazy necessarily. short static inline fit will in headers, IMO.
<rain1>here's a fork that removes effects from GC handlers
<random-nick>also that kind of parsing isn't ideal since you don't get the C macros in that header
<ft>Parsing it is not the issue. Giving what you've parsed a meaning is harder. :)
<random-nick>and some people do a lot of things in macros
<ft>Sure, but having access to #defines and structure layout would be better than nothing.