Code Monkey home page Code Monkey logo

blog's People

Contributors

brucefengnju avatar

Watchers

 avatar

blog's Issues

Clojure ns require use import

ns

ns用来定义当前的命名空间,可以配合import,require,use进行使用。

    (ns foo.bar
      (:refer-clojure :exclude [ancestors printf])
      (:require [clojure.contrib sql sql.tests])
      (:use [my.lib this that])
      (:import [java.util Date Timer Random]
        (java.sql Connection Statement)))

require

require 是将clojure load进入当前的命名空间,会跳过已经load进来的lib。 :require可以配合 :as, :only, :include, :exclude, :refer, :all等等一起使用。

;; alias clojure.java.io as iouser=> (require '[clojure.java.io :as io])nil

user=> (io/file "Filename")#<File Filename>

;; alias clojure.java.io as io using prefixesuser=> (require '(clojure.java [io :as io2])nil

user=> (io2/file "Filename")#<File Filename>

use

use与require作用类似,但除了将libs load进入之外,还使用clojure.core/refer refer他们的namespaces。可以配合:exclude, :only, and :rename使用。

(ns some.namespace
  (:require [clojure.contrib.json :as json])
  (:use [clojure.string :only [trim lower-case split]]
        [clojure.contrib.shell-out]
        [clojure.pprint]
        [clojure.test]))

import

import主要用来加载java类。

    (import & import-symbols-or-lists)
    import-list => (package-symbol class-name-symbols*)
    (ns foo.bar
      (:import (java.util Date
                          Calendar)
               (java.util.logging Logger
                                  Level)))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.