Aliasing core functions in Clojure

Question from rmxm

Funny question, how do you cover for "get" word being a function name, say you have namespace 'computer, surely it would be intuitive to have "get" function obtaining "computer". Just wondering how do you overcome this linguitically πŸ™‚ or do you just place get at the bottom

You are allowed to have a function named get - you just need to put (:refer-clojure :exclude [get]) in your namespace declaration to avoid warnings.

And then you refer to the core get as clojure.core/get within that file.

so

(ns some.computer
  (:refer-clojure :exclude [get]))

(defn get [o]
  (clojure.core/get o :thing))

or

(ns some.computer
  (:require [clojure.core :as core])
  (:refer-clojure :exclude [get]))

(defn get [o]
  (core/get o :thing))

sure, sure its not a technical question more of, do you use a different function name, or do you choose another word etc.

I do this with update in some contexts.

No I just use get if I want to - but you have to be more specific about the use case for me to give a better name.

You can usually call it get-thing or thing

If you mention both get and update in this case I will assume this is ok practice

its fine, depends on your domain

sure, sure, thanks πŸ™‚

I could also get* or something like that for, "c/grud" stuff, get*, update*, delete*, create* seems, ok I think

if the intended usage of the namespace is :require [a.b.thing :as thing], thing/func and the ns is small and focused (enough that you wont forget you shadowed a core fn) then don’t worry about it

thanks, going the get* route, this less bother down the road i think


<- Index