IRC channel logs

2023-03-25.log

back to list of logs

<sneek>wb dsmith :)
<cow_2001>(define-module …) is the guile syntax for (library …), right?
<cow_2001>my sicp solutions file is >3000 lines and i'm breaking it up into individual exercises. i am thoroughly confused about the modules system so i need to read it all
<cow_2001>(most lines are probably pretty printed vertical code layout…)
<flatwhatson>cow_2001: yes define-module is what you want, (define-module (foo bar)) maps to foo/bar.scm on your load-path
<cow_2001>oh!
<flatwhatson>are you using geiser?
<cow_2001>i didn't realise the naming of modules is the naming of directories
<cow_2001>geiser, yes
<flatwhatson>the simplest solution is probably to use geiser's built-in project paths support
<flatwhatson>(setq geiser-repl-per-project-p t)
<flatwhatson>assuming your "project" is a git repository, it should then create a dedicated repl for each project, and add the project root to load-path automatically
<flatwhatson>check %load-path to see if it worked (it should be the first element there)
<flatwhatson>then when you (use-modules (foo bar)) it will search for foo/bar.scm for-each load-path
<cow_2001>%load-path has the project directory! O_O
<cow_2001>i think maybe i should learn rnrs-isms instead of guile-isms first
<flatwhatson>i think you shouldn't worry about it. exactly the same functionality, except guile folks tend to use guile syntax
<cow_2001>so for a solution file name ./guile-1.3.scm will be (use-modules (guile-1.3) …)?
<cow_2001>oh poo. i mixed up between define-module and use-modules
<cow_2001>just a second
<flatwhatson>you can combine them: (define-module (foo bar) #:use-module (bar baz))
<cow_2001>i have guile-1.1.scm (define-module (guile-1.1) #:export (sum-of-squares)) and guile-1.3.scm (define-module (guile-1.3) #:use-modules ((guile-1.1)))
<flatwhatson>it should be (define-module (guile-1.3) #:use-module (guile-1.1))
<flatwhatson>there's no "use-modules" form for define-module, somewhat confusingly
<cow_2001>oh O_O
<cow_2001>THANK YOU
<cow_2001>okay, so now i can run guile-1.1.scm. guile-1.3.scm, which depends on guile-1.1.scm still fails. let's see!
<cow_2001>"no code for module (guile-1.1)" it says
<cow_2001>flatwhatson: the two files https://paste.debian.net/1275213/
<cow_2001>confusion will be my epitaph
<cow_2001>okay, running it with `guile -l guile-1.1.scm guile-1.3.scm` works, but not `guile guile-1.3.scm`
<cow_2001>even with the (add-to-load-path …) inside
<flatwhatson>oh, you are running them outside of geiser
<flatwhatson>tbh, for things like this you should probably just do your coding in the repl and not worry about running separately
<flatwhatson>you can run guile -L /path/to/project or set GUILE_LOAD_PATH environment variable
<flatwhatson>by "in the repl" i mean, in an emacs buffer and C-c C-b to load it into the repl and then call your functions interactively
<cow_2001>flatwhatson: but i would like them to be commandlineish
<cow_2001>put stuff in a makefile kind of stuff
<cow_2001>overengineering!
<flatwhatson>no it's fine, there are uses for that, it's just tedious when hacking on stuff or working through exercises or whatever
<flatwhatson>you're unlikely to be deploying your SICP solutions into production
<cow_2001>i was thinking, i haven't had a good night's sleep, so i will now do tedious work of chopping the huge file into individual exercises files
<flatwhatson>anyway you can set load path with -L or GUILE_LOAD_PATH as mentioned
<cow_2001>yeah. thank you!
<flatwhatson>i often use direnv and put "path_add GUILE_LOAD_PATH ." into .envrc for proper projects
<flatwhatson>and if you're calling guile from makefile steps, put the -L explicitly in the args
<mirai>Is there some procedure to solve this kind of problem ? <https://paste.centos.org/view/11e44592>
<mirai>I'm not even sure what to begin searching for
<flatwhatson>mirai: not sure if one already exists, but this works: https://paste.debian.net/1275223/
<cow_2001>okay, trying to use the rnrs library defining syntax i get this https://paste.debian.net/1275231/
<cow_2001>for some strange reason it works when i use the guile define-module syntax
<cow_2001>okay, i had to (import (scheme base)) and (begin …) everything
<cow_2001>now it works perfectly
<haugh>flatwhatson, mirai: http://vpaste.net/zDyzx
<haugh>Actually flatwhatson's pattern matching solution is both beautiful and annoyingly fast, but I couldn't resist