💾 Archived View for gemini.ctrl-c.club › ~stack › gemlog › 2022-08-22.alists.gmi captured on 2024-05-26 at 15:06:22. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
gemini://siiky.srht.site/scheme/alist-let.gmi
@silky offers a let-like macro for binding variables based on an alist
Firstly, I am a Common Lisper and know very little Scheme.
First question: what is the purpose of alist-let? As I understand it (confusedly scanning the code and comments), you can bind symbols specified as keys to their corresponding values. If you don't know ahead-of-time what the symbol names are, you cannot use them in the body of the let, unless you somehow define local macros that contain those symbol-names... Otherwise, it's just let with a weirder syntax...
In Common Lisp we have another basic kind of a list, a PLIST, which takes a little more space but is a pretty generic datastructure. An alist '((a . 1)(b . 2)(c . 3)) may be converted to a plist `((a 1)(b 2)(c 3))...
The great thing about plists is that plists are used to represent parameters to the let form!
A let expression like (let ((a 1)(b 2)(c 3)) ...) already has a plist inside.
It is trivial to construct a macro that splices a plist into a let form:
(defmacro plist-let (plist body) `(let ,plist ,&body))
Not very useful, as it is a tautology for the let macro in the first place!
Now if you were to try to splice in an alist from some variable containing a plist, making it a compile-time macro that generates a binding, ok, but again, how would you know the names of the bound symbols?
And if it is entirely dynamic, binding things at runtime, even more so?
I am clearly missing the purpose and a use-case for doing this... A reply would be appreciated.