IRC channel logs


back to list of logs

<gnoo>hello, while using guix shell --check, i get the following warning: guix shell: warning: variable 'PKG_CONFIG_PATH' is missing from shell environment
<gnoo>it suggests to look at ~/.bashrc and ~/.bash_profile but i haven't changed PKG_CONFIG_PATH in them
<gnoo>my ~/.bashrc is jut 4 lines, one sets PS1, one aliases `ls', one checks if ti is interactive and the last one sources ~/.alias
<gnoo>~/.alias has only functions so it's not the issue either
<gnoo>oops, should have been guix instead :P
<tohoyn>daviid: I ran the type error snippet in debian unstable. It reported the same error but with different call to gtk-frame-new.
<tohoyn>daviid: in unstable the error is generated in procedure run-panes-demo when frame1 is created.
<tohoyn>daviid: I sent you an improved version of the type error demo. It interrupts the program with a backtrace if there is an error in procedure call to gtk-frame-set-child.
<Zelphir>Hi! I have a question about "style" in Guile programming. I sometimes find myself in the situation, where I want to do something, when a variable has a value and nothing, when it has a specific other value, which is for example not #f. Lets say it is a number. It might be #f, if some previous step failed or perhaps, if that number is not relevant in one case.
<Zelphir>I could use (when ...) to only do something, when the value of the variable fulfills my condition. But it feels somewhat like "bad style" to use (when ...) to me, as I am not explicitly saying, what to do, when the condition is not true.
<Zelphir>Is there objectively anything bad about using (when ...) compared to using (if ...), which always has both cases, the "then-case" and the "else-case"?
<Zelphir>Sometimes I can circumvent using (when ...). For example, when I am creating a string. I could use an (if ...) which writes an empty string to a port inside (call-with-output-string ...).
<Zelphir>Here is one example situation: I have a struct, which has some fields. Most of the fields can be a number or #f, only 1 field is mandatory, some id. I want to serialize the struct into a string, which I will use elsewhere in the program. The attributes need to be serialized in a specific order. I can assume that the id field exists, but cannot assume, that the other fields exist. So I would need to go (when (get-attribute-blah my-struct)
<Zelphir>(simple-format string-port ...)), but I could also use (if ...) and output the empty string to the port, in case the attribute is #f.
<lilyp>Zelphir: (when ) for side-effects is good, actually
<lilyp>if you need control over the return value, you can use (and ), which returns #f in the else case
<lilyp>the case you quote here has two possible implementations
<lilyp>if you process each key-value pair on its own and one of them fails, you'll have garbled output
<lilyp>if you don't want that, you should use a declarative approach instead, where you first serialize the k:v pairs to strings, then output the (joined) strings
<Zelphir>In my case completely leaving out attributes from the string representation is OK, if they have not a number value. Basically #f meaning "this attribute is not there". Is (when ...) better for side effects than (if ...) for a reason other than (when ...) being shorter?
<Zelphir>To first serialize the key value pairs into strings – But would that not only be putting "the problem" (not really a big problem, more like an itch) off to another place in the code?
<lilyp>how so?
<lilyp>suppose you defined your formatting code as (and=> (record-field record) do-format-record-field)
<Zelphir>When transforming the key value pairs into a string, I need to construct that string. Then again I have to check, whether the value is a number or a #f.
<lilyp>then you can (filter-map (cute <> record) record-field-formatters9
<Zelphir>OK, but then the (and ...) would result in a #f if the field is #f. I would need to handle that #f then in the context.
<Zelphir>Ah you leave the #f away - interesting idea.
<lilyp>alternatively, you can always (filter identity ...) or (filter string? ...)
<Zelphir>I think I will try that approach : )
<Zelphir>Thank you!
<dadinn>hi all
<dadinn>happy new year!
<Zelphir>Hi and also happy new year!
<Zelphir>lilyp: Your idea worked well :) Not relying on the order of map looking at list elements, I find, that when looping over the list of key-value pairs, I still need a (when (not (null? attrs)) ...) or an "empty action" in the (cond [(null? attrs) ...] ...) case, but I was able to avoid a lot of (when ...), one for each attribute.
<Zelphir>I guess it would have to be a for-each anyway. Not a map.
<Zelphir>So I correct: Not relying on order of for-each.
<dadinn>not sure what the original question was, but why not use `unless` instead of `(when (not`?
<dadinn>I have a question about regex non-capturing groups. How do they work? This one doesn't work: (regex:string-match (regex:string-match "([0-9]+)(?:\\.([0-9]+)(?:\\.([0-9]+)(?:-(.+))?)?)?" "1.2.3-stuff") "1.2.3-stuff")
<dadinn>ice-9/boot-9.scm:1669:16: In procedure raise-exception:
<dadinn>In procedure make-regexp: Invalid preceding regular expression
<lilyp>I think I know where this might be going, but have you considered PEGs?
<dadinn>lilyp: PEGs? I think I've ran into the term, but not sure what it is :/
<lilyp>it's a way of defining regular or context-insensitive grammars that's a little cleaner than regexp
<pinoaffe>I personally always use instead of "regular" regular expressions, I find the syntax more readable
<pinoaffe>and it seems like the syntax is similar to the PEG syntax
<pinoaffe>(which is documented over at )
<dadinn> tput reset
<dadinn>oops, wrong keystroke :P
<cwebber>I seem to remember that David Thompson showed me he had implemented some repl comma-commands for a thing he was working on
<cwebber>so is that something I could do too? where would I find an example?
<Zelphir>dadinn: If you need examples:
<cwebber>irregex is awesome
<cwebber>I wish it would break things up into substructures
<cwebber>so I could use it as a complete language parser
<pinoaffe>cwebber: i only found out about the fact that it exists about a screen's worth upwards, but PEG appears to be pretty much that: a parser-generator with a syntax similar to irregex
<cwebber>pinoaffe: yeah it is similarish
<cwebber>the main difference is that the builtin guile version of the peg parser is macro based
<cwebber>oh fibers provides some examples
<cwebber>of repl commands