IRC channel logs

2025-04-25.log

back to list of logs

<cow_2001>what is the difference between a chapter and a section and a subsection and a subsubsection? can't i just use nested chapters?
<cow_2001>in skribilo, that is
<cow_2001>you cannot do something like this in skribilo (chapter :title [outer chapter] (chapter :title [first inner chapter] [body of first inner]) [body of outer chapter] (chapter :title [second inner chapter] [body of second inner chapter]))
<cow_2001>hmm
<sneek>Yey! dsmith is back!!
<dsmith>sneek, botsnack
<sneek>:)
<lechner>Hi, is there a predicate to test whether something is an S-expression, or does that not make any sense?
<old>lechner: anything that can be read by the reader is an S-expression
<old>"this is an s-expression"
<old>this also: 1
<old>and this: '(1)
<old>So I would say that having a predicate for an S-expression could be something like so:
<old>(define (s-expr? string) (and (false-if-exception (call-with-input-string string read)) #t)
<old>)
<old>(s-expr? "foo") => #t
<old>(s-expr? "(") => #f
<lechner>old / thanks!
<dsmith>old, Nice! I would not have thought of that.
<sneek>wb chrislck!!
<morenonatural>can I pass a string to a foreign-function? any samples?
<morenonatural>a string as an argument
<old>morenonatural: if your FFI accept pointers, you can: string->pointer
<morenonatural>old, thank you ... didn't think such would be under the "void pointers and byte access" section (I just quickly scheemed through it)
<old>example: https://paste.sr.ht/~old/7a0bb5ceb563d775f8a152254183af1dd9be4e5a
<morenonatural>what's the % prefix hinting?
<old>morenonatural: nothing special. I use it as a convention for "real" implementation
<morenonatural>k, thanks
<old>could had been: primitive-strcmp
<lechner>Hi, is 'eval' the inverse of 'quote'?
<old>lechner: to quote is to not eval
<lechner>so (eval (quote x) (interaction-environment)) is always x, right?
<old>Stricly speaking, I don't think you can say that quote is the inverse of eval
<lechner>yeah, i know. i misspoke
<lechner>old / okay, thanks!
<old>for always x: yes
<old>I mean
<old>if `x' is defined in the interactive environment you will get that value
<old>if you want to get the symbol x you would do: (eval (quote (quote x)) ...)
<lechner>actually, i meant that x is an arbitrary S-expression
<old>assume the following: (define s-exp '(+ 1 1))
<old>(eval 's-exp (interaction-environment))
<old>you get: (list + 1 1)
<old>but if you do
<old>(eval s-exp (interaction-environment))
<old>you get: 2
<old>by applying eval to `s-exp' you are evaluation `s-exp' itself first
<old>so you end up evaluating '(+ 1 1) which is 2
<old>but if you eval 's-exp, you will get wathever is in that symbol
<old>in the environment
<lechner>old / i am not though, am i? (eval (quote x) (interaction-environment)) from above just means that, for your sexp: '(+ 1 1) is (list + 1 1) which true, isn't it?
<old>yes
<old>if X is an s-expr like above, you get that s-expr back if you quote its evaluation
<old>I think I understand your point now
<old>f(f-1(x)) = x
<old>f-1 being the inverse of f
<lechner>old / thank you for your help today!
<old>np
<lechner>Hi, what's the relationship between 'read' and 'eval', please?
<ieure>lechner, Lisp-generic answer: `read' takes text and turns it into lists; `eval' evaluates (executes) lists containing Lisp code.
<old>lechner: read: string -> s-exp; eval: s-exp -> s-exp
<old>actually read is taking a port, but get the gist. It creates s-exp from a sequence of token
<lechner>okay, thanks! is (quasiquote ,(read X)) the same as (quote X) ?
<lechner>actually, (quasiquote ,(call-with-input-string X read))
<ieure>Eval it and see?
<morenonatural>what's The Guile Way to do those monadic `null-or-int` thingies? just like this? 👉🏾 (and (null? maybe-int) (something maybe-int))
<morenonatural>duh
<morenonatural>(or (null? maybe-int) (some-stuff-with-ints maybe-int))
<mwette>morenonatural: (integer? maybe-int)
<mwette>not sure what detail you're after
<morenonatural>mwette, not sure about the name
<morenonatural>for example
<morenonatural>in emacs I would use `or' for, say, default values
<morenonatural>(or maybe-some-value default-value)
<morenonatural>since `or' is a macro, I can safely use a function
<morenonatural>(or maybe-some-value (get-default-value))
<morenonatural>in this ☝🏾 example, `get-default-value' is not called if `maybe-some-value' is not `nil'
<rlb>lechner: note that read only reads one value, so it won't look at anything after that e.g. (call-with-input-string "1 '")
<old>morenonatural: There's nothing in Guile or Scheme for that. But you can roll your own like you want
<old>example: https://paste.sr.ht/~old/b968a1775a5258d0c427ab1fea897131822b0c93
<lechner>rlb / thanks! that's good to know. should it return a 'values' thingy?
<rlb>No, it's explicitly intended to work that way -- if you want to read all the values in the input, you loop until you get (eof-object? x).
<rlb>(or it crashes on a bad s-exp)
<lechner>rlb / okay, thanks!
<lechner>Hi, does the underscore _ have a special meaning in Guile, beyond common convention?
<lechner>or asked differently, what does people do when they want to ignore two arguments in a lambda definition? Using _ twice yields duplicate identifier in argument list in form (_ _ arg seed)
<lechner>what do
<ieure>lechner, I think it's mostly convention, though some macros may treat _ specially (thinking of `match' here). Not sure if this is a Guile convention, but it's idiomatic in Clojure to ignore any underscore prefixed argument, so (lambda (_foo _bar arg seed))
<shawnw>x1 and x2
<rlb>...the underscores in clj and python may also signal the linter(s)
<rlb>(eastwood, kondo, pylint, etc.)
<dsmith>When defining a macro, the macro name in patterns is redundant and often is replaceed with _
<morenonatural>old, thanks 👍🏽
<morenonatural>I have items with a "start", and I want to assign each item an "end" which would be the next item's "start" (last item has no "end")... any way of doing this ergonomically in guile?
<morenonatural>(willing to using list, stream functions or transducers)
<morenonatural>(or anything else available)
<morenonatural>just use a vector with `i' and `(+1 i)'?
<ieure>morenonatural, Probably something like (map (lambda (pair) ...) (zip list (cdr list))) will get you most of the way there.
<ieure>The lambda will end up with a list, where the car is an element from the list and the cadr is the next.
<ieure>Note that this drops the final element, so you probably want (append (cdr list) '(#:end)) or something like that to even them back out.
<ieure>zip is in (srfi srfi-1)
<morenonatural>cool, thanks
<old>lechner: I would recommend to always name things
<old>even if not used, having a name help understand the code
<old>the exceptions to this rule is: catch-all match pattern: (match ... (_ catch-all))
<old>and syntax-rules
<old>good lord as I was writitng that last message, I saw a fox fetching one of my chicken and running with her into the forest
<ieure>oof
<old>fortunatelly, I ran after them and I got the chicken back
<dsmith>ACTION attempts to say something clever about Foxes with "Guile" and Chicken Scheme but mercifully gives up
<dsmith>old, Did the chicken survive?