Noob question on the --> macro implementation

122 views
Skip to first unread message

Ujjwal Thaakar

unread,
Jan 26, 2019, 1:50:21 PM1/26/19
to Clojure
Hi,
I'm trying to learn Clojure and I just curiously typed 
(source ->>)
 in the REPL and was wondering about this: https://github.com/clojure/clojure/commit/749a0ad8b66c781d8176833f0ad26cfe6b9b24e3#r32075784

Am I missing something?

Andy Fingerhut

unread,
Jan 26, 2019, 2:04:28 PM1/26/19
to clo...@googlegroups.com
When you ask "am I right?" about your proposed change, what is it that the current behavior does not do, that your change would do?  Do you have some use case in mind that works with your change, but doesn't with the current implementation?

Andy

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Reeves

unread,
Jan 26, 2019, 2:09:12 PM1/26/19
to clo...@googlegroups.com
I believe he's just saying it's simpler and possibly more efficient.

Unless I'm missing something subtle in the way this is resolved, I believe Ujjwal is right that:

    `(~(first form) ~@(next form) ~x)

Is equivalent to:

    `(~@form ~x)
--
James Reeves

Sean Corfield

unread,
Jan 26, 2019, 6:13:23 PM1/26/19
to clo...@googlegroups.com

I suspect it’s done for consistency with the source of -> (which has to use first/next because it threads the expression between them) – using first/next/x in ->> is therefore a closer parallel to using first/x/next in -> so it’s easier to see the similarity (and correctness) of the code.

 

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

 


From: clo...@googlegroups.com <clo...@googlegroups.com> on behalf of James Reeves <ja...@booleanknot.com>
Sent: Saturday, January 26, 2019 11:08:25 AM
To: clo...@googlegroups.com
Subject: Re: Noob question on the --> macro implementation
 

Gary Fredericks

unread,
Jan 26, 2019, 6:53:24 PM1/26/19
to Clojure
There's probably also a difference in what happens if the form is empty. The current impl results in a compile error about calling nil, whereas the suggested implementation would result in calling the current thread value as a function, I think.

Matching Socks

unread,
Jan 27, 2019, 7:01:15 AM1/27/19
to Clojure
Gary might be on to something. The immediate context is

(if (seq? form)
             
(with-meta `(~(first form) ~@(next form)  ~x) (meta form))
              (list form x))]


where seq?, as distinct from seq, does not check whether there is anything in the sequence.

Ujjwal Thaakar

unread,
Mar 5, 2019, 4:10:31 PM3/5/19
to Clojure
I didn't understand what you meant by
where seq?, as distinct from seq, does not check whether there is anything in the sequence.

Ujjwal Thaakar

unread,
Mar 5, 2019, 4:15:12 PM3/5/19
to Clojure
Sorry I had completely forgotten about this post and just saw it now. I think this explanation makes sense although in most cases the thread value will also not be a function and if it is then it could be treated as invoking the threaded function's call and the result passed on to the next form.

Ujjwal Thaakar

unread,
Mar 5, 2019, 4:15:58 PM3/5/19
to Clojure
Yes that was my only point.
Reply all
Reply to author
Forward
0 new messages