IRC channel logs


back to list of logs

<laertus>is there an r5rs equivalent of "format" (ie. a function that does string interpolation) ?
<laertus>or.. how does one do string interpolation in guile?
<leoprikler>laertus: you mean stuff like "Hello, {world}\n", where {world} takes a value, e.g. Earth?
<leoprikler>my guess would be ice-9 regex
<leoprikler>(alternatively peg)
<laertus>wow.. that seems a bit low-level
<leoprikler>well it is
<leoprikler>there also is SRFI-48, but since guile has its own format, I guess you won't find that here
<leoprikler>if you already have string-typed variables, you can also use string-append
<laertus>yeah, string-append seems easiest
<laertus>but it's not really string interpolation per se
<leoprikler>hmm, let's see some more SRFIs
<laertus>is there a list somewhere of all ice-9 modules and what they do?
<leoprikler>Kawa seems to have SRFI-109, but that also has a lot of other baggage
<leoprikler>you can list directory trees with ice-9 ftw
<leoprikler>"what they do"… perhaps extract the commentary?
<dsmith>"Output the fragments to the current output port.
<dsmith>The fragments are a list of strings, characters, numbers, thunks, #f, #t – and other fragments. The function traverses the tree depth-first, writes out strings and characters, executes thunks, and ignores #f and '()."
<dsmith>That's kind of schemey interpolation
<dsmith>laertus: ^^
<laertus>how would i actually use that?
<dsmith>laertus: Pass it lists and strings and thunks and stuff. Never used it but seems useful.
<dsmith>laertus: Also format in (ice-9 format) Pretty much the same as Common Lisp format. (it's like printf)
<laertus>ahh... there we go
<laertus>that's probably what i want
<laertus>thank you
<dsmith>Does *all* *kinds* of stuff.
<dsmith>Roman nummerals!
<laertus>nice :)
<laertus>time to convert all my program's output to roman numerals...
<dsmith>laertus: About srv:send-reply
<laertus>thanks, but i think ice-9 format looks like more what i had in mind
<dsmith>Ya. It's for when you want to control spaceing, number of decimals, leading +, etc.
<dsmith>Different bases.
<laertus>i've been testing out using guile from gnu make...
<laertus>and when i do $(guile (load "foo.scm")) it works, but make spits out annoying messages about compilation
<laertus>like: "note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0 or pass the --no-auto-compile argument to disable."
<laertus>well, i guess i can try "GUILE_AUTO_COMPILE=0 make"
<laertus>but say i do want to have guile do the compile, but just not tell me about it, in this particular case?
<laertus>anyway, "GUILE_AUTO_COMPILE=0 make" doesn't seem to work
<laertus>even when i don't modify my "foo.scm" file, make keeps warning me "note: source file foo.scm newer than compiled foo.scm.go"
<dsmith>Yeah, that's annoying.
<laertus>i must say that it's really nice to be able to use guile from make, though
<laertus>i've been bashing my head against its obtuse and convoluted syntax all day
<laertus>it'll be such a relief to use a sane language for a change
<apteryx>hello! how can I round a decimal number to the first digit, e.g.: 1.3234343 -> 1.3 ?
<apteryx>I need to use format?
<apteryx>this seems to do it: (format #f "~,1f" 1.32) -> 1.3
<laertus>does guile have something like emacs' #' operator, which in emacs is used to prefix quoted functions, like #'foo ?
<leoprikler>guile does not have quoted functions
<leoprikler>but it does have #:keywords
<laertus>so how do you pass a function to map?
<leoprikler>by variable
<leoprikler>(map fn list)
<laertus>ok, so you just don't quote it
<laertus>in that case, still, i'd expect it'd be useful to differentiate between any old variable and one which contains a function
<laertus>which is what #' vs ' in elisp do
<leoprikler>guile doesn't have function slots
<leoprikler>you can check, whether something is a procedure using procedure?
<leoprikler>but i'd advice against making that into a reader syntax like e.g. #p(fun)
<laertus>i guess for me the use of something like #'foo would be more a visual hint for the human reading the source that the intent here is that this thing is a function
<laertus>kind of like using $foo for variables
<leoprikler>if that really is important to you, try (define (ensure-procedure x) (if (procedure? x) x (error ...)))
<leoprikler>of course you can make up your own conventions for procedure and variable names within your library
<leoprikler>but hungarian notation is typically not adored by many
<laertus>it's not full hungarian notation
<laertus>but, yeah, it's a matter of taste
<laertus>i've personally found it useful to instantly see the intent of the programmer with sigils like #'foo, $foo, or @foo
<leoprikler>yeah, but that can get cluttered
<leoprikler>what would you do e.g. if you found (($mapper) $proc $list)?
<laertus>there are always tradeoffs
<laertus>you could have "clean" looking code, with no indication of what type something is, but then it's more error-prone
***sneek_ is now known as sneek
***apteryx is now known as Guest68452
***apteryx_ is now known as apteryx
<dsmith>laertus: Guile/Scheme is a lisp-1, emacs lisp (and common lisp) is a lisp-2. one namespace or two namespaces.
<dsmith>in a lisp-2, a binding has a variable slot and a function slot. You access them differently
<dsmith>In a lisp-1, it's just a variable.
<dsmith>In scheme you can do ((if flag + *) 3 4) is 7 or 12 depending on flag.
<dsmith>laertus: Guile *does* have a #' but it's used in macros.
<laertus>dsmith: thanks for clearing that up
<leoprikler>is there a way of programmatically setting the duplicate handlers of a module?
<leoprikler>i know, that (define-module ...) has some syntax around that, but I need to get to the nitty gritty of how that's implemented, because I can't define-module in that place
<leoprikler>nvm i'm stupid and fail at typing
<laertus>why does (simple-format #f "~S/~S" "foo" "bar") eval to "\"foo\"/\"bar\"" and not to "foo/bar" ?
<laertus>simpler test case: i expect (simple-format #f "~S" "foo") to "foo" but it instead evals to "\"foo\""
<laertus>ice-9 format behaves pretty much the same way
<d4ryus>laertus: You are looking for ~a, which outputs its argument like display. ~S will output them like write, this is handy if you want to read them back. Also note that ~a will prevent you from distinguishing symbols from strings.
<laertus>because of this, it doesn't seem like either can be used for string interpolation like i wanted
<laertus>ah... ok
<d4ryus>e.g. (format #f "symbol: ~a string: ~a" 'test "test") => "symbol: test string: test" while ~S would return "symbol: test string: \"test\"".
*laertus nods
<laertus>thanks, makes sense
<laertus>another question: does guile have something like flatten?
<str1ngs>leoprikler: (default-duplicate-binding-handler '(merge-generics replace warn-override-core warn last)) assuming you are using this in a none module? also you may not need merge-generics if you do not use goops
<leoprikler>there are some flatten procedures (e.g. context-flatten from (ice-9 peg)) but afaik no "flatten"
<str1ngs>leoprikler: has more does on default-duplicate-binding-handler. just kinda have to read the fine print
<laertus>what about some way to append one list on to the end of another?
<leoprikler>(append (list 'a 'b 'c) (list 'd 'e 'f))
<laertus>thank you
<leoprikler>str1ngs: I prefer the direct setter, but I just typo'd myself
<str1ngs>leoprikler: I think that should work too.
<laertus>is there a way to join a list of strings in to one string delimited by a user-supplied delimiter?
<laertus>thank you
<laertus>does guile have something like system* but which returns the stdout of the process back to guile?
<dsmith>laertus: ya. can't remember the name right now. is in the piping module
<laertus>ok, ok, thanks
<laertus>open-pipe, maybe
<laertus>thank you
<laertus>does guile have a function like "nth", which evals to a certain element of a list?
<laertus>nevermind.. found it... (list-ref '(a b c d) 3)
***jonsger1 is now known as jonsger
***sneek_ is now known as sneek