ClojureScript

Simplify macro usage

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

The usage of macros from CLJS is very explicit and users of any given namespace must remember whether it comes with macros and which vars are macros. This leads to rather verbose :require statements which are confusing and lead to unexpected results if incomplete (eg. missing :refer-macros).

(ns my-ns
  (:require [my-app.other-ns :as other :refer (something) :refer-macros (something) :include-macros true]))

(something) ;; macro (when :refer-macros, otherwise no macro)
(other/thing) ;; maybe macro (only when :include-macros, otherwise no macro)

I think the user should not need to know whether something is a macro or not, they should just be able to use it.

I implemented a proof-of-concept that

(ns my-ns
  (:require [my-app.other-ns :refer (something)])

will work just find and do the correct thing with regards to macros (assuming the namespace has a corresponding clj namespace, :require-macros is unaffected). No changes to any code are necessary as the implementation uses ana/passes, it is also fully backwards compatible.

Implementation points which should be discussed

  • The CLJS namespace with macros currently has to opt-in through a bit of metadata (eg. (ns my-ns-with-macros {:load-macros true})), that might not be necessary and maybe should default to true.
  • The implementation assumes compilation happens in dependency order. shadow-build always does this, I'm not too sure about CLJS though. Given ana/analyze-deps equals true that is guaranteed but I'm not sure that is always the case.

If there is any interest I can provide a patch, until then refer to the proof-of-concept [1].

[1] https://github.com/thheller/shadow-build/blob/f37cfa598f1e90dd66e333d1e45580ea25650025/src/clj/shadow/cljs/passes.clj#L30-L82

  1. cljs-948.diff
    07/Jan/15 8:37 AM
    7 kB
    Thomas Heller
  2. cljs-948-no-passes.diff
    08/Jan/15 9:42 AM
    5 kB
    Thomas Heller

Activity

David Nolen made changes -
Field Original Value New Value
Priority Major [ 3 ] Minor [ 4 ]
Thomas Heller made changes -
Attachment cljs-948.diff [ 13712 ]
Thomas Heller made changes -
Attachment cljs-948.diff [ 13712 ]
Thomas Heller made changes -
Attachment cljs-948.diff [ 13714 ]
David Nolen made changes -
Priority Minor [ 4 ] Major [ 3 ]
Thomas Heller made changes -
Attachment cljs-948.diff [ 13714 ]
Thomas Heller made changes -
Attachment cljs-948.diff [ 13726 ]
Thomas Heller made changes -
Attachment cljs-948-no-passes.diff [ 13735 ]
David Nolen made changes -
Status Open [ 1 ] Resolved [ 5 ]
Resolution Completed [ 1 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]
Thomas Heller made changes -
Resolution Completed [ 1 ]
Status Closed [ 6 ] Reopened [ 4 ]
David Nolen made changes -
Status Reopened [ 4 ] Resolved [ 5 ]
Resolution Completed [ 1 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: