practicalli / practicalli/clojure

Argument order rules of thumb

Open
#378 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

design idiom
Dominant language
Makefile
Stars
117
Forks
36
PR merge metrics
No merged PRs in 30d

Description

https://groups.google.com/u/0/g/clojure/c/iyyNyWs53dc?pli=1

  1. Variable arg lists have to go last;
  2. The "operand," i.e. the object primarily being "operated upon,"
    goes last, to make partial application easier and nested expressions
    easier to read;
  3. If a function/macro takes a collection, the collection goes last.

Skimming through the API, it seems like most of the built-in functions
fit these rules, with a few exceptions:
conj contains? find get nth nthrest select-keys subs subvec with-meta
set/project

Hmmm... Good thing those weren't the rules or assoc/dissoc couldn't
have become variadic. I know it might seem arbitrary, but it's
(usually :) not.

A better characterization (but not a rule, no promises) might be that
the sequence functions take the seq last, and the collection functions
take the collection first.

I think with #() the partial application story is always easy - no
matter what the argument order you often want to bind args other than
the first.
Rich

I think the tradition is more general: abstract process which need missing process passed in(seems all high order functions under this category) should have missing process comes first as it's parameter.
This tradition not only limited to sequence parameter.

Also can we consider that put some special argument in some special position.

The main problem data, which often be the criteria of function dispatch, similar to OO's method target object, can as first parameter or after the missing process parameter?
So we can have a consistent parameter order model:
missing-process-param*, main-problem-data-param, additional-param*

With this model maybe we get better use of "->" to focus on & thread main problem:
E.g.
(->
main-problem-data
concrete-func-1
(concrete-func-2 additional-param)
((partial abstract-func-1 missing-process-1 missing-process-2))
((partial abstract-func-2 missing-process) additional-param))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file, test, or entry point is named. Read the linked Google Groups discussion and compare the listed functions with the Clojure API; a completed contribution would need an agreed, maintainable statement of argument-order guidance and a specified location for documenting it.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.