correl/calrissian

Form preference?

oubiwann opened this issue · 2 comments

One of the things that Robert and I have started using in LFE is the "data" form for pattern matching and, well, data ;-) Here's an example using the constructors:

(defun >>=
  (((tuple 'error reason) f)
   (tuple 'error reason))
  (((tuple 'ok value) f)
   (funcall f value))
  (('ok f)
   (funcall f 'ok)))

Here's an example using the "data" form:

(defun >>=
  ((`#(error ,reason) f)
   (tuple 'error reason))
  ((`#(ok ,value) f)
   (funcall f value))
  (('ok f)
   (funcall f 'ok)))

However, I tend to use the data/quoted form more often that not, e.g.:

(defun >>=
  ((`#(error ,reason) f)
   `#(error ,reason))
  ((`#(ok ,value) f)
   (funcall f value))
  (('ok f)
   (funcall f 'ok)))

If you prefer to use the longer constructor form, just say the word and I won't submit any PRs to change that :-)

There's no set standard or convention around this; either way is totally fine. Well, I guess there is one convention: to use the constructor form when teaching LFE to newcomers, that way one can postpone discussions about backquotes, unquotes, etc., until later.

I remember being on the fence on this when writing it, and probably went with the constructor form since they were simple enough cases and I didn't want to think too long on it.

I'm fine with either convention (and I am a fan of the backquote), so long as it's all consistent in the end, go for it :)

Great! Getting ready for a PR right now ...