# miscellaneous notes # lambda pattern matching ~~~ (apply (lambda (a b c) #t) (list 1 2 3)) ~~~ -> a:1 b:2 c:3 ~~~ (apply (lambda (a b . c) #t) (list 1 2 3 4 5)) ~~~ -> a:1 b:2 c:(3 4 5) ~~~ (apply (lambda* (a #:optional b) #t) (list 1 2)) ~~~ -> a:1 b:2. if a shorter list (list 1) where given instead, then a:1 b:#f ~~~ (apply (lambda* (a #:key (b 8) c) #t) (list 1 #:b 2 #:c 3)) ~~~ the special #: keyword syntax of lambda* is used to differentiate from normal symbols. unfortunately, the following does not work ~~~ (apply (lambda (a . b) #t) (pair 1 2)) ~~~ # other * eq, eqv, equal * `eq?` tests whether two objects are the same (pointer equality). * `eqv?` extends `eq?` by treating numbers and characters with the same value as equivalent. * `equal?` performs deep structural comparison, suitable for lists, vectors, strings, etc. * eval returns objects * `(eval expr module)` evaluates an expression and returns the resulting Scheme object, not its printed form. * exact->inexact: floats are inexact, integers are exact * Exact numbers include integers and rational numbers. * Inexact numbers include floating-point values. * `(exact->inexact 3)` yields `3.0`; the reverse is possible with `(inexact->exact)`. * file tree walk * Use `(scandir path predicate)` to list directory entries. * Use `(file-is-directory? file)` to detect subdirectories. * Combine recursively to walk the file tree. * map with multiple arguments * `(map proc lst1 lst2 ...)` applies `proc` to elements taken simultaneously from each list. * Evaluation stops when the shortest list is exhausted. * multiple hash-table interfaces, multiple exception interfaces * Guile supports native hash tables and SRFI-69. * It offers multiple exception systems: legacy (`catch`), SRFI-34, and SRFI-18. * Interfaces may differ in API and behavior. * named let defines and calls a procedure * A named `let` defines a recursive procedure and invokes it immediately. * Useful for stateful or tail-recursive loops without top-level `define`. * pattern matching with (ice-9 match) * `(use-modules (ice-9 match))` enables `match` expressions. * Supports destructuring, nested patterns, and guards for concise branching. * sandbox evaluation * Sandboxing can be achieved by limiting the bindings in the evaluation environment. * Control I/O and resource access externally for isolation. * the guile c interface * Guile's `libguile` provides a C API to embed Scheme or expose C functions to Scheme. * Use `scm_c_define_gsubr`, `scm_from_int`, etc., for interoperation. * the use of begin on the toplevel * `begin` sequences expressions but does not introduce a new scope at the top level. * All side effects are executed in order during loading. * uniform vectors and c * Uniform vectors (`u8vector`, `f64vector`, etc.) store homogenous, fixed-type data. * They map directly to C-compatible arrays for efficient interop. * the identity function * `(define (identity x) x)` is the canonical form. * Also expressed as `values` in multiple-value contexts. * guile procedure index * Guile provides a comprehensive index of procedures in its manual. * Accessible via `info guile` or online, useful for API discovery. * continuation passing style * Guile supports CPS through first-class continuations and `call/cc`. * Enables non-local exits, backtracking, and coroutines. * lists are chains of pairs * Scheme lists are built from nested pairs (cons cells). * Each node’s `car` holds a value; `cdr` points to the next pair or `()`.