IRC channel logs
2024-09-10.log
back to list of logs
<xelxebar>What's an idiomatic way of building an explicit list where some items are conditionally included? <xelxebar>The noise in `(blah ... ,@(if cond (item)) ...) kind of grates against me. <xelxebar>Wondering if something like (let ((lst '())) (if cond (cons item list)) ...) is reasonable. <xelxebar>Uh. Obviously we'd need to wrap in set!. Blah... Probably even worse. <xelxebar>Wait. Maybe putting #f or whatever in the if alternate and post-processing with a filter is better. <xelxebar>(filter identity (list ... (if cond item) ...)) <flatwhatson>xelxebar: filter-map or append-map from srfi-1 can be useful for this <xelxebar>flatwhatson: Ah, okay. Convenient wrappers. Chers. <morenonatural>on that same matter, I'm having trouble doing assq-ref on a association list that's constructed using (STRING . FLOAT) key-values... cannot write a MWE, but can consistently reproduce <morenonatural>not sure on where to look, I'm doing asserts on key and value... key is string, value is float, (display)s expected key-values <dthompson>morenonatural: you need to use assoc-ref for equal? based lookup <dthompson>and 'match' will not work on association lists as they are unordered <morenonatural>any examples on ($ my-record) matching? I'm getting (unbound)s on the slots <dthompson>consider: (define-record-type <foo> make-foo foo? (bar foo-bar)) <dthompson>or rather: (define-record-type <foo> (make-foo bar) foo? (bar foo-bar)) <dthompson>(match (make-foo 42) (($ <foo> bar) bar)) ;; => 42