drym-org / symex.el

An intuitive way to edit Lisp symbolic expressions ("symexes") structurally in Emacs
Other
271 stars 22 forks source link

Simplify runtime implementations using interfaces #135

Closed countvajhula closed 2 months ago

countvajhula commented 2 months ago

Currently, each language has a dedicated module called symex-interface-racket or symex-interface-fennel which provide similar functions to fulfill common "runtime" tasks like evaluating an expression or looking up docs. @pbaille brought up the idea in #134 of simplifying this through some form of interface for which we provide implementations for each language, while using the same approach to allow adding a custom implementation without it necessarily being part of Symex.

countvajhula commented 2 months ago

To continue the discussion from #134 @pbaille :

It looks like your current implementation maps major modes to interface implementations. So IIUC, we would define new implementations as:

(symex-interface-add 'racket-repl-mode
                     (list :eval #'racket-eval :eval-definition #'racket-eval-defun ...))

and similarly for a different major mode which also happens to use the same Racket implementation (in this case "xp" mode vs "repl" mode):

(symex-interface-add 'racket-xp-mode
                     (list :eval #'racket-eval :eval-definition #'racket-eval-defun ...))

Even though the implementations are duplicated, it should still work in your existing approach, I think?

While I like the simplicity of your approach, I'm wondering if there might be existing support for such "interfaces" in ELisp or perhaps cl-lib which includes a lot of Common Lisp features. cl-defgeneric comes to mind but I'm not sure if that's usable. Could be worth a look.

pbaille commented 2 months ago

Even though the implementations are duplicated, it should still work in your existing approach, I think?

Yes it should, I was just concerned about the duplication, but it may not be that big of a deal.

I'm wondering if there might be existing support for such "interfaces" in ELisp or perhaps cl-lib which includes a lot of Common Lisp features. cl-defgeneric comes to mind but I'm not sure if that's usable. Could be worth a look.

Definitely, I will try to take a look at it tomorrow, and we will discuss it further.

Thanks for the feedback !

pbaille commented 2 months ago

I've just put together a draft PR following this. For now it do not leverage cl-defgeneric and still needs testing, but it can already feed the conversation I guess.

countvajhula commented 2 months ago

Fixed in #136