IRC channel logs

2023-12-04.log

back to list of logs

<festerdam>Hi, all.
<festerdam>Is there a way to do some sort of debug print in scheme code? What I normally do, is I create a begin sexp around the sexp that's causing me problems and then (display) all the variables I'm concerned with, but when printing lists it also removes the double quotes around strings, making the indistinguashable from symbols. Is there some way to do a repl-like print in the middle of some code?
<dthompson>festerdam: 'write' will output things using s-exp formatting. but your friend for print debugging is 'pk'
<dthompson>(pk a b c) will print out a, b, and c and return c
<festerdam>dthompson: Thanks!
<dthompson>np
<isaneran>oh, why is pk undocumented
<dthompson>I dunno :)
<dthompson>it's a not-so-secret secret around here
<isaneran>(pk thunder!!)
<isaneran>it does show up in a code example in the manual
<isaneran>about declarative modules
<festerdam>I'm seeing some weird behaviour. Within a nested procedure, there's a (let* (... (entry (map-find color-map c))) ...), however «entry» unexpectedly has the wrong value when I run the code (it's #f), with «pk» I figured out the value of «color-map» and «c», but running (map-find [copy-pasted value of color-map] [copy-pasted value of c]) directly, gives the expected result (not
<festerdam>#f). «map-find» doesn't use macros or functions like «set!», it simply makes a call to srfi-1's «find», so it shouldn't be dealing with any state, which means that with the same inputs it should be giving the same output. What could be things that cause behaviour like this to happen?
<chrislck>show us map-find
<festerdam>chrislck: (define (map-find entries key) (find (lambda (x) (eq? key (car x))) entries))
<chrislck>are the keys symbols?
<festerdam>chrislck: It should be able to work with symbols, but in this case it's strings.
<chrislck>somethen use equal? instead of eq?
<chrislck>*then
<festerdam>chrislck: Thanks! That fixed it. I will look up the difference between them. I had the idead eq? was a shorthand for equal?
<chrislck> https://www.gnu.org/software/guile/manual/html_node/Equality.html
<festerdam>Thanks!
<chrislck>yw
<festerdam>Hi, all!
<festerdam>I just defined a module with define-module. How do I use it now? Doing (use-modules (my-module)) in the same directory doesn't seem to work.
<lloda>the directory needs to be in your %load-path
<isaneran>festerdam: if you run guile like `guile -L . ` it should work
<festerdam>Thanks! However, it still doesn't seem to work. It complains there is no code for the module. This happens with both -L . and (add-to-load-path (dirname (current-filename))).
<festerdam>Can this be cause by an error in the module being imported?
<festerdam>*caused
<festerdam>Ok, -L. doesn't even seem to be adding the current directory to the %load-path, but add-to-load-path does, but use-modules still fails.
<festerdam>I have the module define this way: (define-module (day02-1) ...) and in the same directory I have the file that I'm trying to run that does (add-to-load-path (dirname (current-filename))) followed by (use-modules (day02-1)).
<apteryx>I'm having a build problem with the new SRFIs I added: https://paste.debian.net/1300147/ Branch: https://gitlab.com/Apteryks/guile/-/tree/add-srfi-209?ref_type=heads
<lloda>festerdam: the module file name has to match the module name. So it has to be named 'day02-1.scm'in your case
<lloda>if your module is found but has errors they you should see those errors in the console
<festerdam>lloda: Thanks! That was it. Btw, is there a way to do the equivalent as python's «if __name__ == "__main__"» (ie. only run a portion code if the file is being directly run, rather than being imported)? I noticed doing the «use-modules» runs a procedure call in that file that's only supposed to be called when run directly as a script (I just want to reuse some definitions in that file in another file).
<lloda>festerdam: idk how to do that in Guile. I think you'd want to put the scripty bits in a different file
<isaneran>lloda: https://paste.debian.net/1300159/
<isaneran>not the prettiest solution but I think it'll work
<isaneran>(not sure if there is a prettier way to expand a relative path to absolute
<isaneran> https://paste.debian.net/1300160/
<isaneran>found canonicalize-path
<dthompson>festerdam: check out 'batch-mode?'
<dthompson>wrap the code that should be run when the module is imported with (when (batch-mode?) ...)
<isaneran>oh I meant to tag festerdam
<isaneran>apologies lloda
<isaneran>either way dthompson had a way better solution
<apteryx>hm, the build system doesn't currently enforce inter-modules dependencies, right?
<apteryx>.go files are compiled in the order they are listed in am/bootstrap.am SOURCES variable
<dthompson>right. you just list things in topological order.
<festerdam>dthompson: Let's say I have a script called make-bread.scm which automatically makes you a plain wheat bread for lunch. I also have a script that is called make-breakfast.scm, but my dietitian says I shouldn't eat wheat on breakfast for some reason, so I want to make pumpernickel for breakfast (in addition to some eggs and black tea). I thus want to import the procedures that make bread in the make-bread.scm file, but I don't want to
<festerdam>automatically make wheat flatbread, I just want to reuse the procedures that mix the dough, leaven the dough and that make the oven bake the bread. In python what I would do is the following: I would go to make-bread.scm/py and add «if __name__ == "__main__": mix_dough("wheat"); knead(); rest(86400); shape(); bake(3600); rest(3600)» at the bottom, so that code is only run when I run python3 make_bread.py, but not when I
<festerdam>run python3 make_breakfast.py, which has «import .make_breakfast» at the top, but still provide make_breakfast.py the «bake», «mix_dough», «rest», etc. functions.
<dsmith>festerdam, ISTR there was something like that in the examples dir, but I don't see what I vaguely remember
<dsmith>festerdam, It may have been back when ttn was involved. Not sure if his code is still up anywhere
<dsmith>(ttn passed away about a year ago)
<festerdam>dsmith: May they rest in peace.
<festerdam>I think I figured out a way: (if (equal? (basename (car (command-line))) (basename (current-filename)))
<apteryx>mirai: by the way, I've sent the guild 'snarfi' script if you'd like to try it to snarf SRFI HTML specs into Texinfo