IRC channel logs
2025-03-19.log
back to list of logs
<lloda>doesn't guile build with -Wall? hmm <__monty__>I have a number as a string and I want to extract the integer part, up to the first `.`. Is there a better way than combining `string-index` and `substring`? <ray1729>I was going to suggest that, but I think your first idea will be more efficient. <__monty__>Afterwards I'll want to use the parts in further strings is `simple-format` more efficient/idiomatic than `string-append`? <ray1729>I'm not familiar with `simple-format`, but looking at the docs it expects to write to a port, so you'll have to do some work to write to a string port. <ray1729>Yes, `format` would also do the trick, but it depends whether or not you need any of its features. There will be an overhead in parsing the format string, so for simple cases `string-append` will be better. <__monty__>What's the most idiomatic way to create a list? SICP tends to use `cons` and `list` but maybe quoting is more idiomatic? <ray1729>Any of the above :-) I tend to use `(list)` or quote or quasiquote depending on the circumstances. I'd use `cons` to build a list in a recursive function, or to prepend to an existing list, but not to build a literal list. <__monty__>I'm trying to wrap `use-modules` in a function but getting this error, `source expression failed to match any pattern in form use-modules`. Is use-modules not something I can call from a function? <dthompson>use 'use-modules' is syntax and you shouldn't use it expect from the top-level <__monty__>So what I'm trying to do is impossible? Or is there an alternative way to get the desired result, like macros? <lloda>you can put your function in its own module <dthompson>you can probably use the module introspection system to achieve what you want, but I think it's likely that you should rethink what you're doing <__monty__>Have a bunch of SICP chapter directories with exercise files in them. Instead of `(use-modules (#{Chapter 2}# #{exercise 2.13.scm}#))` I'd like to write `(use-exercises "2.13")`. <dthompson>you want 'use-exercises' to expand to a 'use-modules' form <__monty__>Can `use-modules` be applied to a list of "specs"? `(apply use-modules ((module one) (module two)))` <__monty__>I can't figure out how to take a variable number of arguments, process each of those arguments and then pass that to `use-modules` as a variable number of arguments. It feels like the problem is that last part but maybe my approach is already wrong to begin with. <graywolf>__monty__: Maybe module-use! would work for you <graywolf>Yes, it make a new module, but loads into it additional modules use requests, which (the loading part) sound like the thing you want. <lloda>__monty__: use-modules isn't a function. You can't use apply on it. You need a macro like dthompson wrote <__monty__>lloda: Yes, I've understood that part. The part I'm stuck on is how to process the arguments to the macro, turning them from strings into lists of symbols, and then passing those to `use-modules`. <graywolf>I am not sure why you need to use use-modules though... <__monty__>I am not set on using `use-modules` but it's the only way I understand to import modules. I don't understand `module-use!` enough to use it. <dthompson>__monty__: given the transformation you are trying to do, you'll need to use the more advanced macro system of syntax-case rather than syntax-rules <dthompson>this is because you are converting string constants to symbols at compile time, so you need a procedural macro system to do it <__monty__>dthompson: OK. My problem remains operating on the arguments and then passing them as arguments rather than a list. This is what I was originally trying to use `apply` for. <__monty__>In my head the macro is as simple as "replace use-exercises with use-modules and map over each of the arguments with the arg->spec procedure." <__monty__>But I can't operate on a variable number of arguments without capturing them in a list. <dthompson>__monty__: you need a macro that captures many arguments using a pattern like (use-exercises . names) or (use-exercises names ...) <dsmith>ray1729, for both format and simple-format, using #f as the port returns a string <dsmith>Typically in a macro with a variable number of arguments, you handle one and then recurse on the rest. <__monty__>dthompson: Capturing them is no issue. The problem is I then have a list, and I can't pass a list to `use-modules`, that's why I was trying to use `apply`. <__monty__>dsmith: Turning the `(use-exercises "1.1" "2.3")` into `(use-modules (arg->symbols "1.1"))(use-exercises <cdr of the args>)`? <dsmith>__monty__, Yeah, probably something like that. <dthompson>__monty__: hmm I don't think we're understanding each other. you are writing a macro, yes? <__monty__>What I *think* I want is for `(use-exercises "1.1" "2.34")` to be turned into `(use-modules (#{Chapter 1}# #{exercise 1.1.scm}#) (#{Chapter 2}# #{exercise 2.34.scm}#))`. <dthompson>file extensions are not included in module names <dthompson>leaving aside the string->symbol conversion issue, this is otherwise a very simple pattern <__monty__>dthompson: I have to include them because of the `.`. Guile won't try to append `.scm` if the last symbol includes a `.`. <dthompson>okay, odd. that's a detail I didn't know about. <dthompson>I should say that what you are doing is *very strange* for guile modulse <dthompson>like I could write a macro that makes this work, but I'd first try to do something else <dthompson>it seems you are having several overlapping problems all at once <dthompson>but the basic question of patterns is a simple one. I don't understand why you bringing up lists. <dthompson>if we *really* simplify things for a moment, you have a pattern like (use-exercises name ...) that should expand to something like (use-modules (name) ...) <dthompson>there's no list, no apply, you are just using a pattern variable in your macro <__monty__>dthompson: The problem doesn't arise until you want to feed all of the arguments through another function. Feel free to use `f` for brevity if you want. <__monty__>Or are you saying each of the arguments captured by `...` will be treated the same as `name` in the template? So expanding `(use-exercises name1 name2)` would give `(use-modules (name1) (name2))`? <__monty__>And instead of `(name)` I should be able to use `(f name)`? <__monty__>My function that transform `"2.2"` to `(#{Chapter 2}# #{exercise 2.2.scm}#)`. <__monty__>What you're saying does solve the problem of "mapping over the list of arguments" but I'm still having a hard time understanding the error message, `source expression failed to match any pattern in form ((exercise-nr->symbols "2.7") (exercise-nr->symbols "2.12"))`. The template for my `syntax-case` is `#'(use-modules (f exercises) ...)` so why does the error message mention the list `((f exercises) ...)`? <dsmith>__monty__, So you want (use-execercies "1.1" "2.3") to be replaced by (use-modules (#{Chapter 1}# #{excercise 1.1scm}#) (#{Chapter 2}# #{}excercise 2.3scm}#)) <__monty__>dsmith: Yes, barring the typos in that last symbol. <dsmith>Ya, forgive my poor keyboarding skills... <__monty__>Well, more accurately I want the former to behave like the latter, if this means not using `use-modules` for example, that's fine. <dthompson>__monty__: you can't call a function there. use-modules is syntax. <ray1729>dsmith: thank you for the tip, I knew about #f for format but didn't realise you could do the same thing with simple-format. <dthompson>__monty__: this is why I mentioned syntax-case earlier. if you really want things to work exactly this way, you need a procedural macro. <__monty__>dthompson: But weren't we using a procedural macro so that I could call functions? I also added `(eval-when (expand) <my-f>)` to make that function available during macro expansion. <dthompson>there are many things beind mixed together and confused here. I suggest you simplify and iterate from there. <__monty__>I am using `syntax-case`. I somewhat suspect I need some sort of antiquotation to get out of the `#'` syntax form, to apply the function and quote its result again. <dthompson>okay, that's something I can work with. you need to use either quasisyntax #` or with-syntax <dthompson>and you need to use syntax->datum to extract the strings from your captured syntax objects <dthompson>in which case, you will now have a list to work with that you can call 'map' on. it wasn't clear before that you were using syntax-case at all. <dthompson>__monty__: quick notes: move the helper procedures into the lambda within define-syntax. use with-syntax to bind a new syntax pattern that is the result of mapping over (syntax->datum #'(exercises ...)). <rlb>Different (nicer) variant could avoid the need for the begin, etc., and do it all in one use-modules, but this was a quick hack... <rlb>And of course you wouldn't want/need *read*, etc. <rlb>I've not used with-exception-handler much yet -- I was trying to use it to catch a system-error and "do something else", but it seems like maybe you can't without capturing a continuation in advance? i.e. it's "non-continuable"? <dthompson>yeah most (all?) exceptions raised by guile are non-continuable <rlb>That seems odd wrt normal exception handling practices elsewhere, i.e. I want to *handle* the error. <rlb>I got an ENOENT, and that's fine. <dthompson>outside of common lisp I don't know of another language with continuable exceptions <rlb>I think I knew the answer and forgot I just needed to set #:unwind? #t. <dthompson>oh, yeah if you just want to handle it and abort to the with-exception-handler call then #:unwind? #t is what you want :) <rlb>...yep - I knew (had known) that, just forgot (needed it any number of places in lokke). In any case, thanks much. <dthompson>I wish #:unwind? #t was the default. it's almost always what I want. <rlb>yeah - that and I'm still not used to having the options at the end :) <old>Funny thing, throw an exception in a args-fold callback if the top exception handler has not #:unwind? #t, then the process segfault <old>well it depends where the exception is been thrown, it's weird <old>but ya, #:unwind? #f is not a good default <dthompson>I wonder if that crash has to do with scheme/c re-entrancy or something <old>good lord srfi-37 is riddle with set! <__monty__>So, trying `with-syntax` first because all the various types of quoting in rlb's paste are a bit intimidating. I thought I'd be able to use the pattern variable and do `(symbols (datum->syntax x (my-f (syntax->datum pattern-variable))))` but that errors so I'm clearly not understanding how to get what was bound to the pattern back into a context where I can apply a function to it. <RavenJoad>Is it possible to prevent Guile from truncating backtrace strings? On Guix there are often long strings that get cut-off in the backtrace, which makes it difficult to debug. <daviid>RavenJoad: ,bt #:width 1000 [#:full? #t] <RavenJoad>Is there a way to configure that ahead of time though?