Closed aartaka closed 1 year ago
Sorry, this fell under my radar because GitHub didn't notify me...
So if I get it right, the main goal of make-instance*
is to avoid the cumbersome idiom for when we only want to instantiate non-nil slots:
(apply 'make-instance 'foo-class :a a-value (when b-value `(:b ,b-value)))
and replace it with just
(make-instance 'foo-class (a-value b-value))
If so, I think you should make this more explicit in the docstring.
So if I get it right, the main goal of
make-instance*
is to avoid the cumbersome idiom for when we only want to instantiate non-nil slots:
No, that's not the case. It was a thought in the initial draft, but that was too involved and easy to shoot feet off with.
(apply 'make-instance 'foo-class :a a-value (when b-value `(:b ,b-value)))
and replace it with just
(make-instance 'foo-class (a-value b-value))
No, make-instance*
does only two things:
{a, b}
=> {a: a, b: b}
.apply
last list inline.So, so have a length form like the one you list above, one has to write:
(make-instance* 'foo-class (a) (when b-value `(:b ,b-value)))
=>
;; Notice the :a a, because (a-value) would expand to :a-value a-value!
(apply 'make-instance 'foo-class :a a (when b-value `(:b ,b-value)))
It's not shortening much for small number of args, but is significantly helpful for 3+ args eponymous to slot names.
Oooops, seems like hard-reseting the branch closes the PR :D
I've refactored the logic one more time, now it should be reliable enough (or emit warnings on cases where it can't) :D
Merged. Will document it on main
and will send the aliases as a separate PR.
This adds
make-instance*
, a helper formake-instance
, abstracting over the frequent uses ofmake-instance
encountered in Nyxt and elsewhere.Addresses https://github.com/atlas-engineer/nyxt/issues/2584
Features
Shortcut args to abstract eponymous keyword arguments:
And the last argument being an arbitrary form to
apply
to:Discussion
Given that we start adding more and more CLOS wrappers to
nclasses
, maybe we should make the naming more consistent by adding aliases like:define-class
: adddefine-class*
alias.define-generic
(another PR):define-generic*
alias.I don't suggest removing the existing ones, I just suggest adding wrappers around them. Even if we don't use these, having a consistent set of macros won't hurt.