IRC channel logs
2023-02-10.log
back to list of logs
<vv[m]>I got some weirdness like that before. I think I got use-modules is not a function or something <jfred>Yeah, it wasn't recognizing any functions including the built-ins for some reason. It stopped happening after I fiddled a bit but I don't know what I did that fixed it <flatwhatson>this can happen if you enter a module which doesn't exist <flatwhatson>in the guile repl, entering eg. ",module foo" where there's no foo module defined, puts you into a completely empty environment <flatwhatson>whereas (define-module (foo)) will actually import (guile) implicitly <flatwhatson>this makes more sense if you think about guile as a multi-lingual environment :) <vv[m]>any magic way to rename a function? Trying to see if I can port the magic of selfish-start to guile but not sure how that would work <flatwhatson>vv[m]: what do you mean rename a function? functions are values, and identifiers (names) are bound to values <flatwhatson>so if you have a function (define (bar) ...) you can (define foo bar) and call it with either (foo) or (bar) <vv[m]>I think it's for the debugger so it doesn't have a name ^selfish-start always <flatwhatson>oh, in that case probably using a macro is the cleanest option <vv[m]>wonder if set-procedure-property! would work <flatwhatson>(define (set-procedure-name! proc name) (set-procedure-properties! proc (acons 'name name (procedure-properties proc)))) <vv[m]>I am not sure how to do the passing of the vals/keyword-vals either. hm. I find the documentation on this aspect a bit confusing <vv[m]>would it be (define selfish-spawn #:allow-other-keys #:rest r) ? <vv[m]> * would it be (define (selfish-spawn #:allow-other-keys #:rest r) ... ) ? <flatwhatson>probably can just be (define (selfish-spawn constructor . args) ...) and let the constructor parse its own keyword args <flatwhatson>keyword arguments aren't special in scheme, keywords are basically like symbols. the define* and lambda* forms just wrap the body in a let which finds them in the argument list and binds them <flatwhatson>so (apply my-function-taking-keywords '(#:foo 1 #:bar "two")) works fine <vv[m]>goblins@(gib-gab-gob lib) [3]> (define* (^narcissus bcom self poopy #:key car bike) (format #t "~s ~s ~s ~s ~s" bcom self poopy car bike)) <vv[m]>goblins@(gib-gab-gob lib) [3]> (selfish-spawn ^narcissus "power" #:car "ford" #:bike "peugeot") <vv[m]>#<procedure become (new-behavior #:optional return-val)> #<local-object ^narcissus> ("power" #:car "ford" #:bike "peugeot") #f #f$6 = #<local-object ^narcissus> <vv[m]>hmm may need to unwrap the args one more time, seems they are in a list, but close. <flatwhatson>vv[m]: it looks like you're renaming ^selfish-start, not what it returns <flatwhatson>check the value of ^selfish-start in the repl to see if it's been renamed <vv[m]>yeah it does seem to also change the original function as well, though, if you define multiple actors then they retain the original name they got. But yeah, messy. And also there's something not quite right with the final structure. <vv[m]>I guess if ^selfish-start is simply defined inside, it is less 'scary' <flatwhatson>the code you sent earlier, the last line of ^selfish-starts has: bcom (apply constructor ... <vv[m]>Just had a missing self at the end but otherwise it works, I think! <vv[m]>oh yeah I forgot that I also fixed that. <vv[m]>lovely lovely! thanks for the help and it was cool to learn a bit further <vv[m]>Perhaps I shall make a PR to add this since it is in the Racket version <vv[m]>hooray, I was able to remove duplicated method definitions from an actor with (methods ...) using this ^_^ <jfred>flatwhatson: Oh! Right, I probably entered my module before evaluating its `define-module` expression. And I didn't know `define-module` did that, how neat. That explains it! <jfred>vv[m]: Please do make a PR, I'd like to use it too! :D it's a handy thing to have around <vv[m]>it's annoying that the pipelines fail and make a big red unless you give them your CC info