atlas-engineer / prompter

Live-narrowing, fuzzy-matching, extensible prompt framework.
BSD 3-Clause "New" or "Revised" License
13 stars 1 forks source link

Use progn combination for `prompter:object-attributes` #18

Closed aartaka closed 1 year ago

aartaka commented 1 year ago

It's our frequent use-case to compose prompter:object-attributes (as in Nyxt hint-mode). Which tends to be ugly and not-exactly-composable after all—adding :around methods everywhere is quite a crude way to do things.

progn method combination seems to be a better shot—progn methods are not limited in number (if the specifies differ), while being perfectly composable. The downsides exist, though:

Mostly backwards-compatible too—I have no idea why anyone would use :before/:after methods in their prompts, so that shouldn't break anything.

EDIT: formatting, typos, and details

aartaka commented 1 year ago

Hmmmmmm, it seems to break because progn combination has no primary methods 0_o That I didn't know. Maybe write our own combination then?

Ambrevar commented 1 year ago

That's an option, I suppose. Then we can support :before and :after.

But can you give an example how progn would be better here?

aartaka commented 1 year ago

That's an option, I suppose. Then we can support :before and :after.

But we don't really need them ( ͡° ͜ʖ ͡°) Maybe to concat to the beginning/end of the thing, but that's achievable with :around...

I guess our own combination with prefixing and suffixing the list and with primary method would work better after all.

But can you give an example how progn would be better here?

It'd be better in appending attributes from several inherited sources/objects. The main application, as I've said, is Nyxt's hint-mode.

Oh, wait, it should be append instead of progn (@´_`@)

Ambrevar commented 1 year ago

I see it's useful for hint-mode, but is it so common that we want to reuse all the attributes of a parent? Seems a bit specific to me. The problem with an append method is that we don't control the attribute order much.

Ambrevar commented 1 year ago

Note: maybe the loop in the hint-mode example is needlessly complicated. Does it do the same as this?

(let ((attributes '(("URL" "http://foo.org"))))
  (mapcar (lambda (attr)
            (or (assoc attr attributes :test 'string=)
                (list attr "")))
          '("URL" "Body")))
aartaka commented 1 year ago

Note: maybe the loop in the hint-mode example is needlessly complicated. Does it do the same as this?

(let ((attributes '(("URL" "http://foo.org"))))
  (mapcar (lambda (attr)
            (or (assoc attr attributes :test 'string=)
                (list attr "")))
          '("URL" "Body")))

No, it's merely ensuring the attribute is there. But I'm guessing we can simplify it too if we have a reasonable method combination.