|
2729 | 2729 | `(do ~@forms))
|
2730 | 2730 |
|
2731 | 2731 | (core/defmacro require
|
2732 |
| - [& specs] |
2733 |
| - `(~'ns* ~(cons :require specs))) |
| 2732 | + "Loads libs, skipping any that are already loaded. Each argument is |
| 2733 | + either a libspec that identifies a lib or a flag that modifies how all the identified |
| 2734 | + libs are loaded. Use :require in the ns macro in preference to calling this |
| 2735 | + directly. |
| 2736 | +
|
| 2737 | + Libs |
| 2738 | +
|
| 2739 | + A 'lib' is a named set of resources in classpath whose contents define a |
| 2740 | + library of ClojureScript code. Lib names are symbols and each lib is associated |
| 2741 | + with a ClojureScript namespace. A lib's name also locates its root directory |
| 2742 | + within classpath using Java's package name to classpath-relative path mapping. |
| 2743 | + All resources in a lib should be contained in the directory structure under its |
| 2744 | + root directory. All definitions a lib makes should be in its associated namespace. |
| 2745 | +
|
| 2746 | + 'require loads a lib by loading its root resource. The root resource path |
| 2747 | + is derived from the lib name in the following manner: |
| 2748 | + Consider a lib named by the symbol 'x.y.z; it has the root directory |
| 2749 | + <classpath>/x/y/, and its root resource is <classpath>/x/y/z.clj. The root |
| 2750 | + resource should contain code to create the lib's namespace (usually by using |
| 2751 | + the ns macro) and load any additional lib resources. |
| 2752 | +
|
| 2753 | + Libspecs |
| 2754 | +
|
| 2755 | + A libspec is a lib name or a vector containing a lib name followed by |
| 2756 | + options expressed as sequential keywords and arguments. |
| 2757 | +
|
| 2758 | + Recognized options: |
| 2759 | + :as takes a symbol as its argument and makes that symbol an alias to the |
| 2760 | + lib's namespace in the current namespace. |
| 2761 | + :refer takes a list of symbols to refer from the namespace.. |
| 2762 | + :refer-macros takes a list of macro symbols to refer from the namespace. |
| 2763 | + :include-macros true causes macros from the namespace to be required. |
| 2764 | +
|
| 2765 | + Flags |
| 2766 | +
|
| 2767 | + A flag is a keyword. |
| 2768 | + Recognized flags: :reload, :reload-all, :verbose |
| 2769 | + :reload forces loading of all the identified libs even if they are |
| 2770 | + already loaded |
| 2771 | + :reload-all implies :reload and also forces loading of all libs that the |
| 2772 | + identified libs directly or indirectly load via require or use |
| 2773 | + :verbose triggers printing information about each load, alias, and refer |
| 2774 | +
|
| 2775 | + Example: |
| 2776 | +
|
| 2777 | + The following would load the library clojure.string :as string. |
| 2778 | +
|
| 2779 | + (require '[clojure/string :as string])" |
| 2780 | + [& args] |
| 2781 | + `(~'ns* ~(cons :require args))) |
2734 | 2782 |
|
2735 | 2783 | (core/defmacro require-macros
|
2736 |
| - [& specs] |
2737 |
| - `(~'ns* ~(cons :require-macros specs))) |
| 2784 | + "Similar to require but only for macros." |
| 2785 | + [& args] |
| 2786 | + `(~'ns* ~(cons :require-macros args))) |
2738 | 2787 |
|
2739 | 2788 | (core/defmacro use
|
2740 |
| - [& specs] |
2741 |
| - `(~'ns* ~(cons :use specs))) |
| 2789 | + "Like require, but referring vars specified by the mandatory |
| 2790 | + :only option. |
| 2791 | +
|
| 2792 | + Example: |
| 2793 | +
|
| 2794 | + The following would load the library clojure.set while referring |
| 2795 | + the intersection var. |
| 2796 | +
|
| 2797 | + (use '[clojure.set :only [intersection]])" |
| 2798 | + [& args] |
| 2799 | + `(~'ns* ~(cons :use args))) |
2742 | 2800 |
|
2743 | 2801 | (core/defmacro use-macros
|
2744 |
| - [& specs] |
2745 |
| - `(~'ns* ~(cons :use-macros specs))) |
| 2802 | + "Similar to use but only for macros." |
| 2803 | + [& args] |
| 2804 | + `(~'ns* ~(cons :use-macros args))) |
2746 | 2805 |
|
2747 | 2806 | (core/defmacro import
|
2748 |
| - [& specs] |
2749 |
| - `(~'ns* ~(cons :import specs))) |
| 2807 | + "import-list => (closure-namespace constructor-name-symbols*) |
| 2808 | +
|
| 2809 | + For each name in constructor-name-symbols, adds a mapping from name to the |
| 2810 | + constructor named by closure-namespace to the current namespace. Use :import in the ns |
| 2811 | + macro in preference to calling this directly." |
| 2812 | + [& import-symbols-or-lists] |
| 2813 | + `(~'ns* ~(cons :import import-symbols-or-lists))) |
2750 | 2814 |
|
2751 | 2815 | (core/defmacro refer-clojure
|
2752 |
| - [& specs] |
2753 |
| - `(~'ns* ~(cons :refer-clojure specs))) |
| 2816 | + "Refers to all the public vars of `cljs.core`, subject to |
| 2817 | + filters. |
| 2818 | + Filters can include at most one each of: |
| 2819 | +
|
| 2820 | + :exclude list-of-symbols |
| 2821 | + :rename map-of-fromsymbol-tosymbol |
| 2822 | +
|
| 2823 | + Filters can be used to select a subset, via exclusion, or to provide a mapping |
| 2824 | + to a symbol different from the var's name, in order to prevent clashes." |
| 2825 | + [& args] |
| 2826 | + `(~'ns* ~(cons :refer-clojure args))) |
2754 | 2827 |
|
2755 | 2828 | ;; INTERNAL - do not use, only for Node.js
|
2756 | 2829 | (core/defmacro load-file* [f]
|
|
0 commit comments