IRC channel logs
2023-03-25.log
back to list of logs
<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>i didn't realise the naming of modules is the naming of directories <flatwhatson>the simplest solution is probably to use geiser's built-in project paths support <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 <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>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>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>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 <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 <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>I'm not even sure what to begin searching for <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 <haugh>Actually flatwhatson's pattern matching solution is both beautiful and annoyingly fast, but I couldn't resist