<< Back to previous view

[CLJ-707] -> produces known-invalid code when it could be smarter Created: 07/Jan/11  Updated: 03/Sep/11  Resolved: 03/Sep/11

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Alan Malloy Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None

Attachments: Text File patch.txt    


(-> inc (comp read ())

Macroexpands to (nil (comp read promise)), which is known at compile-time to be illegal code.
It seems like it would be harmless, and occasionally useful, to special-case () to expand into wrapping parens around the preceding form, such as:

((comp inc read))

I'll put together a patch for this shortly if nobody tells me it's a terrible idea.

Comment by Alan Malloy [ 07/Jan/11 4:28 PM ]

Sorry, that -> form came out wrong. The first line should read: (-> inc (comp read) ())

Comment by Alan Malloy [ 08/Jan/11 12:16 AM ]

Here's me testing that my improved versions of -> and ->> work in my use case, and preserve existing behavior for (-> x []) just in case someone was depending on the expansion of this crazy form. Patch will be attached momentarily.

clojure.core> (macroexpand-all '(-> inc (comp read) ()))
((comp inc read))
clojure.core> (macroexpand-all '(->> inc (comp read) ()))
((comp read inc))
clojure.core> (macroexpand-all '(->> read (comp inc) () inc))
(inc ((comp inc read)))
clojure.core> (macroexpand-all '(-> x))
clojure.core> (macroexpand-all '(-> x []))
([] x)

Comment by Alan Malloy [ 08/Jan/11 12:20 AM ]

I also factored out some of the behavior common to -> and ->> into a separate function - especially helpful as I was adding still more common behavior. If y'all think it's a good idea I can lift the rest of the common functionality (ie the defns and recursive cases) into a macro that gets called twice, but that seems likely to be less readable and it's not like we're playing golf here.

Comment by Alan Malloy [ 11/Jan/11 11:41 PM ]

Having run ant test, I see that defn- isn't actually available at this point in the bootstrapping process; it should read defn ^:private.

Comment by Stuart Halloway [ 14/Jan/11 7:38 AM ]

Rich: interested?

Comment by Rich Hickey [ 14/Jan/11 8:06 AM ]


Comment by Chas Emerick [ 03/Sep/11 10:05 PM ]

Closed per request from Alan Malloy.

Generated at Sun Jul 23 12:07:37 CDT 2017 using JIRA 4.4#649-r158309.