IRC channel logs

2026-03-12.log

back to list of logs

<lechner>Hi, is there an idiom to check whether a list has at least N elements without traversing the entire list with 'length'?
<sneek>Welcome back dsmith!
<ieure>lechner, Yes, you can use a recursive function which takes N-1 cdrs of the list, terminating when you reach an empty list or N-1 iterations. If you get an empty list before you're out of iterations, the list is shorter than N.
<JohnCowan>dsmith: That's impossible.
<JohnCowan>sorry. misread
<ieure>lechner, I'm probably off a bit on the details, but hopefully you understand the approach. Lists are fundamentally O(n) data structures, so this will never be efficient, but is a good optimization when the N you care about is small.
<lechner>ieure / thanks!
<lechner>JohnCowan / thanks for looking!
<rlb>ieure: yeah, also handy if you're dealing with potentially lazy / infinite lists/sequences.
<rlb>clj has bounded-count for that, though it can "cheat" when it hits a collection that's "counted", e.g. (assuming I didn't get it wrong) https://codeberg.org/lokke/lokke/src/branch/main/mod/lokke/base/collection.scm#L188-L197
<rlb>(utf8 branch rebased after a few minor conflicts https://codeberg.org/rlb/guile/src/branch/utf8)
<dsmith>sneek, botsnack
<sneek>:)
<zyd>Asking about LLM policy/attitude here: https://codeberg.org/guile/guile/issues/127
<loquatdev>How do I add a module to the load path from C?
<loquatdev>Nevermind, I was thinking about something the wrong way.
<loquatdev>I am trying to read an srfi-9 record from C. Since srfi-9 records aren't really convenient to define from C, I'm instead loading a Scheme module that has my record and its associated functions already defined. My record is called `window` and I'm attempting to test if a value is of this type by using `scm_call_1(scm_c_lookup("window?"), variable)` I get an error along the lines of `Wrong type to apply:
<loquatdev>#<variable 7f7a46e68700 value: #<syntax-transformer window?>>`. Apparently, `window?` is not a procedure. What's the proper way to check an srfi-9 record from C?
<loquatdev>I saw an old email thread about this but there wasn't really an answer, just someone suggesting to write a wrapper procedure in the Scheme module and load that instead. While I imagine that could work, I want to try and actually understand how to interface with these records.
<loquatdev>Is there a way I can view the expanded code from a syntax transformer?
<old>loquatdev: ,expand form
<dsmith>JohnCowan, I'm a bit curious about what was impossible...