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'? <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. <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. <rlb>ieure: yeah, also handy if you're dealing with potentially lazy / infinite lists/sequences. <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...