Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I :require :refer in clojurescript?

See: https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure#namespaces

It bothers me that idiomatic clojure is:

(ns clojure-example
  (:require [clojure.set :refer [union]]))

But idiomatic clojurescript is:

(ns clojurescript-example
  (:use [clojure.set :only [union]]))

Of course, the clojurescript code would work in clojure as well, but that brings out demons who say I should use require with :refer instead!

What is the cause of this?

like image 868
ToBeReplaced Avatar asked Nov 19 '13 17:11

ToBeReplaced


1 Answers

Actually ClojureScript does support :require :refer and has supported it for a long while (here's my commit introducing support for :refer from 12 Jun 2012). That wiki page is out of date. I have edited the section on namespaces on the wiki to bring it up to date.

As for what is idiomatic, there are of course people who dislike :use, but that hardly makes it unidiomatic after several years of production use. You're free to make up your own mind as to whether you prefer :require :refer or not.

(Although the use case where :use actually offers capabilities that :require does not -- pulling in several namespaces with (:use lib.foo lib.bar lib.quux) -- is indeed not supported in ClojureScript, by design.)

like image 192
Michał Marczyk Avatar answered Oct 16 '22 03:10

Michał Marczyk