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 siiky (30 Jun 2022 15:54 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 siiky 30 Jun 2022 15:54 UTC
Hi again,

Sorry for the long silence.

I now have a better idea of a syntax that I think would be good:

(alist-let ALIST ((VAR KEY [DEFAULT [EQUAL?]]) ...)
   BODY ...)

I spent some time trying to write an implementation and this is what I
have working:

(define (alist-values alist . keys)
   (chain keys
          (map (cute alist-ref <> alist equal?) _)
          (apply values _)))

(define-syntax alist-let
   (syntax-rules ()
     ((alist-let alist ((var key) ...)
        body ...)
      (receive (var ...) (alist-values alist key ...)
        body ...))))

(Not impressive, I know... It's the most basic functionality, with no
way to provide a default value or equality test. Still, Marc's
suggestion take advantage of receive with an alist-values greatly
simplifies things!)

Most of the time I spent was actually trying to implement an
alist-values that supports an optional default value but with no luck...
I hit the limit of my macrology, apparently. (Sending that failed
attempt attached in case anyway wants to give it a go)

The problem with it is that symbols  'sym  match  (key default)  as
(quote sym)  in the following clause:

(_ "add-defaults" (tmp-list ...) alist ((key default) keys ...))

And so I have to no way to tell appart ('foo "some default") from 'foo.

siiky