Email list hosting service & mailing list manager

Re: [RFC] alist-let: let-like alist destructuring syntax Marc Nieper-Wißkirchen (03 Jun 2022 15:08 UTC)
Re: [RFC] alist-let: let-like alist destructuring syntax Marc Nieper-Wißkirchen (03 Jun 2022 15:33 UTC)
Re: [RFC] alist-let: let-like alist destructuring syntax Wolfgang Corcoran-Mathe (03 Jun 2022 18:53 UTC)
Re: [RFC] alist-let: let-like alist destructuring syntax Marc Nieper-Wißkirchen (03 Jun 2022 19:08 UTC)
Re: [RFC] alist-let: let-like alist destructuring syntax Marc Nieper-Wißkirchen (30 Jun 2022 16:40 UTC)
Re: [RFC] alist-let: let-like alist destructuring syntax elf (14 Aug 2022 00:10 UTC)

Re: [RFC] alist-let: let-like alist destructuring syntax elf 14 Aug 2022 00:09 UTC

Use fold with two args, one the alist and one (iota (length alist)), if i understood you correctly.

On 14 August 2022 2:49:32 GMT+03:00, siiky <xxxxxx@net-c.cat> wrote:
>Hi all,
>
>Breaking another long silence.
>
>I've been thinking on and off about a more efficient `alist-values` (that Marc suggested) but nothing I can implement comes to mind.
>
>The best idea I got was the following (assuming an alist `al` and N variables/keys): initialize a vector of length N with each variable's default value (assume #f for now). Traversing `al`, for each key/value, if the key is one of the wanted ones then set the value in the key's position of the vector. Of course, only the value of the first occurrence should be kept, if any. In the end it's just a matter of (apply values (vector->list vec)).
>
>Something like this:
>
>(define (alist-values al . keys)
>  (define (key-index k) ???)
>
>  (define vec (make-vector (length keys)))
>
>  (define (wanted-key? k)
>    (and (member k keys)
>         (not (vector-ref vec (key-index k)))))
>
>  (for-each
>    (lambda (kv)
>      (let ((k (car kv))
>            (v (cdr kv)))
>        (when (wanted-key? k)
>          (vector-set! vec (key-index k) v))))
>    al)
>
>  (apply values (vector->list vec)))
>
>The problem is I have no idea how to associate a vector index to a key... This is as far as I can go for now.
>
>
>PS: I changed repos recently, it's on SourceHut now. It's still on GitHub (in case anyone prefers that) which I'll keep up to date if I don't forget.
>
>PPS: Added a tiny usage example and some clearer docs (I couldn't remember anymore off the top of my head the purpose of each clause...)
>
>[0]: https://git.sr.ht/~siiky/alist-let
>
>siiky
>
>