Movatterモバイル変換


[0]ホーム

URL:


Clojure

Clojure Core API Reference

Clojurev1.13.0 API
Namespaces
Other Versions
Clojure Home

API Overview -Clojurev1.13.0 (in development)


Important Clojure resources




clojure.core

Detailed API documentation
Fundamental library of the Clojure language
Contents:&**'*1*2*3*agent**assert**clojure-version**command-line-args**compile-files**compile-path**compiler-options**data-readers**default-data-reader-fn**e*err**file**flush-on-newline**in**ns**out**print-dup**print-length**print-level**print-meta**print-namespace-maps**print-readably**read-eval**repl**unchecked-math**warn-on-reflection*++'--'->->>->ArrayChunk->Eduction->Vec->VecNode->VecSeq.../<<====>>=absaccessoracloneadd-classpathadd-tapadd-watchagentagent-erroragent-errorsagetalengthaliasall-nsalteralter-meta!alter-var-rootamapancestorsandany?applyareducearray-mapArrayChunkas->asetaset-booleanaset-byteaset-charaset-doubleaset-floataset-intaset-longaset-shortassertassocassoc!assoc-inassociative?atomawaitawait-forbasesbeanbigdecbigintbigintegerbindingbit-andbit-and-notbit-clearbit-flipbit-notbit-orbit-setbit-shift-leftbit-shift-rightbit-testbit-xorbooleanboolean-arrayboolean?booleansbound-fnbound-fn*bound?bounded-countbutlastbytebyte-arraybytesbytes?casecastcatcatchcharchar-arraychar-escape-stringchar-name-stringchar?charsclassclass?clear-agent-errorsclojure-versioncoll?commentcommutecompcomparatorcomparecompare-and-set!compilecomplementcompletingconcatcondcond->cond->>condpconjconj!consconstantlyconstruct-proxycontains?countcounted?create-nscreate-structcycledecdec'decimal?declarededupedefdefault-data-readersdefinlinedefinterfacedefmacrodefmethoddefmultidefndefn-defoncedefprotocoldefrecorddefstructdeftypedelaydelay?deliverdenominatorderefderivedescendantsdisjdisj!dissocdissoc!distinctdistinct?dodoalldorundoseqdosyncdotimesdotodoubledouble-arraydouble?doublesdropdrop-lastdrop-whileeductionEductionemptyempty?ensureensure-reducedenumeration-seqerror-handlererror-modeevaleven?every-predevery?ex-causeex-dataex-infoex-messageextendextend-protocolextend-typeextendersextends?false?ffirstfile-seqfilterfiltervfinallyfindfind-keywordfind-nsfind-varfirstflattenfloatfloat-arrayfloat?floatsflushfnfn?fnextfnilforforceformatfrequenciesfuturefuture-callfuture-cancelfuture-cancelled?future-done?future?gen-classgen-interfacegensymgetget-inget-methodget-proxy-classget-thread-bindingsget-validatorgroup-byhalt-whenhashhash-maphash-ordered-collhash-sethash-unordered-collident?identical?identityifif-letif-notif-someifn?importin-nsincinc'indexed?infinite?init-proxyinst-msinst?instance?intint-arrayint?integer?interleaveinterninterposeintointo-arrayintsio!isa?iterateiterationiterator-seqjuxtkeepkeep-indexedkeykeyskeywordkeyword?lastlazy-catlazy-seqletletfnline-seqlistlist*list?loadload-fileload-readerload-stringloaded-libslockinglonglong-arraylongsloopmacroexpandmacroexpand-1make-arraymake-hierarchymapmap-entry?map-indexedmap?mapcatmapvmaxmax-keymemfnmemoizemergemerge-withmetamethodsminmin-keymix-collection-hashmodmonitor-entermonitor-exitnamenamespacenamespace-mungeNaN?nat-int?neg-int?neg?newnewlinenextnfirstnil?nnextnotnot-any?not-emptynot-every?not=nsns-aliasesns-importsns-internsns-mapns-namens-publicsns-refersns-resolvens-unaliasns-unmapnthnthnextnthrestnumnumber?numeratorobject-arrayodd?orparentsparse-booleanparse-doubleparse-longparse-uuidpartialpartitionpartition-allpartition-bypartitionvpartitionv-allpcallspeekpersistent!pmappoppop!pop-thread-bindingspos-int?pos?prpr-strprefer-methodprefersprintprint-strprintfprintlnprintln-strPrintWriter-onprnprn-strpromiseproxyproxy-mappingsproxy-superpush-thread-bindingspvaluesqualified-ident?qualified-keyword?qualified-symbol?quotquoterandrand-intrand-nthrandom-samplerandom-uuidrangeratio?rational?rationalizere-findre-groupsre-matcherre-matchesre-patternre-seqreadread+stringread-lineread-stringreader-conditionalreader-conditional?realized?record?recurreducereduce-kvreducedreduced?reductionsrefref-history-countref-max-historyref-min-historyref-setreferrefer-clojurereifyrelease-pending-sendsremremoveremove-all-methodsremove-methodremove-nsremove-tapremove-watchrepeatrepeatedlyreplacereplicaterequirerequiring-resolvereset!reset-meta!reset-vals!resolverestrestart-agentresultset-seqreversereversible?rseqrsubseqrun!satisfies?secondselect-keyssendsend-offsend-viaseqseq-to-map-for-destructuringseq?seqable?sequesequencesequential?setset!set-agent-send-executor!set-agent-send-off-executor!set-error-handler!set-error-mode!set-validator!set?shortshort-arrayshortsshuffleshutdown-agentssimple-ident?simple-keyword?simple-symbol?slurpsomesome->some->>some-fnsome?sortsort-bysorted-mapsorted-map-bysorted-setsorted-set-bysorted?special-symbol?spitsplit-atsplit-withsplitv-atStackTraceElement->vecstrstream-into!stream-reduce!stream-seq!stream-transduce!string?structstruct-mapsubssubseqsubvecsupersswap!swap-vals!symbolsymbol?synctagged-literaltagged-literal?taketake-lasttake-nthtake-whiletap>testthe-nsthread-bound?throwThrowable->maptimeto-arrayto-array-2dtrampolinetransducetransienttree-seqtrue?trytypeunchecked-addunchecked-add-intunchecked-byteunchecked-charunchecked-decunchecked-dec-intunchecked-divide-intunchecked-doubleunchecked-floatunchecked-incunchecked-inc-intunchecked-intunchecked-longunchecked-multiplyunchecked-multiply-intunchecked-negateunchecked-negate-intunchecked-remainder-intunchecked-shortunchecked-subtractunchecked-subtract-intunderiveunreducedunsigned-bit-shift-rightupdateupdate-inupdate-keysupdate-proxyupdate-valsuri?useuuid?valvalsvarvar-getvar-setvar?vary-metavecVecVecNodeVecSeqvectorvector-ofvector?volatile!volatile?vreset!vswap!whenwhen-firstwhen-letwhen-notwhen-somewhilewith-bindingswith-bindings*with-in-strwith-local-varswith-metawith-openwith-out-strwith-precisionwith-redefswith-redefs-fnxml-seqzero?zipmap

Variables and functions inclojure.core.protocols:coll-reduceCollReduceDatafiabledatafyIKVReduceinternal-reduceInternalReducekv-reducenavNavigable

Variables and functions inclojure.core.reducers:->Catappend!catCatdropfilterflattenfoldfoldcatfoldermapmapcatmonoidreducereducerremovetaketake-while

Variables and functions inclojure.core.server:io-preplpreplremote-preplreplrepl-initrepl-readstart-serverstart-serversstop-serverstop-servers

Variables and functions inclojure.core.specs.alpha:::as::as-alias::binding::binding-form::bindings::class-ident::constructors::defn-argseven-number-of-forms?::exclude::expose::exposes::extends::factory::filters::get::impl-ns::implements::import-list::init::keys::libspec::load-impl-ns::local-name::main::map-binding::map-binding-form::map-bindings::map-special-binding::method::methods::name::ns-clauses::ns-form::ns-gen-class::ns-import::ns-keys::ns-load::ns-refer::ns-refer-clojure::ns-require::ns-use::only::or::package-list::param-list::params+body::post-init::prefix::prefix-list::quotable-import-list::refer::rename::seq-binding-form::set::signature::state::strs::syms::use-libspec::use-prefix-list


clojure.data

byStuart Halloway
Detailed API documentation
Non-core data functions.
Contents:diffDiffdiff-similarequality-partitionEqualityPartition


clojure.datafy

Detailed API documentation
Functions to turn objects into data. Alpha, subject to change
Contents:datafynav


clojure.edn

byRich Hickey
Detailed API documentation
edn reading.
Contents:readread-string


clojure.inspector

byRich Hickey
Detailed API documentation
Graphical object inspector for Clojure data structures.
Contents:inspectinspect-tableinspect-tree


clojure.java.basis

Detailed API documentation
The lib basis includes which libraries and versions were loaded bothfor direct dependencies and transitive dependencies, as well as theclasspath and possibly other information from the resolution process.This basis will be known if the runtime was started by the Clojure CLI.The Clojure CLI or tools.deps merge a set of deps maps (often fromdeps.edn files). Additional runtime modifications are supplied via argmapkeys, provided via alias maps in the merged deps. Deps maps typically have:paths, :deps, and :aliases keys.The basis is a superset of merged deps.edn files with the followingadditional keys:  :basis-config - params used to configure basis deps sources, can be                  string path, deps map, nil, or :default    :root - default = loaded as a resource from tools.deps)    :user - default = ~/.clojure/deps.edn)    :project - default = ./deps.edn)    :extra - default = nil    :aliases - coll of keyword aliases to include during dep calculation  :argmap - effective argmap (after resolving and merging argmaps from aliases)  :libs - map of lib to coord for all included libraries  :classpath - classpath map, keys are paths (to directory or .jar), values               are maps with source identifier (either :lib-name or :path-key)  :classpath-roots - vector of paths in classpath order (keys of :classpath)
Contents:current-basisinitial-basis

Variables and functions inclojure.java.basis.impl:update-basis!


clojure.java.browse

byChristophe Grand
Detailed API documentation
Start a web browser from Clojure
Contents:browse-url


clojure.java.javadoc

byChristophe Grand, Stuart Sierra
Detailed API documentation
A repl helper to quickly open javadocs.
Contents:add-local-javadocadd-remote-javadocjavadoc


clojure.java.process

Detailed API documentation
A process invocation API wrapping the Java process API.The primary function is 'start' which starts a process and handles thestreams as directed. It returns the Process object. Use 'exit-ref' to waitfor completion and receive the exit value, and ‘stdout', 'stderr', 'stdin'to access the process streams. The 'exec' function handles the common caseto 'start' a process, wait for process exit, and return stdout.
Contents:execexit-reffrom-filestartstderrstdinstdoutto-file


clojure.java.shell

byChris Houser, Stuart Halloway
Detailed API documentation
Conveniently launch a sub-process providing its stdin andcollecting its stdout
Contents:shwith-sh-dirwith-sh-env


clojure.math

byAlex Miller
Detailed API documentation
Clojure wrapper functions for java.lang.Math static methods.Function calls are inlined for performance, and type hinted for primitivelong or double parameters where appropriate. In general, Math methods areoptimized for performance and have bounds for error tolerance. Ifgreater precision is needed, use java.lang.StrictMath directly instead.For more complete information, see:https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html
Contents:acosadd-exactasinatanatan2cbrtceilcopy-signcoscoshdecrement-exactEexpexpm1floorfloor-divfloor-modget-exponenthypotIEEE-remainderincrement-exactloglog10log1pmultiply-exactnegate-exactnext-afternext-downnext-upPIpowrandomrintroundscalbsignumsinsinhsqrtsubtract-exacttantanhto-degreesto-radiansulp


clojure.pprint

byTom Faulhaber
Detailed API documentation
A Pretty Printer for Clojureclojure.pprint implements a flexible system for printing structured datain a pleasing, easy-to-understand format. Basic use of the pretty printer is simple, just call pprint instead of println. More advanced users can use the building blocks provided to create custom output formats. Out of the box, pprint supports a simple structured format for basic data and a specialized format for Clojure source code. More advanced formats, including formats that don't look like Clojure data at all like XML and JSON, can be rendered by creating custom dispatch functions. In addition to the pprint function, this module contains cl-format, a text formatting function which is fully compatible with the format function in Common Lisp. Because pretty printing directives are directly integrated withcl-format, it supports very concise custom dispatch. It also providesa more powerful alternative to Clojure's standard format function.See documentation for pprint and cl-format for more information or complete documentation on the Clojure web site on GitHub.
Added in Clojure version 1.2
Contents:*print-base**print-miser-width**print-pprint-dispatch**print-pretty**print-radix**print-right-margin**print-suppress-namespaces*cl-formatcode-dispatchformatterformatter-outfresh-lineget-pretty-writerpppprintpprint-indentpprint-logical-blockpprint-newlinepprint-tabprint-length-loopprint-tableset-pprint-dispatchsimple-dispatchwith-pprint-dispatchwritewrite-out


clojure.reflect

byStuart Halloway
Detailed API documentation
Reflection on Host TypesAlpha - subject to change.Two main entry points: * type-reflect reflects on something that implements TypeReference.* reflect (for REPL use) reflects on the class of an instance, or  on a class if passed a classKey features:* Exposes the read side of reflection as pure data. Reflecting  on a type returns a map with keys :bases, :flags, and :members.* Canonicalizes class names as Clojure symbols. Types can extend  to the TypeReference protocol to indicate that they can be  unambiguously resolved as a type name. The canonical format  requires one non-Java-ish convention: array brackets are <>  instead of [] so they can be part of a Clojure symbol.* Pluggable Reflectors for different implementations. The default  JavaReflector is good when you have a class in hand, or use  the AsmReflector for "hands off" reflection without forcing  classes to load.Platform implementers must:* Create an implementation of Reflector.* Create one or more implementations of TypeReference.* def default-reflector to be an instance that satisfies Reflector.
Added in Clojure version 1.3
Contents:->AsmReflector->Constructor->Field->JavaReflector->MethodAsmReflectorClassResolverConstructordo-reflectFieldflag-descriptorsJavaReflectormap->Constructormap->Fieldmap->MethodMethodreflectReflectorresolve-classtype-reflecttypenameTypeReference


clojure.repl

byChris Houser, Christophe Grand, Stephen Gilardi, Michel Salim
Detailed API documentation
Utilities meant to be used interactively at the REPL
Contents:aproposdemungedirdir-fndocfind-docpstroot-causeset-break-handler!sourcesource-fnstack-element-strthread-stopper

Variables and functions inclojure.repl.deps:add-libadd-libssync-deps


clojure.stacktrace

byStuart Sierra
Detailed API documentation
Print stack traces oriented towards Clojure, not Java.
Contents:eprint-cause-traceprint-stack-traceprint-throwableprint-trace-elementroot-cause


clojure.string

byStuart Sierra, Stuart Halloway, David Liebke
Detailed API documentation
Clojure String utilitiesIt is poor form to (:use clojure.string). Instead, use requirewith :as to specify a prefix, e.g.(ns your.namespace.here  (:require [clojure.string :as str]))Design notes for clojure.string:1. Strings are objects (as opposed to sequences). As such, the   string being manipulated is the first argument to a function;   passing nil will result in a NullPointerException unless   documented otherwise. If you want sequence-y behavior instead,   use a sequence.2. Functions are generally not lazy, and call straight to host   methods where those are available and efficient.3. Functions take advantage of String implementation details to   write high-performing loop/recurs instead of using higher-order   functions. (This is not idiomatic in general-purpose application   code.)4. When a function is documented to accept a string argument, it   will take any implementation of the correct *interface* on the   host platform. In Java, this is CharSequence, which is more   general than String. In ordinary usage you will almost always   pass concrete strings. If you are doing something unusual,   e.g. passing a mutable implementation of CharSequence, then   thread-safety is your responsibility.
Contents:blank?capitalizeends-with?escapeincludes?index-ofjoinlast-index-oflower-casere-quote-replacementreplacereplace-firstreversesplitsplit-linesstarts-with?trimtrim-newlinetrimltrimrupper-case


clojure.template

byStuart Sierra
Detailed API documentation
Macros that expand to repeated copies of a template expression.
Contents:apply-templatedo-template


clojure.test

byStuart Sierra, with contributions and suggestions by Chas Emerick, Allen Rohner, and Stuart Halloway
Detailed API documentation
A unit testing framework.ASSERTIONSThe core of the library is the "is" macro, which lets you makeassertions of any arbitrary expression:(is (= 4 (+ 2 2)))(is (instance? Integer 256))(is (.startsWith "abcde" "ab"))You can type an "is" expression directly at the REPL, which willprint a message if it fails.    user> (is (= 5 (+ 2 2)))    FAIL in  (:1)    expected: (= 5 (+ 2 2))      actual: (not (= 5 4))    falseThe "expected:" line shows you the original expression, and the"actual:" shows you what actually happened.  In this case, itshows that (+ 2 2) returned 4, which is not = to 5.  Finally, the"false" on the last line is the value returned from theexpression.  The "is" macro always returns the result of theinner expression.There are two special assertions for testing exceptions.  The"(is (thrown? c ...))" form tests if an exception of class c isthrown:(is (thrown? ArithmeticException (/ 1 0))) "(is (thrown-with-msg? c re ...))" does the same thing and alsotests that the message on the exception matches the regularexpression re:(is (thrown-with-msg? ArithmeticException #"Divide by zero"                      (/ 1 0)))DOCUMENTING TESTS"is" takes an optional second argument, a string describing theassertion.  This message will be included in the error report.(is (= 5 (+ 2 2)) "Crazy arithmetic")In addition, you can document groups of assertions with the"testing" macro, which takes a string followed by any number ofassertions.  The string will be included in failure reports.Calls to "testing" may be nested, and all of the strings will bejoined together with spaces in the final report, in a stylesimilar to RSpec <http://rspec.info/>(testing "Arithmetic"  (testing "with positive integers"    (is (= 4 (+ 2 2)))    (is (= 7 (+ 3 4))))  (testing "with negative integers"    (is (= -4 (+ -2 -2)))    (is (= -1 (+ 3 -4)))))Note that, unlike RSpec, the "testing" macro may only be usedINSIDE a "deftest" or "with-test" form (see below).DEFINING TESTSThere are two ways to define tests.  The "with-test" macro takesa defn or def form as its first argument, followed by any numberof assertions.  The tests will be stored as metadata on thedefinition.(with-test    (defn my-function [x y]      (+ x y))  (is (= 4 (my-function 2 2)))  (is (= 7 (my-function 3 4))))As of Clojure SVN rev. 1221, this does not work with defmacro.Seehttp://code.google.com/p/clojure/issues/detail?id=51The other way lets you define tests separately from the rest ofyour code, even in a different namespace:(deftest addition  (is (= 4 (+ 2 2)))  (is (= 7 (+ 3 4))))(deftest subtraction  (is (= 1 (- 4 3)))  (is (= 3 (- 7 4))))This creates functions named "addition" and "subtraction", whichcan be called like any other function.  Therefore, tests can begrouped and composed, in a style similar to the test framework inPeter Seibel's "Practical Common Lisp"<http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html>(deftest arithmetic  (addition)  (subtraction))The names of the nested tests will be joined in a list, like"(arithmetic addition)", in failure reports.  You can use nestedtests to set up a context shared by several tests.RUNNING TESTSRun tests with the function "(run-tests namespaces...)":(run-tests 'your.namespace 'some.other.namespace)If you don't specify any namespaces, the current namespace isused.  To run all tests in all namespaces, use "(run-all-tests)".By default, these functions will search for all tests defined ina namespace and run them in an undefined order.  However, if youare composing tests, as in the "arithmetic" example above, youprobably do not want the "addition" and "subtraction" tests runseparately.  In that case, you must define a special functionnamed "test-ns-hook" that runs your tests in the correct order:(defn test-ns-hook []  (arithmetic))Note: test-ns-hook prevents execution of fixtures (see below).OMITTING TESTS FROM PRODUCTION CODEYou can bind the variable "*load-tests*" to false when loading orcompiling code in production.  This will prevent any tests frombeing created by "with-test" or "deftest".FIXTURESFixtures allow you to run code before and after tests, to set upthe context in which tests should be run.A fixture is just a function that calls another function passed asan argument.  It looks like this:(defn my-fixture [f]   Perform setup, establish bindings, whatever.  (f)  Then call the function we were passed.   Tear-down / clean-up code here. )Fixtures are attached to namespaces in one of two ways.  "each"fixtures are run repeatedly, once for each test function createdwith "deftest" or "with-test".  "each" fixtures are useful forestablishing a consistent before/after state for each test, likeclearing out database tables."each" fixtures can be attached to the current namespace like this:(use-fixtures :each fixture1 fixture2 ...)The fixture1, fixture2 are just functions like the example above.They can also be anonymous functions, like this:(use-fixtures :each (fn [f] setup... (f) cleanup...))The other kind of fixture, a "once" fixture, is only run once,around ALL the tests in the namespace.  "once" fixtures are usefulfor tasks that only need to be performed once, like establishingdatabase connections, or for time-consuming tasks.Attach "once" fixtures to the current namespace like this:(use-fixtures :once fixture1 fixture2 ...)Note: Fixtures and test-ns-hook are mutually incompatible.  If youare using test-ns-hook, fixture functions will *never* be run.SAVING TEST OUTPUT TO A FILEAll the test reporting functions write to the var *test-out*.  Bydefault, this is the same as *out*, but you can rebind it to anyPrintWriter.  For example, it could be a file opened withclojure.java.io/writer.EXTENDING TEST-IS (ADVANCED)You can extend the behavior of the "is" macro by defining newmethods for the "assert-expr" multimethod.  These methods arecalled during expansion of the "is" macro, so they should returnquoted forms to be evaluated.You can plug in your own test-reporting framework by rebindingthe "report" function: (report event)The 'event' argument is a map.  It will always have a :type key,whose value will be a keyword signaling the type of event beingreported.  Standard events with :type value of :pass, :fail, and:error are called when an assertion passes, fails, and throws anexception, respectively.  In that case, the event will also havethe following keys:  :expected   The form that was expected to be true  :actual     A form representing what actually occurred  :message    The string message given as an argument to 'is'The "testing" strings will be a list in "*testing-contexts*", andthe vars being tested will be a list in "*testing-vars*".Your "report" function should wrap any printing calls in the"with-test-out" macro, which rebinds *out* to the current valueof *test-out*.For additional event types, see the examples in the code.
Contents:*load-tests**stack-trace-depth*areassert-anyassert-predicatecompose-fixturesdeftestdeftest-do-reportfile-positionfunction?get-possibly-unbound-varinc-report-counterisjoin-fixturesreportrun-all-testsrun-testrun-test-varrun-testsset-testsuccessful?test-all-varstest-nstest-vartest-varstestingtesting-contexts-strtesting-vars-strtry-expruse-fixtureswith-testwith-test-out

Variables and functions inclojure.test.junit:with-junit-output

Variables and functions inclojure.test.tap:print-tap-diagnosticprint-tap-failprint-tap-passprint-tap-planwith-tap-output


clojure.tools.deps.interop

Detailed API documentation
Functions for invoking Java processes and invoking tools via the Clojure CLI.
Contents:invoke-tool


clojure.walk

byStuart Sierra
Detailed API documentation
This file defines a generic tree walker for Clojure datastructures.  It takes any data structure (list, vector, map, set,seq), calls a function on every element, and uses the return valueof the function in place of the original.  This makes it fairlyeasy to write recursive search-and-replace functions, as shown inthe examples.Note: "walk" supports all Clojure data structures EXCEPT mapscreated with sorted-map-by.  There is no (obvious) way to retrievethe sorting function.
Contents:keywordize-keysmacroexpand-allpostwalkpostwalk-demopostwalk-replaceprewalkprewalk-demoprewalk-replacestringify-keyswalk
Copyright 2007-2025 by Rich Hickey
Logo & site design byTom Hickey.
Clojure auto-documentation system by Tom Faulhaber.

[8]ページ先頭

©2009-2025 Movatter.jp