|
5241 | 5241 | You may include an optional docstring for the namespace to describe its purpose. The |
5242 | 5242 | docstring will be applied as the ``:doc`` key on the namespace metadata map. |
5243 | 5243 |
|
| 5244 | + An optional map of metadata can be given after the docstring. If provided, this |
| 5245 | + metadata will be merged into the metadata for the resulting namespace. |
| 5246 | + |
5244 | 5247 | Example:: |
5245 | 5248 |
|
5246 | 5249 | (ns my.namespace |
5247 | 5250 | \"My namespace with code\" |
| 5251 | + {:meta-key 1} |
5248 | 5252 | (:refer-basilisp :exclude [get]) |
5249 | 5253 | (:require |
5250 | 5254 | [basilisp.string :as str]) |
|
5273 | 5277 | (when-not (and (symbol? name) (nil? (namespace name))) |
5274 | 5278 | (throw (ex-info "Namespace name must be a non-namespaced symbol" |
5275 | 5279 | {:name name}))) |
5276 | | - (let [doc (when (string? (first opts)) |
5277 | | - (first opts)) |
5278 | | - opts (if doc (rest opts) opts) |
5279 | | - opts (reduce* (fn [m opt] |
5280 | | - (let [opt-name (first opt) |
5281 | | - options (rest opt)] |
5282 | | - (when-not (keyword? opt-name) |
5283 | | - (throw (ex-info "Namespace option must be a keyword" |
5284 | | - {:option opt-name}))) |
5285 | | - (assoc m opt-name (vec options)))) |
5286 | | - {} |
5287 | | - opts) |
| 5280 | + (let [doc (when (string? (first opts)) |
| 5281 | + (first opts)) |
| 5282 | + opts (if doc (rest opts) opts) |
| 5283 | + attr-map (when (map? (first opts)) |
| 5284 | + (first opts)) |
| 5285 | + metadata (merge (->> (meta name) |
| 5286 | + (remove #(= (namespace (key %)) "basilisp.lang.reader")) |
| 5287 | + (apply hash-map)) |
| 5288 | + {:doc doc} |
| 5289 | + attr-map) |
| 5290 | + opts (if attr-map (rest opts) opts) |
| 5291 | + opts (reduce* (fn [m opt] |
| 5292 | + (let [opt-name (first opt) |
| 5293 | + options (rest opt)] |
| 5294 | + (when-not (keyword? opt-name) |
| 5295 | + (throw (ex-info "Namespace option must be a keyword" |
| 5296 | + {:option opt-name}))) |
| 5297 | + (assoc m opt-name (vec options)))) |
| 5298 | + {} |
| 5299 | + opts) |
5288 | 5300 |
|
5289 | 5301 | refer-filters (when-let [filters (or (:refer-basilisp opts) |
5290 | 5302 | (:refer-clojure opts))] |
|
5300 | 5312 | `(^:use-var-indirection do |
5301 | 5313 | (in-ns (quote ~name)) |
5302 | 5314 | (swap! *loaded-libs* conj (quote ~name)) |
5303 | | - ~(when doc |
5304 | | - `(alter-meta! (the-ns (quote ~name)) assoc :doc ~doc)) |
| 5315 | + ~(when metadata |
| 5316 | + `(reset-meta! (the-ns (quote ~name)) ~metadata)) |
5305 | 5317 | (refer-basilisp ~@refer-filters) |
5306 | 5318 | ~requires |
5307 | 5319 | ~uses |
|
0 commit comments