Override "required" in Clojure?

Is it possible to override the require command to try to load a specific resource if it is not found on the local computer. For instance:

(require 'examples.introduction) 
; if not found => download from the net
;   (url: http://media.pragprog.com/titles/shcloj/code/examples/introduction.clj)
+5
source share
2 answers

You can override the function require, and, of course, the overriden option can upload files if the namespace it requests is not available in the classpath. Path redefinition :requireworks in forms (ns ...), it is AFAIK, it is impossible at present because of how it is processed ns.

, " require" , ( ), path Clojure (- JVM). clojure.core/add-classpath... , , , , . , , , .

require, foo,

(ns foo
  (:refer-clojure :exclude [require])
  ; other stuff; any :requires here will work as usual!
  )

, clojure.core/require, :

(defn require [ns-symbol]
  (do-stuff-to-obtain-the-namespace))

clojure.contrib.find-namespaces , . ( the-ns , , clojure.core/require.)

, binding, ((binding [require ...] ...)), , require Var, clojure.core, Vars , clojure ( , Var, Vars ).

(:refer-clojure :exclude [require]) ns require clojure.core/require Var . , clojure.core/require Var, .

+4

, (add-classpath " http://foo/bar/baz/src/" ) (add-classpath " http://www.foo.com/bar.jar" ), .

Michał : ...

+1

All Articles