First comments Marc Nieper-Wißkirchen 09 Jun 2020 06:48 UTC

Dear Adam,

congratulations to your first SRFI!

I have read your initial draft and have a few first comments that are
hopefully helpful:

(1) In the issue section, you wrote that the name "threading macros"
may be a bit misleading, and, in fact, when I read the SRFI's title in
Arthur's announcement, I thought it had something to do with threads.

What about a name that uses the word "sequencing" like in "sequencing
operators" instead?

(2) The fact that the macros `->' and `->>' do some automatic wrapping
in parentheses leads to some inconsistencies, so I would drop it. At
the moment, the macros rely too much on the syntax:

(-> x f)

result in `(f x)'. If `f' is itself the result of a call to the thunk
`g' (or the expansion of a macro named `g'), the user will expect that

(-> x (g))

does the same. It doesn't, however, because this expands into `(g x)'.

A good macro shouldn't lead to such surprises. In SRFI 2, the number
of parentheses in each claw has been wisely chosen, for example, to
make it always work as expected.

(3) The description of `as->' is harder to understand than reading its
definition in terms of the syntax-rules macro. The macro allows many
more uses than what the description says.

(4) Reading the descriptions of `some->' and `some->>', I am wondering
whether the whole syntax of this SRFI can be merged with the syntax of
SRFI 2, reducing the number of overlapping syntaxes. SRFI 197 seems to
(partially) describe `and-let*' constructs where the intermediate
variables can be made anonymous.

(5) As `cond->' and `cond->>' do not short-circuit, `when->' and
`when->>' maybe better names.

(6) These macros do not handle procedures returning multiple values;
this may not be an issue with Clojure (I don't know), but it should be
taken into consideration with Scheme. Especially for pipelining,
multiple values can come in handy when more than one value has to be
threaded through (or just at some intermediate stages).

(7) The draft uses the term "function" several times, where it would
be called "procedure" in the Scheme world.

(8) It took me a moment to understand what you meant by "thread-first"
and "thread->last". I don't find the difference in the symbols `->'
and `->>' self-explanatory in this regard.

(9) `as->' needs a dummy argument `name', which is not needed from a
language-designers point of view. I would suggest getting rid of it
and having SRFI 197 export an identifier that is used to mark the
slot. This can be implemented as `yield' in SRFI 190.

Marc

Am Di., 9. Juni 2020 um 05:41 Uhr schrieb Arthur A. Gleckler
<xxxxxx@speechcode.com>:
>
> Scheme Request for Implementation 197,
> "Threading Macros,"
> by Adam Nelson,
> is now available for discussion.
>
> Its draft and an archive of the ongoing discussion are available at https://srfi.schemers.org/srfi-197/.
>
> You can join the discussion of the draft by filling out the subscription form on that page.
>
> You can contribute a message to the discussion by sending it to xxxxxx@srfi.schemers.org.
>
> Here's the abstract:
>
> Threading macros provide a simple, readable way to write deeply-nested expressions. Also known as "arrows", these macros were first introduced in Clojure, and are a key feature of that language. With threading macros, expressions like
> (append (cons (assoc x y) c) '(a b))
> can be written as a sequence of operations:
> (-&gt; x (assoc y) (cons c) (append '(a b)).
>
> Regards,
>
>
> SRFI Editor