Share your thoughts in the 2024 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

In numerical code, it is often useful and idiomatic to replace clojure.core functions with augmented versions (e.g. clojure.core.matrix.operators defines + in a way that works with whole arrays, not just scalar numbers)

Currently there seems to be no way to avoid a warning in client code when a library does this, e.g.:

`
;; library namespace
(ns foo
(:refer-clojure :exclude [+]))
(def + clojure.core/+)

;; later on, in some other namespace
(require '[foo :refer :all])
=> WARNING: + already refers to: #'clojure.core/+ in namespace: bar, being replaced by: #'foo/+
`

A workaround exists by using (:refer-clojure :exclude ...) in the user namespace, however this creates unnecessary work for the user and requires maintenance of boilerplate code.

Proposed solution is to allow vars to be annotated with additional metadata (e.g. ^:replace-var ) that when added to library functions will suppress this warning. This will allow library authors to specify that a function should work as a drop-in replacement for clojure.core (or some other namespace), and that a warning is therefore not required.

4 Answers

0 votes
by

Comment made by: jafingerhut

Duplicate with CLJ-1257 ?

0 votes
by

Comment made by: mikera

Hi Andy, it refers to the same warning - but the scope of the solution is different:
- CLJ-1257 is more like a global way to turn off this warning
- CLJ-1592 is for suppressing this warning on specific vars

If CLJ-1257 is implemented and the warning is off be default, CLJ-1592 becomes mostly unnecessary. Without CLJ-1257 or if the warning defaults to on, CLJ-1592 is needed.

0 votes
by

Comment made by: jcburley

Another use case (of possibly questionable validity) is defining a function or macro that has the same name as something in clojure.core but is not intended as a drop-in replacement, rather something else entirely.

E.g. in my early efforts to learn Clojure, I'm trying out some coding examples and want to run (and time) various test cases against different versions of a function that is spec'ed to read from * . So I threw together a quick little bash-shell-like namespace defining macros named <, >, and >>, to do the "obvious" things (invoke the body of code with pertinent globals bound to a suitably opened file). Use case is something like:

(require ['com.burleyarch.bash :as bash]) (bash/< "path-to-input-file" (read-line))

It'd be nice to avoid warnings for that case as well, without anyone assuming the function/macro is intended as a "drop-in replacement" for any namespace.

(Yes, I realize that what I'm trying to do here is probably unsuitable for general consumption and/or duplicative of something already available....)

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-1592 (reported by mikera)
...