├── src
├── resources
│ └── clojure
│ │ └── version.properties
├── jvm
│ └── clojure
│ │ ├── storm
│ │ ├── IForm.java
│ │ ├── FormRegistry.java
│ │ └── FormLocation.java
│ │ ├── lang
│ │ ├── IType.java
│ │ ├── IRecord.java
│ │ ├── Sequential.java
│ │ ├── Fn.java
│ │ ├── IPending.java
│ │ ├── IHashEq.java
│ │ ├── IReduceInit.java
│ │ ├── Seqable.java
│ │ ├── IKVReduce.java
│ │ ├── Reversible.java
│ │ ├── IMeta.java
│ │ ├── IPersistentList.java
│ │ ├── IndexedSeq.java
│ │ ├── MapEquivalence.java
│ │ ├── IReduce.java
│ │ ├── ILookupThunk.java
│ │ ├── Named.java
│ │ ├── IBlockingDeref.java
│ │ ├── IKeywordLookup.java
│ │ ├── ILookupSite.java
│ │ ├── IObj.java
│ │ ├── IEditableCollection.java
│ │ ├── IMapEntry.java
│ │ ├── Settable.java
│ │ ├── ILookup.java
│ │ ├── Indexed.java
│ │ ├── Box.java
│ │ ├── IChunk.java
│ │ ├── Counted.java
│ │ ├── IPersistentStack.java
│ │ ├── ITransientAssociative2.java
│ │ ├── Repl.java
│ │ ├── ITransientCollection.java
│ │ ├── Script.java
│ │ ├── IReference.java
│ │ ├── ITransientAssociative.java
│ │ ├── Reduced.java
│ │ ├── IChunkedSeq.java
│ │ ├── ITransientVector.java
│ │ ├── Associative.java
│ │ ├── IPersistentCollection.java
│ │ ├── ITransientSet.java
│ │ ├── IPersistentSet.java
│ │ ├── IPersistentMap.java
│ │ ├── IPersistentVector.java
│ │ ├── IProxy.java
│ │ ├── ITransientMap.java
│ │ ├── Sorted.java
│ │ ├── package.html
│ │ ├── IMapIterable.java
│ │ ├── Binding.java
│ │ ├── IRef.java
│ │ ├── Volatile.java
│ │ ├── IExceptionInfo.java
│ │ ├── IAtom2.java
│ │ ├── IAtom.java
│ │ ├── WarnBoxedMath.java
│ │ ├── ISeq.java
│ │ ├── SeqEnumeration.java
│ │ ├── ChunkBuffer.java
│ │ ├── Obj.java
│ │ ├── ArityException.java
│ │ ├── IDrop.java
│ │ ├── MapEntry.java
│ │ ├── AReference.java
│ │ ├── IDeref.java
│ │ ├── SeqIterator.java
│ │ ├── ATransientSet.java
│ │ ├── Cons.java
│ │ ├── ExceptionInfo.java
│ │ ├── Tuple.java
│ │ ├── RecordIterator.java
│ │ ├── Delay.java
│ │ ├── KeywordLookupSite.java
│ │ ├── LazilyPersistentVector.java
│ │ ├── ChunkedCons.java
│ │ ├── AFunction.java
│ │ ├── TaggedLiteral.java
│ │ ├── ArrayChunk.java
│ │ ├── FnLoaderThunk.java
│ │ ├── ReaderConditional.java
│ │ ├── StringSeq.java
│ │ ├── IteratorSeq.java
│ │ ├── EnumerationSeq.java
│ │ ├── ARef.java
│ │ ├── ProxyHandler.java
│ │ ├── Ratio.java
│ │ ├── MethodImplCache.java
│ │ └── XMLHandler.java
│ │ ├── main.java
│ │ ├── asm
│ │ ├── commons
│ │ │ └── TableSwitchGenerator.java
│ │ └── CurrentFrame.java
│ │ └── java
│ │ └── api
│ │ └── package.html
├── script
│ ├── run_test_generative.clj
│ ├── run_test.clj
│ └── run_storm_test.clj
├── clj
│ └── clojure
│ │ ├── uuid.clj
│ │ ├── java
│ │ ├── browse_ui.clj
│ │ ├── basis
│ │ │ └── impl.clj
│ │ └── basis.clj
│ │ ├── pprint
│ │ └── print_table.clj
│ │ ├── edn.clj
│ │ ├── template.clj
│ │ ├── storm
│ │ └── repl.clj
│ │ ├── pprint.clj
│ │ └── datafy.clj
└── assembly
│ ├── slim.xml
│ └── distribution.xml
├── Makefile
├── test
├── java
│ ├── clojure
│ │ ├── test
│ │ │ ├── GenericInterface.java
│ │ │ ├── ConcreteClass.java
│ │ │ ├── FIConstructor.java
│ │ │ ├── ReflectorTryCatchFixture.java
│ │ │ ├── FIStatic.java
│ │ │ ├── FunctionalTester.java
│ │ │ └── SwissArmy.java
│ │ └── testfixtures
│ │ │ ├── MyView.java
│ │ │ └── Component.java
│ ├── compilation
│ │ ├── JDK8InterfaceMethods.java
│ │ ├── TestDispatch.java
│ │ └── ClassWithFailingStaticInitialiser.java
│ └── reflector
│ │ └── IBar.java
└── clojure
│ └── test_clojure
│ ├── repl
│ ├── example.clj
│ └── deps.clj
│ ├── compilation
│ ├── load_ns.clj
│ └── examples.clj
│ ├── protocols
│ ├── more_examples.clj
│ └── examples.clj
│ ├── storm_typehint_bug.clj
│ ├── storm_test_code
│ ├── core_async.clj
│ ├── functions.clj
│ ├── types.clj
│ ├── hints.clj
│ └── bodies.clj
│ ├── ns_libs_load_later.clj
│ ├── refs.clj
│ ├── annotations.clj
│ ├── storm_core_async.clj
│ ├── pprint.clj
│ ├── clojure_zip.clj
│ ├── volatiles.clj
│ ├── clojure_xml.clj
│ ├── proxy
│ └── examples.clj
│ ├── java
│ ├── process.clj
│ ├── javadoc.clj
│ └── shell.clj
│ ├── pprint
│ └── test_helper.clj
│ ├── parallel.clj
│ ├── run_single_test.clj
│ ├── edn.clj
│ ├── data.clj
│ ├── keywords.clj
│ ├── storm_utils.clj
│ ├── try_catch.clj
│ ├── api.clj
│ ├── server.clj
│ ├── atoms.clj
│ ├── fn.clj
│ ├── test_fixtures.clj
│ ├── reflect.clj
│ ├── repl.clj
│ ├── method_thunks.clj
│ └── clojure_walk.clj
├── .gitignore
├── .github
├── workflows
│ ├── snapshot.yml
│ ├── release.yml
│ ├── test.yml
│ └── doc-build.yml
└── PULL_REQUEST_TEMPLATE
├── antsetup.sh
└── CONTRIBUTING.md
/src/resources/clojure/version.properties:
--------------------------------------------------------------------------------
1 | version=${version}
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | install:
2 | mvn -Dmaven.test.skip=true clean
3 | mvn -Dmaven.test.skip=true package
4 | mvn -Dmaven.test.skip=true install
5 |
--------------------------------------------------------------------------------
/test/java/clojure/test/GenericInterface.java:
--------------------------------------------------------------------------------
1 | package clojure.test;
2 |
3 | public interface GenericInterface {
4 | T stampWidgets(T val);
5 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.jar
2 | target
3 | clojure.iws
4 | clojure.ipr
5 | nbproject/private/
6 | maven-classpath
7 | maven-classpath.properties
8 | .idea/
9 | *.iml
10 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/repl/example.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.repl.example)
2 |
3 | ;; sample namespace for repl tests, don't add anything here
4 | (defn foo [])
5 | (defn bar [])
6 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/compilation/load_ns.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.compilation.load-ns)
2 |
3 | (defn a [] 1)
4 | (defprotocol p (f [_]))
5 | (deftype x []
6 | :load-ns true
7 | p (f [_] (a)))
8 |
--------------------------------------------------------------------------------
/.github/workflows/snapshot.yml:
--------------------------------------------------------------------------------
1 | name: Snapshot on demand
2 |
3 | on: [workflow_dispatch]
4 |
5 | jobs:
6 | call-snapshot:
7 | uses: clojure/build.ci/.github/workflows/snapshot.yml@master
8 | secrets: inherit
9 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE:
--------------------------------------------------------------------------------
1 | Hi! This project does not accept pull requests.
2 |
3 | Please see the guidelines for contribution on how to file issues or provide patches:
4 |
5 | https://github.com/clojure/clojure/blob/master/CONTRIBUTING.md
6 |
--------------------------------------------------------------------------------
/test/java/clojure/test/ConcreteClass.java:
--------------------------------------------------------------------------------
1 | package clojure.test;
2 |
3 | public class ConcreteClass implements GenericInterface {
4 | @Override
5 | public Integer stampWidgets(Integer val) {
6 | return 42;
7 | }
8 | }
--------------------------------------------------------------------------------
/src/jvm/clojure/storm/IForm.java:
--------------------------------------------------------------------------------
1 | package clojure.storm;
2 |
3 | import clojure.lang.Keyword;
4 |
5 | interface IForm {
6 | Object getForm();
7 | Integer getId();
8 | String getNs();
9 | String getSourceFile();
10 | int getLine();
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/protocols/more_examples.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.protocols.more-examples)
2 |
3 | (defprotocol SimpleProtocol
4 | "example protocol used by clojure tests. Note that
5 | foo collides with examples/ExampleProtocol."
6 |
7 | (foo [a] ""))
8 |
--------------------------------------------------------------------------------
/src/script/run_test_generative.clj:
--------------------------------------------------------------------------------
1 | (System/setProperty "java.awt.headless" "true")
2 | (when-not (System/getProperty "clojure.test.generative.msec")
3 | (System/setProperty "clojure.test.generative.msec" "60000"))
4 | (require '[clojure.test.generative.runner :as runner])
5 | (runner/-main "test")
6 |
--------------------------------------------------------------------------------
/antsetup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | mvn -q dependency:build-classpath -Dmdep.outputFile=maven-classpath
4 | cat <maven-classpath.properties
5 | maven.compile.classpath=`cat maven-classpath`
6 | maven.test.classpath=`cat maven-classpath`
7 | EOF
8 | echo "Wrote maven-classpath.properties for standalone ant use"
9 |
--------------------------------------------------------------------------------
/test/java/compilation/JDK8InterfaceMethods.java:
--------------------------------------------------------------------------------
1 | package compilation;
2 |
3 | public interface JDK8InterfaceMethods {
4 | public static long staticMethod0(long v) { return v; }
5 | public static String staticMethod1(String s) { return s; }
6 | public static boolean staticMethod2(boolean b) { return b; }
7 | }
8 |
--------------------------------------------------------------------------------
/test/java/reflector/IBar.java:
--------------------------------------------------------------------------------
1 | package reflector;
2 |
3 | public interface IBar {
4 | String stuff();
5 |
6 | class Factory {
7 | public static IBar get() {
8 | return new SubBar();
9 | }
10 | }
11 | }
12 |
13 | class Bar {
14 | public String stuff() {
15 | return "stuff";
16 | }
17 | }
18 |
19 | class SubBar extends Bar implements IBar {
20 | }
21 |
--------------------------------------------------------------------------------
/test/java/compilation/TestDispatch.java:
--------------------------------------------------------------------------------
1 | package compilation;
2 |
3 | public class TestDispatch {
4 | public static String someMethod (int a, int b) {
5 | return "(int, int)";
6 | }
7 |
8 | public static String someMethod (int a, long b) {
9 | return "(int, long)";
10 | }
11 |
12 | public static String someMethod (long a, long b) {
13 | return "(long, long)";
14 | }
15 | }
--------------------------------------------------------------------------------
/src/script/run_test.clj:
--------------------------------------------------------------------------------
1 | (System/setProperty "java.awt.headless" "true")
2 | (require
3 | '[clojure.test :as test]
4 | '[clojure.tools.namespace.find :as ns])
5 | (def namespaces (remove (read-string (System/getProperty "clojure.test-clojure.exclude-namespaces"))
6 | (ns/find-namespaces-in-dir (java.io.File. "test"))))
7 | (doseq [ns namespaces] (require ns))
8 | (let [summary (apply test/run-tests namespaces)]
9 | (System/exit (if (test/successful? summary) 0 -1)))
10 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/storm_typehint_bug.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.storm-typehint-bug
2 | (:require
3 | [clojure.test :refer [deftest is testing]]
4 | [clojure.test-clojure.storm-test-code.hints :as hints]))
5 |
6 | (deftest wrong-type-hint-falls-back-to-reflection-test
7 | (testing "Flow-Storm instrumentation matches Clojure's fallback for incorrect hints"
8 | (is (thrown? java.lang.ClassCastException (hints/form-1)))
9 | (is (some? (hints/form-2)))
10 | (is (some? (hints/form-3)))))
11 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/storm_test_code/core_async.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.storm-test-code.core-async
2 | (:require [clojure.core.async :as async]))
3 |
4 | (defn produce [c]
5 | (async/go-loop [[i & r] (range 10)]
6 | (if i
7 | (do
8 | (async/>! c i)
9 | (recur r))
10 | (async/>! c :done))))
11 |
12 | (defn consume [c]
13 | (async/go-loop [v (async/ numbers;
10 |
11 | public FIConstructor(Predicate pred) {
12 | List numbers = Arrays.asList(-2, -1, 0, 1, 2);
13 | Object[] filteredNumbers = numbers.stream().filter(pred).toArray();
14 | this.numbers = Arrays.asList(filteredNumbers);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/test/java/compilation/ClassWithFailingStaticInitialiser.java:
--------------------------------------------------------------------------------
1 | package compilation;
2 |
3 | public class ClassWithFailingStaticInitialiser {
4 | static {
5 | // Static analysis refuses to compile a static initialiser
6 | // which will always throw, so we pretend to branch. This may
7 | // need updating if the static analysis gets cleverer in the
8 | // future
9 | if(true) {
10 | throw new AssertionError("Static Initialiser was run when it shouldn't have been");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release on demand
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | releaseVersion:
7 | description: "Version to release"
8 | required: true
9 | snapshotVersion:
10 | description: "Snapshot version after release"
11 | required: true
12 |
13 | jobs:
14 | call-release:
15 | uses: clojure/build.ci/.github/workflows/release.yml@master
16 | with:
17 | releaseVersion: ${{ github.event.inputs.releaseVersion }}
18 | snapshotVersion: ${{ github.event.inputs.snapshotVersion }}
19 | secrets: inherit
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | public interface IType {
14 | }
15 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IRecord.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | public interface IRecord {
14 | }
15 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Sequential.java:
--------------------------------------------------------------------------------
1 | package clojure.lang;
2 |
3 | /**
4 | * Copyright (c) Rich Hickey. All rights reserved.
5 | * The use and distribution terms for this software are covered by the
6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
7 | * which can be found in the file epl-v10.html at the root of this distribution.
8 | * By using this software in any fashion, you are agreeing to be bound by
9 | * the terms of this license.
10 | * You must not remove this notice, or any other, from this software.
11 | */
12 | public interface Sequential {
13 | }
14 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Fn.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Nov 25, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | public interface Fn{
16 | }
17 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IPending.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | public interface IPending{
14 | boolean isRealized();
15 | }
16 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/compilation/examples.clj:
--------------------------------------------------------------------------------
1 | ;; Copyright (c) Rich Hickey. All rights reserved.
2 | ;; The use and distribution terms for this software are covered by the
3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ;; which can be found in the file epl-v10.html at the root of this distribution.
5 | ;; By using this software in any fashion, you are agreeing to be bound by
6 | ;; the terms of this license.
7 | ;; You must not remove this notice, or any other, from this software.
8 |
9 | (ns clojure.test-clojure.compilation.examples)
10 |
11 | (eval '(deftype X []))
12 | (deftype T [])
13 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/protocols/examples.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.protocols.examples)
2 |
3 | (defprotocol ExampleProtocol
4 | "example protocol used by clojure tests"
5 |
6 | (foo [a] "method with one arg")
7 | (bar [a b] "method with two args")
8 | (^String baz [a] [a b] "method with multiple arities")
9 | (with-quux [a] "method name with a hyphen"))
10 |
11 | (defprotocol MarkerProtocol
12 | "a protocol with no methods")
13 |
14 | (defprotocol MarkerProtocol2)
15 |
16 | (definterface ExampleInterface
17 | (hinted [^int i])
18 | (hinted [^String s]))
19 |
20 | (defprotocol LongsHintedProto
21 | (^longs longs-hinted [_]))
22 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IHashEq.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich 10/23/11 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IHashEq{
16 | int hasheq();
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IReduceInit.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | public interface IReduceInit{
14 | Object reduce(IFn f, Object start) ;
15 | }
16 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Seqable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jan 28, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface Seqable {
16 | ISeq seq();
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IKVReduce.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich 7/20/15 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IKVReduce{
16 | Object kvreduce(IFn f, Object init);
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Reversible.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jan 5, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | public interface Reversible{
16 | ISeq rseq() ;
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IMeta.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Dec 31, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IMeta {
16 | IPersistentMap meta();
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IPersistentList.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | */
10 |
11 | package clojure.lang;
12 |
13 |
14 | public interface IPersistentList extends Sequential, IPersistentStack{
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IndexedSeq.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | */
10 |
11 | package clojure.lang;
12 |
13 | public interface IndexedSeq extends ISeq, Sequential, Counted{
14 |
15 | public int index();
16 | }
17 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/MapEquivalence.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Aug 4, 2010 */
12 |
13 | package clojure.lang;
14 |
15 | //marker interface
16 | public interface MapEquivalence{
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IReduce.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jun 11, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IReduce extends IReduceInit{
16 | Object reduce(IFn f) ;
17 | }
18 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/ns_libs_load_later.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ;; used by clojure.test-clojure.ns-libs/require-as-alias-then-load-later
10 | (ns clojure.test-clojure.ns-libs-load-later)
11 |
12 | (defn example [] true)
13 |
--------------------------------------------------------------------------------
/test/java/clojure/test/ReflectorTryCatchFixture.java:
--------------------------------------------------------------------------------
1 | package clojure.test;
2 |
3 | public class ReflectorTryCatchFixture {
4 |
5 | public static void fail(Long x) throws Cookies {
6 | throw new Cookies("Long");
7 | }
8 |
9 | public static void fail(Double y) throws Cookies {
10 | throw new Cookies("Double");
11 | }
12 |
13 | public void failWithCause(Double y) throws Cookies {
14 | throw new Cookies("Wrapped", new Cookies("Cause"));
15 | }
16 |
17 | public static class Cookies extends Exception {
18 | public Cookies(String msg, Throwable cause) { super(msg, cause); }
19 | public Cookies(String msg) { super(msg); }
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ILookupThunk.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Nov 2, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface ILookupThunk{
16 |
17 | Object get(Object target);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Named.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Sep 20, 2007 */
12 |
13 | package clojure.lang;
14 |
15 | public interface Named{
16 | String getNamespace();
17 |
18 | String getName();
19 | }
20 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IBlockingDeref.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich 3/18/11 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IBlockingDeref{
16 | Object deref(long ms, Object timeoutValue) ;
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IKeywordLookup.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Oct 31, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IKeywordLookup{
16 | ILookupThunk getLookupThunk(Keyword k);
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ILookupSite.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Nov 2, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface ILookupSite{
16 |
17 | ILookupThunk fault(Object target);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IObj.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 |
14 | public interface IObj extends IMeta {
15 |
16 | public IObj withMeta(IPersistentMap meta);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IEditableCollection.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jul 17, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IEditableCollection{
16 | ITransientCollection asTransient();
17 | }
18 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IMapEntry.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | */
10 |
11 | package clojure.lang;
12 |
13 | import java.util.Map;
14 |
15 | public interface IMapEntry extends Map.Entry{
16 | Object key();
17 |
18 | Object val();
19 | }
20 |
--------------------------------------------------------------------------------
/test/java/clojure/testfixtures/MyView.java:
--------------------------------------------------------------------------------
1 | package clojure.testfixtures;
2 |
3 | public class MyView {
4 |
5 | private final String id;
6 |
7 | private MyView(String id) {
8 | this.id = id;
9 | }
10 |
11 | public String id() {
12 | return id;
13 | }
14 |
15 | public static Builder newBuilder() {
16 | return new Builder();
17 | }
18 |
19 | public static final class Builder {
20 | private String id = "";
21 |
22 | public Builder withId(String id) {
23 | this.id = id;
24 | return this;
25 | }
26 |
27 | public MyView build() {
28 | return new MyView(id);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Settable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Dec 31, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | public interface Settable {
16 | Object doSet(Object val) ;
17 | Object doReset(Object val) ;
18 | }
19 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ILookup.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Aug 2, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface ILookup{
16 | Object valAt(Object key);
17 |
18 | Object valAt(Object key, Object notFound);
19 | }
20 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Indexed.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich May 24, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface Indexed extends Counted{
16 | Object nth(int i);
17 |
18 | Object nth(int i, Object notFound);
19 | }
20 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Box.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Mar 27, 2006 8:40:19 PM */
12 |
13 | package clojure.lang;
14 |
15 | public class Box{
16 |
17 | public Object val;
18 |
19 | public Box(Object val){
20 | this.val = val;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IChunk.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jun 18, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IChunk extends Indexed{
16 |
17 | IChunk dropFirst();
18 |
19 | Object reduce(IFn f, Object start) ;
20 | }
21 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Counted.java:
--------------------------------------------------------------------------------
1 | package clojure.lang;
2 |
3 | /**
4 | * Copyright (c) Rich Hickey. All rights reserved.
5 | * The use and distribution terms for this software are covered by the
6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
7 | * which can be found in the file epl-v10.html at the root of this distribution.
8 | * By using this software in any fashion, you are agreeing to be bound by
9 | * the terms of this license.
10 | * You must not remove this notice, or any other, from this software.
11 | */
12 |
13 | /* A class that implements Counted promises that it is a collection
14 | * that implement a constant-time count() */
15 |
16 | public interface Counted {
17 | int count();
18 | }
19 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IPersistentStack.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Sep 19, 2007 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IPersistentStack extends IPersistentCollection{
16 | Object peek();
17 |
18 | IPersistentStack pop();
19 | }
20 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/storm_test_code/functions.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.storm-test-code.functions)
2 |
3 | (defn empty-body [a b])
4 |
5 | (defn simple [a b]
6 | (+ a b))
7 |
8 | (def defed (fn [] 42))
9 |
10 | (defn multi-arity
11 | ([a] (multi-arity a 2))
12 | ([a b] (+ a b)))
13 |
14 | (defn args-destructuring [{:keys [a b]} c [d e]]
15 | (+ a b c d e))
16 |
17 | (defn variadic [& nums]
18 | (reduce + nums))
19 |
20 | (defn tail-recursive [s n]
21 | (if (zero? n)
22 | s
23 | (recur (+ s n) (dec n))))
24 |
25 | (defn factorial [n]
26 | (if (zero? n)
27 | 1
28 | (* n (factorial (dec n)))))
29 |
30 | (defmulti area :type)
31 |
32 | (defmethod area :square
33 | [{:keys [side]}]
34 | (* side side))
35 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ITransientAssociative2.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | public interface ITransientAssociative2 extends ITransientAssociative {
14 | boolean containsKey(Object key);
15 | IMapEntry entryAt(Object key);
16 | }
17 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Repl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Oct 18, 2007 */
12 |
13 | package clojure.lang;
14 |
15 | import clojure.main;
16 |
17 | public class Repl {
18 |
19 | public static void main(String[] args) {
20 | main.legacy_repl(args);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ITransientCollection.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jul 17, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface ITransientCollection{
16 |
17 | ITransientCollection conj(Object val);
18 |
19 | IPersistentCollection persistent();
20 | }
21 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Script.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Oct 18, 2007 */
12 |
13 | package clojure.lang;
14 |
15 | import clojure.main;
16 |
17 | public class Script {
18 |
19 | public static void main(String[] args) {
20 | main.legacy_script(args);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IReference.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Dec 31, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IReference extends IMeta {
16 | IPersistentMap alterMeta(IFn alter, ISeq args) ;
17 | IPersistentMap resetMeta(IPersistentMap m);
18 | }
19 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ITransientAssociative.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jul 17, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface ITransientAssociative extends ITransientCollection, ILookup{
16 |
17 | ITransientAssociative assoc(Object key, Object val);
18 | }
19 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Reduced.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | public final class Reduced implements IDeref{
14 | Object val;
15 |
16 | public Reduced(Object val){
17 | this.val = val;
18 | }
19 |
20 | public Object deref(){
21 | return val;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IChunkedSeq.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich May 24, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface IChunkedSeq extends ISeq, Sequential {
16 |
17 | IChunk chunkedFirst() ;
18 |
19 | ISeq chunkedNext() ;
20 |
21 | ISeq chunkedMore() ;
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ITransientVector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jul 17, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public interface ITransientVector extends ITransientAssociative, Indexed{
16 |
17 | ITransientVector assocN(int i, Object val);
18 |
19 | ITransientVector pop();
20 | }
21 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 |
3 | on:
4 | push:
5 | workflow_dispatch:
6 |
7 | jobs:
8 | test:
9 | strategy:
10 | fail-fast: false
11 | matrix:
12 | os: [ubuntu-latest] # macOS-latest, windows-latest]
13 | java-version: ["8", "11", "17", "21"]
14 | distribution: ["temurin", "corretto"]
15 | profile: ["test-direct", "test-no-direct"]
16 | runs-on: ${{ matrix.os }}
17 | steps:
18 | - uses: actions/checkout@v4
19 | - name: Set up Java
20 | uses: actions/setup-java@v4
21 | with:
22 | java-version: ${{ matrix.java-version }}
23 | distribution: ${{ matrix.distribution }}
24 | cache: 'maven'
25 | - name: Build with Maven
26 | run: mvn -ntp -B -P${{ matrix.profile }} clean test
27 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Associative.java:
--------------------------------------------------------------------------------
1 | package clojure.lang;
2 |
3 | /**
4 | * Copyright (c) Rich Hickey. All rights reserved.
5 | * The use and distribution terms for this software are covered by the
6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
7 | * which can be found in the file epl-v10.html at the root of this distribution.
8 | * By using this software in any fashion, you are agreeing to be bound by
9 | * the terms of this license.
10 | * You must not remove this notice, or any other, from this software.
11 | */
12 | public interface Associative extends IPersistentCollection, ILookup{
13 | boolean containsKey(Object key);
14 |
15 | IMapEntry entryAt(Object key);
16 |
17 | Associative assoc(Object key, Object val);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/refs.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ; Author: Frantisek Sodomka
10 |
11 |
12 | (ns clojure.test-clojure.refs
13 | (:use clojure.test))
14 |
15 | ; http://clojure.org/refs
16 |
17 | ; ref
18 | ; deref, @-reader-macro
19 | ; dosync io!
20 | ; ensure ref-set alter commute
21 | ; set-validator get-validator
22 |
23 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IPersistentCollection.java:
--------------------------------------------------------------------------------
1 | package clojure.lang;
2 |
3 | /**
4 | * Copyright (c) Rich Hickey. All rights reserved.
5 | * The use and distribution terms for this software are covered by the
6 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
7 | * which can be found in the file epl-v10.html at the root of this distribution.
8 | * By using this software in any fashion, you are agreeing to be bound by
9 | * the terms of this license.
10 | * You must not remove this notice, or any other, from this software.
11 | */
12 |
13 |
14 | public interface IPersistentCollection extends Seqable {
15 |
16 | int count();
17 |
18 | IPersistentCollection cons(Object o);
19 |
20 | IPersistentCollection empty();
21 |
22 | boolean equiv(Object o);
23 | }
24 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ITransientSet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Mar 3, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | public interface ITransientSet extends ITransientCollection, Counted{
16 | public ITransientSet disjoin(Object key) ;
17 | public boolean contains(Object key);
18 | public Object get(Object key);
19 | }
20 |
--------------------------------------------------------------------------------
/test/java/clojure/test/FIStatic.java:
--------------------------------------------------------------------------------
1 | package clojure.test;
2 |
3 | import java.util.Arrays;
4 | import java.util.List;
5 | import java.util.function.Predicate;
6 |
7 | public class FIStatic {
8 |
9 | public static List
15 | *
ISeqs are immutable values, i.e. neither first(), nor rest() changes
16 | * or invalidates the ISeq
17 | */
18 | public interface ISeq extends IPersistentCollection {
19 |
20 | Object first();
21 |
22 | ISeq next();
23 |
24 | ISeq more();
25 |
26 | ISeq cons(Object o);
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/pprint.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ;; Author: Tom Faulhaber
10 |
11 | (ns clojure.test-clojure.pprint
12 | (:refer-clojure :exclude [format])
13 | (:require [clojure.string :as str])
14 | (:use [clojure.test :only (deftest is are run-tests)]
15 | [clojure.test-helper :only [platform-newlines]]
16 | clojure.test-clojure.pprint.test-helper
17 | clojure.pprint))
18 |
19 | (load "pprint/test_cl_format")
20 | (load "pprint/test_pretty")
21 |
--------------------------------------------------------------------------------
/src/script/run_storm_test.clj:
--------------------------------------------------------------------------------
1 | (System/setProperty "java.awt.headless" "true")
2 | ;; (clojure.storm.Emitter/setInstrumentationEnable true)
3 | ;; (clojure.storm.Emitter/addInstrumentationOnlyPrefix "clojure.test-clojure.storm-test-code")
4 | (require
5 | '[clojure.string :as str]
6 | '[clojure.test :as test]
7 | '[clojure.tools.namespace.find :as ns])
8 | (def namespaces (filter (fn [ns-symb]
9 | (str/includes? (str ns-symb) "storm"))
10 | (ns/find-namespaces-in-dir (java.io.File. "test"))))
11 | (println "Instrumenting everything under: " (->> (clojure.storm.Emitter/getInstrumentationOnlyPrefixes)
12 | (map #(clojure.lang.Compiler/demunge %))
13 | (str/join ",")))
14 | (doseq [ns namespaces] (require ns))
15 | (let [summary (apply test/run-tests namespaces)]
16 | (System/exit (if (test/successful? summary) 0 -1)))
17 |
--------------------------------------------------------------------------------
/src/assembly/slim.xml:
--------------------------------------------------------------------------------
1 |
2 | slim
3 |
4 | jar
5 |
6 | false
7 |
8 |
9 | src/clj
10 | /
11 |
12 |
13 | src/resources
14 | /
15 | true
16 |
17 |
18 | target/classes/clojure/asm
19 | clojure/asm
20 |
21 |
22 | target/classes/clojure/lang
23 | clojure/lang
24 |
25 |
26 |
27 |
28 | target/classes/clojure/main.class
29 | clojure
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/SeqEnumeration.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Mar 3, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | import java.util.Enumeration;
16 |
17 | public class SeqEnumeration implements Enumeration{
18 | ISeq seq;
19 |
20 | public SeqEnumeration(ISeq seq){
21 | this.seq = seq;
22 | }
23 |
24 | public boolean hasMoreElements(){
25 | return seq != null;
26 | }
27 |
28 | public Object nextElement(){
29 | Object ret = RT.first(seq);
30 | seq = RT.next(seq);
31 | return ret;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/storm_test_code/types.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.storm-test-code.types)
2 |
3 | (defprotocol ShapeP
4 | (area [_])
5 | (perimeter [_]))
6 |
7 | (defprotocol SidedP
8 | (sides-count [_]))
9 |
10 | (defrecord Square [side]
11 | ShapeP
12 | (area [_] (* side side))
13 | (perimeter [_] (* side 4)))
14 |
15 | (deftype Circle [rad]
16 | ShapeP
17 | (area [_] (* 3.14 rad rad))
18 | (perimeter [_] (* 2 3.14 rad)))
19 |
20 | (defrecord Rectangle [w h])
21 | (defrecord Triangle [b h])
22 |
23 | (extend-type String
24 | ShapeP
25 | (area [s] (count s))
26 | (perimeter [s] 1))
27 |
28 | (extend-type Triangle
29 | SidedP
30 | (sides-count [_] (+ 1 (+ 1 1))))
31 |
32 | (extend-protocol ShapeP
33 | Rectangle
34 | (area [r] (* (:w r) (:h r)))
35 | (perimeter [r] (+ (:w r) (:w r)
36 | (:h r) (:h r)))
37 |
38 | Triangle
39 | (area [t] (/ (* (:b t) (:h t))
40 | 2))
41 |
42 | Long
43 | (area [n] (* n n))
44 | (perimeter [n] (* 2 n)))
45 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ChunkBuffer.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich May 26, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | final public class ChunkBuffer implements Counted{
16 | Object[] buffer;
17 | int end;
18 |
19 | public ChunkBuffer(int capacity){
20 | buffer = new Object[capacity];
21 | end = 0;
22 | }
23 |
24 | public void add(Object o){
25 | buffer[end++] = o;
26 | }
27 |
28 | public IChunk chunk(){
29 | ArrayChunk ret = new ArrayChunk(buffer, 0, end);
30 | buffer = null;
31 | return ret;
32 | }
33 |
34 | public int count(){
35 | return end;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Obj.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Mar 25, 2006 3:44:58 PM */
12 |
13 | package clojure.lang;
14 |
15 | import java.io.Serializable;
16 |
17 | public abstract class Obj implements IObj, Serializable {
18 |
19 | private static final long serialVersionUID = 802029099426284526L;
20 |
21 | final IPersistentMap _meta;
22 |
23 | public Obj(IPersistentMap meta){
24 | this._meta = meta;
25 | }
26 |
27 | public Obj(){
28 | _meta = null;
29 | }
30 |
31 | final public IPersistentMap meta(){
32 | return _meta;
33 | }
34 |
35 | abstract public Obj withMeta(IPersistentMap meta);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/storm_test_code/hints.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.storm-test-code.hints
2 | (:import (clojure.testfixtures Component MyView MyView$Builder)
3 | (java.util.concurrent Executors)))
4 |
5 | (def form-1
6 | "Returns a function that executes the inline .build call (previously failing)."
7 | (fn []
8 | (-> (Component/newBuilder)
9 | (.setMyView ^MyView$Builder
10 | (.build (MyView/newBuilder)))
11 | .build)))
12 |
13 | (def form-2
14 | "Returns a function that executes the threaded -> form (was expected to succeed)."
15 | (fn []
16 | (-> (Component/newBuilder)
17 | (.setMyView ^MyView$Builder
18 | (-> (MyView/newBuilder)
19 | .build))
20 | .build)))
21 |
22 | (def form-3
23 | "Returns a function that executes a form that needs the type hint befor the (fn ...) macro to succed"
24 | (fn []
25 | true
26 | ;; Needs to find another example that doesn't use multithreading since it break the test
27 | #_(.submit (Executors/newFixedThreadPool 10) ^Callable (fn [] 42))))
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/clojure_zip.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ; Author: Frantisek Sodomka
10 |
11 |
12 | (ns clojure.test-clojure.clojure-zip
13 | (:use clojure.test)
14 | (:require [clojure.zip :as zip]))
15 |
16 |
17 | ; zipper
18 | ;
19 | ; seq-zip
20 | ; vector-zip
21 | ; xml-zip
22 | ;
23 | ; node
24 | ; branch?
25 | ; children
26 | ; make-node
27 | ; path
28 | ; lefts
29 | ; rights
30 | ; down
31 | ; up
32 | ; root
33 | ; right
34 | ; rightmost
35 | ; left
36 | ; leftmost
37 | ;
38 | ; insert-left
39 | ; insert-right
40 | ; replace
41 | ; edit
42 | ; insert-child
43 | ; append-child
44 | ; next
45 | ; prev
46 | ; end?
47 | ; remove
48 |
49 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/volatiles.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ;;Author: Alex Miller
10 |
11 | (ns clojure.test-clojure.volatiles
12 | (:use clojure.test))
13 |
14 | (deftest volatile-basics
15 | (let [vol (volatile! "abc")]
16 | (is (volatile? vol))
17 | (is (= "abc" @vol))
18 | (is (= "def" (vreset! vol "def")))
19 | (is (= "def" @vol))))
20 |
21 | (deftest volatile-vswap!
22 | (let [vol (volatile! 10)]
23 | (is (= 11 (vswap! vol inc)))
24 | (is (= 11 @vol)))
25 | (let [vol (volatile! 10)]
26 | (is (= 20 (vswap! vol + 10)))
27 | (is (= 20 @vol)))
28 | (let [vol (volatile! 10)]
29 | (is (= 25 (vswap! vol + 10 5)))
30 | (is (= 25 @vol))))
31 |
32 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/clojure_xml.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ;;Author: Frantisek Sodomka
10 |
11 |
12 | (ns clojure.test-clojure.clojure-xml
13 | (:use clojure.test)
14 | (:require [clojure.xml :as xml])
15 | (:import [java.io ByteArrayInputStream]))
16 |
17 | (deftest CLJ-2611-avoid-XXE
18 | (let [xml-str "
19 |
21 | ]>
22 | &xxe;"]
23 | (is (= {:tag :foo, :attrs nil, :content nil}
24 | (with-open [input (ByteArrayInputStream. (.getBytes xml-str))]
25 | (xml/parse input))))))
26 | ; parse
27 |
28 | ; emit-element
29 | ; emit
30 |
31 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ArityException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | /**
14 | * @since 1.3
15 | */
16 | public class ArityException extends IllegalArgumentException {
17 |
18 | private static final long serialVersionUID = 2265783180488869950L;
19 |
20 | final public int actual;
21 |
22 | final public String name;
23 |
24 | public ArityException(int actual, String name) {
25 | this(actual, name, null);
26 | }
27 |
28 | public ArityException(int actual, String name, Throwable cause) {
29 | super("Wrong number of args (" + (actual <= 20 ? actual : "> 20") + ") passed to: " + Compiler.demunge(name), cause);
30 | this.actual = actual;
31 | this.name = name;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IDrop.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | /**
14 | * Persistent or algorithmically defined collections can implement IDrop to provide
15 | * a means of dropping N items that is more efficient than sequential walking.
16 | */
17 | public interface IDrop{
18 | /**
19 | * Returns a collection that is Sequential, ISeq, and IReduceInit. It is also
20 | * useful if the returned coll implements IDrop for subsequent use in a
21 | * partition-like scenario.
22 | *
23 | * @param n Items to drop, must be > 0
24 | * @return Collection that is Sequential, ISeq, and IReduceInit, or null if past the end
25 | */
26 | Sequential drop(int n);
27 | }
28 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/repl/deps.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.repl.deps
2 | (:use clojure.test)
3 | (:require [clojure.string :as str]
4 | [clojure.repl.deps :as deps]
5 | [clojure.main :as main]))
6 |
7 | (defmacro with-dynamic-loader
8 | "Ensure or install a DynamicClassLoader as the current thread's
9 | context classloader and execute the body."
10 | [& body]
11 | `(let [t# (Thread/currentThread)
12 | cl# (.getContextClassLoader t#)]
13 | (if (instance? ~'clojure.lang.DynamicClassLoader cl#)
14 | (do ~@body)
15 | (try
16 | (.setContextClassLoader t# (clojure.lang.DynamicClassLoader. cl#))
17 | ~@body
18 | (finally
19 | (.setContextClassLoader t# cl#))))))
20 |
21 | ;(deftest test-no-add-libs-outside-repl
22 | ; (try
23 | ; (deps/add-lib 'org.clojure/data.json {:mvn/version "2.4.0"})
24 | ; (is false "add-libs outside repl should throw")
25 | ; (catch Throwable t (str/includes? (ex-message t) "add-libs")))
26 | ;
27 | ; (with-dynamic-loader
28 | ; (binding [*repl* true]
29 | ; (is (some #{'org.clojure/data.json} (deps/add-lib 'org.clojure/data.json {:mvn/version "2.4.0"})))))
30 | ; )
31 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/proxy/examples.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns ^{:doc "Test proxy classes that are AOT-compiled for the tests in
10 | clojure.test-clojure.java-interop."
11 | :author "Ambrose Bonnaire-Sergeant"}
12 | clojure.test-clojure.proxy.examples)
13 |
14 | (definterface A
15 | (^int a [^String x])
16 | (^boolean a [^java.io.File x])
17 | (^boolean a [^Runnable x])
18 | (a [^Boolean x])
19 | (^int a [^Boolean x ^String y])
20 | (^int a [^String x ^String y])
21 | (^boolean a [^String x ^java.io.File y])
22 | (^boolean a [^String x ^Runnable y])
23 | (b [^String x])
24 | (c [^String x])
25 | (d [^String x]))
26 |
27 | (def ^String proxy1-class-name
28 | (-> (proxy [A] [])
29 | class
30 | .getName))
31 |
--------------------------------------------------------------------------------
/src/assembly/distribution.xml:
--------------------------------------------------------------------------------
1 |
2 | distribution
3 |
4 | zip
5 |
6 |
7 |
8 | src
9 | src
10 |
11 |
12 | doc
13 | doc
14 |
15 |
16 | test
17 | test
18 |
19 |
20 | target
21 | /
22 | false
23 |
24 | *.jar
25 |
26 |
27 |
28 |
29 |
30 | pom.xml
31 |
32 |
33 | build.xml
34 |
35 |
36 | readme.txt
37 | true
38 |
39 |
40 | changes.md
41 |
42 |
43 | clojure.iml
44 |
45 |
46 | epl-v10.html
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/MapEntry.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | import java.util.Iterator;
14 |
15 | public class MapEntry extends AMapEntry{
16 |
17 | private static final long serialVersionUID = -3752414622414469244L;
18 |
19 | final Object _key;
20 | final Object _val;
21 |
22 | static public MapEntry create(Object key, Object val){
23 | return new MapEntry(key, val);
24 | }
25 |
26 | public MapEntry(Object key, Object val){
27 | this._key = key;
28 | this._val = val;
29 | }
30 |
31 | public Object key(){
32 | return _key;
33 | }
34 |
35 | public Object val(){
36 | return _val;
37 | }
38 |
39 | public Object getKey(){
40 | return key();
41 | }
42 |
43 | public Object getValue(){
44 | return val();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/AReference.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Dec 31, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | public class AReference implements IReference {
16 | private IPersistentMap _meta;
17 |
18 | public AReference() {
19 | this(null);
20 | }
21 |
22 | public AReference(IPersistentMap meta) {
23 | _meta = meta;
24 | }
25 |
26 | synchronized public IPersistentMap meta() {
27 | return _meta;
28 | }
29 |
30 | synchronized public IPersistentMap alterMeta(IFn alter, ISeq args) {
31 | _meta = (IPersistentMap) alter.applyTo(new Cons(_meta, args));
32 | return _meta;
33 | }
34 |
35 | synchronized public IPersistentMap resetMeta(IPersistentMap m) {
36 | _meta = m;
37 | return m;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/java/process.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns clojure.test-clojure.java.process
10 | (:require
11 | [clojure.test :refer :all]
12 | [clojure.java.process :as p]
13 | [clojure.string :as str]))
14 |
15 | (deftest test-stderr-redirect
16 | ;; capture to stdout and return string
17 | (is (not (str/blank? (p/exec "bash" "-c" "ls"))))
18 |
19 | ;; print to stderr, capture nil
20 | (is (str/blank? (p/exec "bash" "-c" "ls >&2")))
21 |
22 | ;; redirect, then capture to string
23 | (is (not (str/blank? (p/exec {:err :stdout} "bash" "-c" "ls >&2")))))
24 |
25 | (deftest test-process-deref
26 | (is (zero? @(p/exit-ref (p/start "sleep" "1"))))
27 | (is (zero? (deref (p/exit-ref (p/start "sleep" "1")) 2500 :timeout)))
28 | (is (= :timeout (deref (p/exit-ref (p/start "sleep" "1")) 1 :timeout))))
29 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/pprint/test_helper.clj:
--------------------------------------------------------------------------------
1 | ;;; test_helper.clj -- part of the pretty printer for Clojure
2 |
3 | ; Copyright (c) Rich Hickey. All rights reserved.
4 | ; The use and distribution terms for this software are covered by the
5 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
6 | ; which can be found in the file epl-v10.html at the root of this distribution.
7 | ; By using this software in any fashion, you are agreeing to be bound by
8 | ; the terms of this license.
9 | ; You must not remove this notice, or any other, from this software.
10 |
11 | ;; Author: Tom Faulhaber
12 | ;; April 3, 2009
13 |
14 |
15 | ;; This is just a macro to make my tests a little cleaner
16 |
17 | (ns clojure.test-clojure.pprint.test-helper
18 | (:use [clojure.test :only (deftest is)]
19 | [clojure.test-helper :only [platform-newlines]]))
20 |
21 | (defn- back-match [x y] (re-matches y x))
22 |
23 | (defmacro simple-tests [name & test-pairs]
24 | `(deftest ~name
25 | ~@(for [[x y] (partition 2 test-pairs)]
26 | (cond
27 | (instance? java.util.regex.Pattern y)
28 | `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y))
29 | (instance? java.lang.String y) `(is (= ~x (platform-newlines ~y)))
30 | :else `(is (= ~x ~y))))))
31 |
32 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/parallel.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ; Author: Frantisek Sodomka
10 |
11 |
12 | (ns clojure.test-clojure.parallel
13 | (:use clojure.test))
14 |
15 | ;; !! Tests for the parallel library will be in a separate file clojure_parallel.clj !!
16 |
17 | ; future-call
18 | ; future
19 | ; pmap
20 | ; pcalls
21 | ; pvalues
22 |
23 |
24 | ;; pmap
25 | ;;
26 | (deftest pmap-does-its-thing
27 | ;; regression fixed in r1218; was OutOfMemoryError
28 | (is (= '(1) (pmap inc [0]))))
29 |
30 |
31 | (def ^:dynamic *test-value* 1)
32 |
33 | (deftest future-fn-properly-retains-conveyed-bindings
34 | (let [a (atom [])]
35 | (binding [*test-value* 2]
36 | @(future (dotimes [_ 3]
37 | ;; we need some binding to trigger binding pop
38 | (binding [*print-dup* false]
39 | (swap! a conj *test-value*))))
40 | (is (= [2 2 2] @a)))))
41 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IDeref.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Feb 9, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | import java.util.function.BooleanSupplier;
16 | import java.util.function.DoubleSupplier;
17 | import java.util.function.IntSupplier;
18 | import java.util.function.LongSupplier;
19 | import java.util.function.Supplier;
20 |
21 | public interface IDeref extends Supplier, BooleanSupplier, IntSupplier, LongSupplier, DoubleSupplier {
22 | Object deref() ;
23 |
24 | @Override
25 | default Object get() {
26 | return deref();
27 | }
28 |
29 | @Override
30 | default boolean getAsBoolean() {
31 | return RT.booleanCast(deref());
32 | }
33 |
34 | @Override
35 | default int getAsInt() {
36 | return RT.intCast(deref());
37 | }
38 |
39 | @Override
40 | default long getAsLong() {
41 | return RT.longCast(deref());
42 | }
43 |
44 | @Override
45 | default double getAsDouble() {
46 | return RT.doubleCast(deref());
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/java/javadoc.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns clojure.test-clojure.java.javadoc
10 | (:use clojure.test
11 | [clojure.java.javadoc :as j])
12 | (:require [clojure.string :as str])
13 | (:import (java.io File)))
14 |
15 | (defn correct-url [url-pattern-str module-name url-suffix]
16 | (str (format url-pattern-str module-name) url-suffix))
17 |
18 | (deftest javadoc-url-test
19 | (testing "for a core api"
20 | (binding [*feeling-lucky* false]
21 | (are [x y] (= x (#'j/javadoc-url y))
22 | nil "foo.Bar"
23 | (correct-url *core-java-api* "java.base" "java/lang/String.html") "java.lang.String"
24 | (correct-url *core-java-api* "java.sql" "java/sql/Connection.html") "java.sql.Connection")))
25 | (testing "for a remote javadoc"
26 | (binding [*remote-javadocs* (ref (sorted-map "java." "http://example.com/"))]
27 | (is (= "http://example.com/java/lang/Number.html" (#'j/javadoc-url "java.lang.Number"))))))
28 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/run_single_test.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns clojure.test-clojure.run-single-test
10 | (:require [clojure.test :refer [is deftest run-test run-tests]]
11 | [clojure.test-helper :refer [with-err-string-writer]]
12 | [clojure.test-clojure.test-fixtures :as tf]))
13 |
14 | (defn not-a-test
15 | [])
16 |
17 | (defmacro should-print-to-err
18 | [re & body]
19 | `(is (re-find ~re (with-err-string-writer ~@body))))
20 |
21 | (deftest reports-missing-var
22 | (should-print-to-err #"^Unable to resolve .*/function-missing to a test function.*"
23 | (let [result (eval `(run-test function-missing))]
24 | (is (nil? result)))))
25 |
26 | (deftest reports-non-test-var
27 | (should-print-to-err #"^.*/not-a-test is not a test.*"
28 | (let [result (eval `(run-test not-a-test))]
29 | (is (nil? result)))))
30 |
31 | (deftest can-run-test-with-fixtures
32 | (is (= {:test 1, :pass 2, :fail 0, :error 0, :type :summary}
33 | (run-test tf/can-use-once-fixtures))))
34 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/SeqIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jun 19, 2007 */
12 |
13 | package clojure.lang;
14 |
15 | import java.util.Iterator;
16 | import java.util.NoSuchElementException;
17 |
18 | public class SeqIterator implements Iterator{
19 |
20 | static final Object START = new Object();
21 | Object seq;
22 | Object next;
23 |
24 | public SeqIterator(Object o){
25 | seq = START;
26 | next = o;
27 | }
28 |
29 | //preserved for binary compatibility
30 | public SeqIterator(ISeq o){
31 | seq = START;
32 | next = o;
33 | }
34 |
35 | public boolean hasNext(){
36 | if(seq == START){
37 | seq = null;
38 | next = RT.seq(next);
39 | }
40 | else if(seq == next)
41 | next = RT.next(seq);
42 | return next != null;
43 | }
44 |
45 | public Object next() throws NoSuchElementException {
46 | if(!hasNext())
47 | throw new NoSuchElementException();
48 | seq = next;
49 | return RT.first(next);
50 | }
51 |
52 | public void remove(){
53 | throw new UnsupportedOperationException();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/edn.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ; Author: Stuart Halloway
10 |
11 |
12 | (ns clojure.test-clojure.edn
13 | (:require [clojure.test.generative :refer (defspec)]
14 | [clojure.test-clojure.generators :as cgen]
15 | [clojure.edn :as edn]))
16 |
17 | (defn roundtrip
18 | "Print an object and read it back as edn. Returns rather than throws
19 | any exceptions."
20 | [o]
21 | (binding [*print-length* nil
22 | *print-dup* nil
23 | *print-level* nil]
24 | (try
25 | (-> o pr-str edn/read-string)
26 | (catch Throwable t t))))
27 |
28 | (defspec types-that-should-roundtrip
29 | roundtrip
30 | [^{:tag cgen/ednable} o]
31 | (when-not (= o %)
32 | (throw (ex-info "Value cannot roundtrip, see ex-data" {:printed o :read %}))))
33 |
34 | (defspec types-that-should-not-roundtrip
35 | roundtrip
36 | [^{:tag cgen/non-ednable} o]
37 | (when-not (instance? Throwable %)
38 | (throw (ex-info "edn/read should have thrown, see ex-data" {:printed o :read %}))))
39 |
--------------------------------------------------------------------------------
/src/clj/clojure/java/browse_ui.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns
10 | ^{:author "Christophe Grand",
11 | :doc "Helper namespace for clojure.java.browse.
12 | Prevents console apps from becoming GUI unnecessarily."}
13 | clojure.java.browse-ui)
14 |
15 | (defn- open-url-in-swing
16 | [url]
17 | (let [htmlpane (javax.swing.JEditorPane. url)]
18 | (.setEditable htmlpane false)
19 | (.addHyperlinkListener htmlpane
20 | (proxy [javax.swing.event.HyperlinkListener] []
21 | (hyperlinkUpdate [^javax.swing.event.HyperlinkEvent e]
22 | (when (= (.getEventType e) (. javax.swing.event.HyperlinkEvent$EventType ACTIVATED))
23 | (if (instance? javax.swing.text.html.HTMLFrameHyperlinkEvent e)
24 | (-> htmlpane .getDocument (.processHTMLFrameHyperlinkEvent e))
25 | (.setPage htmlpane (.getURL e)))))))
26 | (doto (javax.swing.JFrame.)
27 | (.setContentPane (javax.swing.JScrollPane. htmlpane))
28 | (.setBounds 32 32 700 900)
29 | (.setVisible true))))
30 |
31 |
--------------------------------------------------------------------------------
/src/jvm/clojure/main.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure;
12 |
13 | import clojure.lang.Symbol;
14 | import clojure.lang.Var;
15 | import clojure.lang.RT;
16 |
17 | public class main{
18 |
19 | final static private Symbol CLOJURE_MAIN = Symbol.intern("clojure.main");
20 | final static private Var REQUIRE = RT.var("clojure.core", "require");
21 | final static private Var LEGACY_REPL = RT.var("clojure.main", "legacy-repl");
22 | final static private Var LEGACY_SCRIPT = RT.var("clojure.main", "legacy-script");
23 | final static private Var MAIN = RT.var("clojure.main", "main");
24 |
25 | public static void legacy_repl(String[] args) {
26 | RT.init();
27 | REQUIRE.invoke(CLOJURE_MAIN);
28 | LEGACY_REPL.invoke(RT.seq(args));
29 | }
30 |
31 | public static void legacy_script(String[] args) {
32 | RT.init();
33 | REQUIRE.invoke(CLOJURE_MAIN);
34 | LEGACY_SCRIPT.invoke(RT.seq(args));
35 | }
36 |
37 | public static void main(String[] args) {
38 | RT.init();
39 | REQUIRE.invoke(CLOJURE_MAIN);
40 | MAIN.applyTo(RT.seq(args));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ATransientSet.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Mar 3, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | public abstract class ATransientSet extends AFn implements ITransientSet{
16 | volatile ITransientMap impl;
17 |
18 | ATransientSet(ITransientMap impl) {
19 | this.impl = impl;
20 | }
21 |
22 | public int count() {
23 | return impl.count();
24 | }
25 |
26 | public ITransientSet conj(Object val) {
27 | ITransientMap m = impl.assoc(val, val);
28 | if (m != impl) this.impl = m;
29 | return this;
30 | }
31 |
32 | public boolean contains(Object key) {
33 | return this != impl.valAt(key, this);
34 | }
35 |
36 | public ITransientSet disjoin(Object key) {
37 | ITransientMap m = impl.without(key);
38 | if (m != impl) this.impl = m;
39 | return this;
40 | }
41 |
42 | public Object get(Object key) {
43 | return impl.valAt(key);
44 | }
45 |
46 | public Object invoke(Object key, Object notFound) {
47 | return impl.valAt(key, notFound);
48 | }
49 |
50 | public Object invoke(Object key) {
51 | return impl.valAt(key);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Cons.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Mar 25, 2006 11:01:29 AM */
12 |
13 | package clojure.lang;
14 |
15 | import java.io.Serializable;
16 |
17 | final public class Cons extends ASeq implements Serializable {
18 |
19 | private static final long serialVersionUID = 6682587018567831263L;
20 |
21 | private final Object _first;
22 | private final ISeq _more;
23 |
24 | public Cons(Object first, ISeq _more){
25 | this._first = first;
26 | this._more = _more;
27 | }
28 |
29 |
30 | public Cons(IPersistentMap meta, Object _first, ISeq _more){
31 | super(meta);
32 | this._first = _first;
33 | this._more = _more;
34 | }
35 |
36 | public Object first(){
37 | return _first;
38 | }
39 |
40 | public ISeq next(){
41 | return more().seq();
42 | }
43 |
44 | public ISeq more(){
45 | if(_more == null)
46 | return PersistentList.EMPTY;
47 | return _more;
48 | }
49 |
50 | public int count(){
51 | return 1 + RT.count(_more);
52 | }
53 |
54 | public Cons withMeta(IPersistentMap meta){
55 | if(meta() == meta)
56 | return this;
57 | return new Cons(meta, _first, _more);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/data.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns clojure.test-clojure.data
10 | (:use clojure.data clojure.test)
11 | (:import java.util.HashSet))
12 |
13 | (deftest diff-test
14 | (are [d x y] (= d (diff x y))
15 | [nil nil nil] nil nil
16 | [1 2 nil] 1 2
17 | [nil nil [1 2 3]] [1 2 3] '(1 2 3)
18 | [1 [:a :b] nil] 1 [:a :b]
19 | [{:a 1} :b nil] {:a 1} :b
20 | [:team #{:p1 :p2} nil] :team #{:p1 :p2}
21 | [{0 :a} [:a] nil] {0 :a} [:a]
22 | [nil [nil 2] [1]] [1] [1 2]
23 | [nil nil [1 2]] [1 2] (into-array [1 2])
24 | [#{:a} #{:b} #{:c :d}] #{:a :c :d} #{:b :c :d}
25 | [nil nil {:a 1}] {:a 1} {:a 1}
26 | [{:a #{2}} {:a #{4}} {:a #{3}}] {:a #{2 3}} {:a #{3 4}}
27 | [#{1} #{3} #{2}] (HashSet. [1 2]) (HashSet. [2 3])
28 | [nil nil [1 2]] [1 2] (into-array [1 2])
29 | [nil nil [1 2]] (into-array [1 2]) [1 2]
30 | [{:a {:c [1]}} {:a {:c [0]}} {:a {:c [nil 2] :b 1}}] {:a {:b 1 :c [1 2]}} {:a {:b 1 :c [0 2]}}
31 | [{:a nil} {:a false} {:b nil :c false}] {:a nil :b nil :c false} {:a false :b nil :c false}))
32 |
33 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ExceptionInfo.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | */
10 |
11 | package clojure.lang;
12 |
13 | /**
14 | * Exception that carries data (a map) as additional payload. Clojure programs that need
15 | * richer semantics for exceptions should use this in lieu of defining project-specific
16 | * exception classes.
17 | */
18 | public class ExceptionInfo extends RuntimeException implements IExceptionInfo {
19 |
20 | private static final long serialVersionUID = -1073473305916521986L;
21 |
22 | public final IPersistentMap data;
23 |
24 | public ExceptionInfo(String s, IPersistentMap data) {
25 | this(s, data, null);
26 | }
27 |
28 | public ExceptionInfo(String s, IPersistentMap data, Throwable throwable) {
29 | // null cause is equivalent to not passing a cause
30 | super(s, throwable);
31 | this.data = (data == null) ? PersistentArrayMap.EMPTY: data;
32 | }
33 |
34 | public IPersistentMap getData() {
35 | return data;
36 | }
37 |
38 | public String toString() {
39 | return "clojure.lang.ExceptionInfo: " + getMessage() + " " + data.toString();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Hi! Thanks for your interest in Clojure!
2 |
3 | ## I want to ask a question
4 |
5 | If you have a question about Clojure, please use the official Ask Clojure forum at https://ask.clojure.org. This forum is monitored by the Clojure maintainers.
6 |
7 | ## I want to discuss an idea
8 |
9 | There are many interactive Clojure forums for discussion and you can find a list at [Clojure Discussion](https://clojure.org/community/resources#_clojure_discussion).
10 |
11 | ## I want to file a bug / suggest an enhancement
12 |
13 | Please file it as a question on https://ask.clojure.org with the tag "problem" (possible bugs) or "request" (enhancements).
14 |
15 | ## I want to provide a patch / PR
16 |
17 | If you would like to contribute patches, the Clojure dev process is described in detail at https://clojure.org/dev.
18 |
19 | In short, this process requires:
20 |
21 | - [Signing the Contributor Agreement](https://clojure.org/dev/contributor_agreement)
22 | - [Requesting jira access](https://clojure.atlassian.net/servicedesk/customer/portal/1)
23 |
24 | This project does not accept pull requests.
25 |
26 | ## I am looking for official documentation
27 |
28 | You can find official documentation on the Clojure web site:
29 |
30 | * Reference docs https://clojure.org/reference
31 | * Tutorials and guides: https://clojure.org/guides
32 | * API: https://clojure.org/api/api
33 |
34 | ## What release should I use?
35 |
36 | Find the current release info here:
37 |
38 | https://clojure.org/releases/downloads
39 |
40 | A list of all releases can be found here:
41 |
42 | https://clojure.org/releases/downloads_older
43 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Tuple.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich 7/16/15 */
12 | // proposed by Zach Tellman
13 |
14 | package clojure.lang;
15 |
16 | import java.util.Collection;
17 | import java.util.RandomAccess;
18 |
19 | public class Tuple{
20 | static final int MAX_SIZE = 6;
21 |
22 | public static IPersistentVector create(){return PersistentVector.EMPTY;}
23 | public static IPersistentVector create(Object v0)
24 | {return RT.vector(v0);}
25 | public static IPersistentVector create(Object v0, Object v1)
26 | {return RT.vector(v0, v1);}
27 | public static IPersistentVector create(Object v0, Object v1, Object v2)
28 | {return RT.vector(v0, v1, v2);}
29 | public static IPersistentVector create(Object v0, Object v1, Object v2, Object v3)
30 | {return RT.vector(v0, v1, v2, v3);}
31 | public static IPersistentVector create(Object v0, Object v1, Object v2, Object v3, Object v4)
32 | {return RT.vector(v0, v1, v2, v3, v4);}
33 | public static IPersistentVector create(Object v0, Object v1, Object v2, Object v3, Object v4, Object v5)
34 | {return RT.vector(v0, v1, v2, v3, v4, v5);}
35 |
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/keywords.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns clojure.test-clojure.keywords
10 | (:use clojure.test))
11 |
12 | (let [this-ns (str (.name *ns*))]
13 | (deftest test-find-keyword
14 | :foo
15 | ::foo
16 | (let [absent-keyword-sym (gensym "absent-keyword-sym")]
17 | (are [result lookup] (= result (find-keyword lookup))
18 | :foo :foo
19 | :foo 'foo
20 | :foo "foo"
21 | nil absent-keyword-sym
22 | nil (str absent-keyword-sym))
23 | (are [result lookup] (= result (find-keyword this-ns lookup))
24 | ::foo "foo"
25 | nil (str absent-keyword-sym)))))
26 |
27 | (deftest arity-exceptions
28 | (is (thrown-with-msg? IllegalArgumentException #"Wrong number of args \(0\) passed to: :kw" (:kw)))
29 | (is (thrown-with-msg? IllegalArgumentException #"Wrong number of args \(20\) passed to: :foo/bar" (apply :foo/bar (range 20))))
30 | (is (thrown-with-msg? IllegalArgumentException #"Wrong number of args \(> 20\) passed to: :foo/bar" (apply :foo/bar (range 21))))
31 | (is (thrown-with-msg? IllegalArgumentException #"Wrong number of args \(> 20\) passed to: :foo/bar" (apply :foo/bar (range 22)))))
32 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/RecordIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | */
10 |
11 | /* ghadi shayban Sep 24, 2014 */
12 |
13 | package clojure.lang;
14 |
15 | import java.util.Iterator;
16 |
17 | public final class RecordIterator implements Iterator {
18 |
19 | int i = 0;
20 | final int basecnt;
21 | final ILookup rec;
22 | final IPersistentVector basefields;
23 | final Iterator extmap;
24 |
25 | public RecordIterator (ILookup rec, IPersistentVector basefields, Iterator extmap) {
26 | this.rec = rec;
27 | this.basefields = basefields;
28 | this.basecnt = basefields.count();
29 | this.extmap = extmap;
30 | }
31 |
32 | public boolean hasNext() {
33 | if (i < basecnt) {
34 | return true;
35 | } else {
36 | return extmap.hasNext();
37 | }
38 | }
39 |
40 | public Object next() {
41 | if (i < basecnt) {
42 | Object k = basefields.nth(i);
43 | i++;
44 | return MapEntry.create(k, rec.valAt(k));
45 | } else {
46 | return extmap.next();
47 | }
48 | }
49 |
50 | public void remove() {
51 | throw new UnsupportedOperationException();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/Delay.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jun 28, 2007 */
12 |
13 | package clojure.lang;
14 |
15 | import java.util.concurrent.locks.Lock;
16 | import java.util.concurrent.locks.ReentrantLock;
17 |
18 | public class Delay implements IDeref, IPending{
19 | Object val;
20 | Throwable exception;
21 | IFn fn;
22 | volatile Lock lock;
23 |
24 | public Delay(IFn f){
25 | fn = f;
26 | val = null;
27 | exception = null;
28 | lock = new ReentrantLock();
29 | }
30 |
31 | static public Object force(Object x) {
32 | return (x instanceof Delay) ?
33 | ((Delay) x).deref()
34 | : x;
35 | }
36 |
37 | private void realize() {
38 | Lock l = lock;
39 | if(l != null) {
40 | l.lock();
41 | try {
42 | if(fn!=null) {
43 | try {
44 | val = fn.invoke();
45 | } catch (Throwable t) {
46 | exception = t;
47 | }
48 | fn = null;
49 | lock = null;
50 | }
51 | } finally {
52 | l.unlock();
53 | }
54 | }
55 | }
56 |
57 | public Object deref() {
58 | if(lock != null)
59 | realize();
60 | if(exception != null)
61 | throw Util.sneakyThrow(exception);
62 | return val;
63 | }
64 |
65 | public boolean isRealized(){
66 | return lock == null;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/storm_utils.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.storm-utils
2 | (:require [clojure.string :as str]))
3 |
4 | (def captured-traces (atom []))
5 |
6 | (defn maybe-serialize [v]
7 | (cond
8 | (or (nil? v) (map? v) (vector? v)
9 | (set? v) (seq? v) (symbol? v)
10 | (string? v) (number? v) (boolean? v))
11 | v
12 |
13 | (instance? Throwable v)
14 | (format "#error[%s]" (ex-message v))
15 |
16 | :else (-> v
17 | pr-str
18 | (str/replace #"#object\[.+\]" "#object[...]"))))
19 |
20 | (defn stable-fn-name [fn-name]
21 | (str/replace fn-name #"\-\-[0-9]+$" "--GEN-ID"))
22 |
23 | (defn reset-captured-traces-fixture [f]
24 | (clojure.storm.Tracer/setTraceFnsCallbacks
25 | {:trace-fn-call-fn
26 | (fn [_ fn-ns fn-name args form-id]
27 | (swap! captured-traces conj [:fn-call fn-ns (stable-fn-name fn-name) (into [] (map maybe-serialize) args) form-id]))
28 | :trace-fn-return-fn
29 | (fn [_ ret-val coord _]
30 | (swap! captured-traces conj [:fn-return (maybe-serialize ret-val) coord]))
31 | :trace-fn-unwind-fn
32 | (fn [_ throwable coord _]
33 | (swap! captured-traces conj [:fn-unwind (maybe-serialize (.getMessage throwable)) coord]))
34 | :trace-expr-fn
35 | (fn [_ val coord _]
36 | (swap! captured-traces conj [:expr-exec (maybe-serialize val) coord]))
37 | :trace-bind-fn
38 | (fn [_ coord sym-name val]
39 | (swap! captured-traces conj [:bind sym-name (maybe-serialize val) coord]))})
40 | (reset! captured-traces [])
41 | (f)
42 | (clojure.storm.Tracer/setTraceFnsCallbacks {}))
43 |
44 | (defn capture [] @captured-traces)
45 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/try_catch.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ; Author: Paul M Bauer
10 |
11 | (ns clojure.test-clojure.try-catch
12 | (:use clojure.test)
13 | (:import [clojure.test ReflectorTryCatchFixture
14 | ReflectorTryCatchFixture$Cookies]))
15 |
16 | (defn- get-exception [expression]
17 | (try (eval expression)
18 | nil
19 | (catch java.lang.Throwable t
20 | t)))
21 |
22 | (deftest catch-receives-checked-exception-from-eval
23 | (are [expression expected-exception] (= expected-exception
24 | (type (get-exception expression)))
25 | "Eh, I'm pretty safe" nil
26 | '(java.io.FileReader. "CAFEBABEx0/idonotexist") java.io.FileNotFoundException))
27 |
28 |
29 | (defn fail [x]
30 | (ReflectorTryCatchFixture/fail x))
31 |
32 | (defn make-instance []
33 | (ReflectorTryCatchFixture.))
34 |
35 | (deftest catch-receives-checked-exception-from-reflective-call
36 | (is (thrown-with-msg? ReflectorTryCatchFixture$Cookies #"Long" (fail 1)))
37 | (is (thrown-with-msg? ReflectorTryCatchFixture$Cookies #"Double" (fail 1.0)))
38 | (is (thrown-with-msg? ReflectorTryCatchFixture$Cookies #"Wrapped"
39 | (.failWithCause (make-instance) 1.0))))
40 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/KeywordLookupSite.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Nov 2, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | public final class KeywordLookupSite implements ILookupSite, ILookupThunk{
16 |
17 | final Keyword k;
18 |
19 | public KeywordLookupSite(Keyword k){
20 | this.k = k;
21 | }
22 |
23 | public ILookupThunk fault(Object target){
24 | if(target instanceof IKeywordLookup)
25 | {
26 | return install(target);
27 | }
28 | else if(target instanceof ILookup)
29 | {
30 | return ilookupThunk(target.getClass());
31 | }
32 | return this;
33 | }
34 |
35 | public Object get(Object target){
36 | if(target instanceof IKeywordLookup || target instanceof ILookup)
37 | return this;
38 | return RT.get(target,k);
39 | }
40 |
41 | private ILookupThunk ilookupThunk(final Class c){
42 | return new ILookupThunk(){
43 | public Object get(Object target){
44 | if(target != null && target.getClass() == c)
45 | return ((ILookup) target).valAt(k);
46 | return this;
47 | }
48 | };
49 | }
50 |
51 | private ILookupThunk install(Object target){
52 | ILookupThunk t = ((IKeywordLookup)target).getLookupThunk(k);
53 | if(t != null)
54 | return t;
55 | return ilookupThunk(target.getClass());
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/storm_test_code/bodies.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.storm-test-code.bodies)
2 |
3 | (defn tried []
4 | (try
5 | (+ 1 1)
6 | (throw (Exception. "Dummy"))
7 | (catch Exception e
8 | (+ 2 2))))
9 |
10 | (defn uncached-throw []
11 | (throw (Exception. "Dang")))
12 |
13 | (defn uncached-throw-inner []
14 | (let [f (fn inner []
15 | (throw (Exception. "Dang")))]
16 | (f)))
17 |
18 | (defn letfn-fn []
19 | (letfn [(square [x]
20 | (* x x))]
21 | (+ 1 (square 2))))
22 |
23 | (defn looper []
24 | (loop [s 0
25 | n 2]
26 | (if (zero? n)
27 | s
28 | (recur (+ s n) (dec n)))))
29 |
30 | (defn letter []
31 | (let [a 5
32 | b (* a 2)
33 | c (let [z (+ a b)]
34 | z)]
35 | c))
36 |
37 | (defprotocol PP
38 | (doit [_]))
39 |
40 | (defn reified-let []
41 | (doit
42 | (reify PP
43 | (doit [_]
44 | (let [a 10
45 | b 20]
46 | (+ a b))))))
47 |
48 | (defn casey [x]
49 | (case x
50 | :first (+ 40 2)
51 | :second 1
52 | 0))
53 |
54 | (defn doer []
55 | (do
56 | (+ 1 1)
57 | (+ 2 2)
58 | (do
59 | (+ 3 3)
60 | (+ 4 4))))
61 |
62 | (defn constructor []
63 | (str (String. "ctor")
64 | (^[byte/1] String/new (byte-array [64 64]))))
65 |
66 | (defn method-value []
67 | (let [parser ^[String] Integer/parseInt]
68 | (mapv parser ["4" "2"])))
69 |
70 | (defn hinted-and-static ^long [^long n]
71 | (let [arr (byte-array [1 2 3 4])
72 | e (aget arr 2)
73 | l (long e)
74 | b (bit-shift-left n 2)]
75 | (+ e l b)))
76 |
77 | (defn instance-methods []
78 | (let [strs ["a" "b" "c"]]
79 | (mapv String/.toUpperCase strs)))
80 |
81 | (defn interopter [o]
82 | ;; TODO
83 | )
84 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/LazilyPersistentVector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich May 14, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | import java.util.Collection;
16 | import java.util.RandomAccess;
17 |
18 | public class LazilyPersistentVector{
19 |
20 |
21 | static public IPersistentVector createOwning(Object... items){
22 | // if(items.length <= Tuple.MAX_SIZE)
23 | // return Tuple.createFromArray(items);
24 | // else
25 | if(items.length <= 32)
26 | return new PersistentVector(items.length, 5, PersistentVector.EMPTY_NODE,items);
27 | return PersistentVector.create(items);
28 | }
29 |
30 | static int fcount(Object c){
31 | if(c instanceof Counted)
32 | return ((Counted) c).count();
33 | return ((Collection)c).size();
34 | }
35 |
36 | static public IPersistentVector create(Object obj){
37 | // if((obj instanceof Counted || obj instanceof RandomAccess)
38 | // && fcount(obj) <= Tuple.MAX_SIZE)
39 | // return Tuple.createFromColl(obj);
40 | // else
41 | if(obj instanceof IReduceInit)
42 | return PersistentVector.create((IReduceInit) obj);
43 | else if(obj instanceof ISeq)
44 | return PersistentVector.create(RT.seq(obj));
45 | else if(obj instanceof Iterable)
46 | return PersistentVector.create((Iterable)obj);
47 | else
48 | return createOwning(RT.toArray(obj));
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/clj/clojure/pprint/print_table.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (in-ns 'clojure.pprint)
10 |
11 | (defn print-table
12 | "Prints a collection of maps in a textual table. Prints table headings
13 | ks, and then a line of output for each row, corresponding to the keys
14 | in ks. If ks are not specified, use the keys of the first item in rows."
15 | {:added "1.3"}
16 | ([ks rows]
17 | (when (seq rows)
18 | (let [widths (map
19 | (fn [k]
20 | (apply max (count (str k)) (map #(count (str (get % k))) rows)))
21 | ks)
22 | spacers (map #(apply str (repeat % "-")) widths)
23 | fmts (map #(str "%" % "s") widths)
24 | fmt-row (fn [leader divider trailer row]
25 | (str leader
26 | (apply str (interpose divider
27 | (for [[col fmt] (map vector (map #(get row %) ks) fmts)]
28 | (format fmt (str col)))))
29 | trailer))]
30 | (println)
31 | (println (fmt-row "| " " | " " |" (zipmap ks ks)))
32 | (println (fmt-row "|-" "-+-" "-|" (zipmap ks spacers)))
33 | (doseq [row rows]
34 | (println (fmt-row "| " " | " " |" row))))))
35 | ([rows] (print-table (keys (first rows)) rows)))
36 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/api.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns clojure.test-clojure.api
10 | (:require [clojure.test.generative :refer (defspec)]
11 | [clojure.test-clojure.generators :as cgen])
12 | (:import clojure.lang.IFn
13 | clojure.java.api.Clojure
14 | clojure.lang.Var))
15 |
16 | (set! *warn-on-reflection* true)
17 |
18 | (defn roundtrip
19 | "Print an object and read it back with Clojure/read"
20 | [o]
21 | (binding [*print-length* nil
22 | *print-dup* nil
23 | *print-level* nil]
24 | (Clojure/read (pr-str o))))
25 |
26 | (defn api-var-str
27 | [^Var v]
28 | (Clojure/var (str (.name (.ns v)))
29 | (str (.sym v))))
30 |
31 | (defn api-var
32 | [^Var v]
33 | (Clojure/var (.name (.ns v))
34 | (.sym v)))
35 |
36 | (defspec api-can-read
37 | roundtrip
38 | [^{:tag cgen/ednable} o]
39 | (when-not (= o %)
40 | (throw (ex-info "Value cannot roundtrip with Clojure/read" {:printed o :read %}))))
41 |
42 | (defspec api-can-find-var
43 | api-var
44 | [^{:tag cgen/var} v]
45 | (when-not (= v %)
46 | (throw (ex-info "Var cannot roundtrip through Clojure/var" {:from v :to %}))))
47 |
48 | (defspec api-can-find-var-str
49 | api-var-str
50 | [^{:tag cgen/var} v]
51 | (when-not (= v %)
52 | (throw (ex-info "Var cannot roundtrip strings through Clojure/var" {:from v :to %}))))
53 |
54 |
55 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ChunkedCons.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich May 25, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | final public class ChunkedCons extends ASeq implements IChunkedSeq{
16 |
17 | private static final long serialVersionUID = 2773920188566401743L;
18 |
19 | final IChunk chunk;
20 | final ISeq _more;
21 |
22 | ChunkedCons(IPersistentMap meta, IChunk chunk, ISeq more){
23 | super(meta);
24 | this.chunk = chunk;
25 | this._more = more;
26 | }
27 |
28 | public ChunkedCons(IChunk chunk, ISeq more){
29 | this(null,chunk, more);
30 | }
31 |
32 | public Obj withMeta(IPersistentMap meta){
33 | if(meta != _meta)
34 | return new ChunkedCons(meta, chunk, _more);
35 | return this;
36 | }
37 |
38 | public Object first(){
39 | return chunk.nth(0);
40 | }
41 |
42 | public ISeq next(){
43 | if(chunk.count() > 1)
44 | return new ChunkedCons(chunk.dropFirst(), _more);
45 | return chunkedNext();
46 | }
47 |
48 | public ISeq more(){
49 | if(chunk.count() > 1)
50 | return new ChunkedCons(chunk.dropFirst(), _more);
51 | if(_more == null)
52 | return PersistentList.EMPTY;
53 | return _more;
54 | }
55 |
56 | public IChunk chunkedFirst(){
57 | return chunk;
58 | }
59 |
60 | public ISeq chunkedNext(){
61 | return chunkedMore().seq();
62 | }
63 |
64 | public ISeq chunkedMore(){
65 | if(_more == null)
66 | return PersistentList.EMPTY;
67 | return _more;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/AFunction.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Dec 16, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | import java.io.Serializable;
16 | import java.util.Comparator;
17 |
18 | public abstract class AFunction extends AFn implements IObj, Comparator, Fn, Serializable {
19 |
20 | private static final long serialVersionUID = 4469383498184457675L;
21 |
22 | public volatile MethodImplCache __methodImplCache;
23 |
24 | public IPersistentMap meta(){
25 | return null;
26 | }
27 |
28 | public IObj withMeta(final IPersistentMap meta){
29 | if(meta == null)
30 | return this;
31 | return new RestFn(){
32 | protected Object doInvoke(Object args) {
33 | return AFunction.this.applyTo((ISeq) args);
34 | }
35 |
36 | public IPersistentMap meta(){
37 | return meta;
38 | }
39 |
40 | public IObj withMeta(IPersistentMap newMeta){
41 | if(meta == newMeta)
42 | return this;
43 | return AFunction.this.withMeta(newMeta);
44 | }
45 |
46 | public int getRequiredArity(){
47 | return 0;
48 | }
49 | };
50 | }
51 |
52 | public int compare(Object o1, Object o2){
53 | Object o = invoke(o1, o2);
54 |
55 | if(o instanceof Boolean)
56 | {
57 | if(RT.booleanCast(o))
58 | return -1;
59 | return RT.booleanCast(invoke(o2,o1))? 1 : 0;
60 | }
61 |
62 | Number n = (Number) o;
63 | return n.intValue();
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/TaggedLiteral.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | public class TaggedLiteral implements ILookup {
14 |
15 | public static final Keyword TAG_KW = Keyword.intern("tag");
16 | public static final Keyword FORM_KW = Keyword.intern("form");
17 |
18 | public final Symbol tag;
19 | public final Object form;
20 |
21 | public static TaggedLiteral create(Symbol tag, Object form) {
22 | return new TaggedLiteral(tag, form);
23 | }
24 |
25 | private TaggedLiteral(Symbol tag, Object form){
26 | this.tag = tag;
27 | this.form = form;
28 | }
29 |
30 | public Object valAt(Object key) {
31 | return valAt(key, null);
32 | }
33 |
34 | public Object valAt(Object key, Object notFound) {
35 | if (FORM_KW.equals(key)) {
36 | return this.form;
37 | } else if (TAG_KW.equals(key)) {
38 | return this.tag;
39 | } else {
40 | return notFound;
41 | }
42 | }
43 |
44 | @Override
45 | public boolean equals(Object o) {
46 | if (this == o) return true;
47 | if (o == null || getClass() != o.getClass()) return false;
48 |
49 | TaggedLiteral that = (TaggedLiteral) o;
50 |
51 | if (form != null ? !form.equals(that.form) : that.form != null) return false;
52 | if (tag != null ? !tag.equals(that.tag) : that.tag != null) return false;
53 |
54 | return true;
55 | }
56 |
57 | @Override
58 | public int hashCode() {
59 | int result = Util.hash(tag);
60 | result = 31 * result + Util.hash(form);
61 | return result;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ArrayChunk.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich May 24, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | import java.io.Serializable;
16 |
17 | public final class ArrayChunk implements IChunk, Serializable {
18 |
19 | private static final long serialVersionUID = -8302142882294545702L;
20 |
21 | final Object[] array;
22 | final int off;
23 | final int end;
24 |
25 | public ArrayChunk(Object[] array){
26 | this(array, 0, array.length);
27 | }
28 |
29 | public ArrayChunk(Object[] array, int off){
30 | this(array, off, array.length);
31 | }
32 |
33 | public ArrayChunk(Object[] array, int off, int end){
34 | this.array = array;
35 | this.off = off;
36 | this.end = end;
37 | }
38 |
39 | public Object nth(int i){
40 | return array[off + i];
41 | }
42 |
43 | public Object nth(int i, Object notFound){
44 | if(i >= 0 && i < count())
45 | return nth(i);
46 | return notFound;
47 | }
48 |
49 | public int count(){
50 | return end - off;
51 | }
52 |
53 | public IChunk dropFirst(){
54 | if(off==end)
55 | throw new IllegalStateException("dropFirst of empty chunk");
56 | return new ArrayChunk(array, off + 1, end);
57 | }
58 |
59 | public Object reduce(IFn f, Object start) {
60 | Object ret = f.invoke(start, array[off]);
61 | if(RT.isReduced(ret))
62 | return ret;
63 | for(int x = off + 1; x < end; x++)
64 | {
65 | ret = f.invoke(ret, array[x]);
66 | if(RT.isReduced(ret))
67 | return ret;
68 | }
69 | return ret;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/clj/clojure/edn.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns ^{:doc "edn reading."
10 | :author "Rich Hickey"}
11 | clojure.edn
12 | (:refer-clojure :exclude [read read-string]))
13 |
14 | (defn read
15 | "Reads the next object from stream, which must be an instance of
16 | java.io.PushbackReader or some derivee. stream defaults to the
17 | current value of *in*.
18 |
19 | Reads data in the edn format (subset of Clojure data):
20 | http://edn-format.org
21 |
22 | opts is a map that can include the following keys:
23 | :eof - value to return on end-of-file. When not supplied, eof throws an exception.
24 | :readers - a map of tag symbols to data-reader functions to be considered before default-data-readers.
25 | When not supplied, only the default-data-readers will be used.
26 | :default - A function of two args, that will, if present and no reader is found for a tag,
27 | be called with the tag and the value."
28 |
29 | {:added "1.5"}
30 | ([]
31 | (read *in*))
32 | ([stream]
33 | (read {} stream))
34 | ([opts stream]
35 | (clojure.lang.EdnReader/read stream opts)))
36 |
37 | (defn read-string
38 | "Reads one object from the string s. Returns nil when s is nil or empty.
39 |
40 | Reads data in the edn format (subset of Clojure data):
41 | http://edn-format.org
42 |
43 | opts is a map as per clojure.edn/read"
44 | {:added "1.5"}
45 | ([s] (read-string {:eof nil} s))
46 | ([opts s] (when s (clojure.lang.EdnReader/readString s opts))))
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/FnLoaderThunk.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich 2/28/11 */
12 |
13 | package clojure.lang;
14 |
15 | public class FnLoaderThunk extends RestFn{
16 |
17 | private static final long serialVersionUID = 2194257205455463687L;
18 |
19 | final Var v;
20 | final ClassLoader loader;
21 | final String fnClassName;
22 | IFn fn;
23 |
24 | public FnLoaderThunk(Var v, String fnClassName){
25 | this.v = v;
26 | this.loader = (ClassLoader) RT.FN_LOADER_VAR.get();
27 | this.fnClassName = fnClassName;
28 | fn = null;
29 | }
30 |
31 | public Object invoke(Object arg1) {
32 | load();
33 | return fn.invoke(arg1);
34 | }
35 |
36 | public Object invoke(Object arg1, Object arg2) {
37 | load();
38 | return fn.invoke(arg1,arg2);
39 | }
40 |
41 | public Object invoke(Object arg1, Object arg2, Object arg3) {
42 | load();
43 | return fn.invoke(arg1,arg2,arg3);
44 | }
45 |
46 | protected Object doInvoke(Object args) {
47 | load();
48 | return fn.applyTo((ISeq) args);
49 | }
50 |
51 | private void load() {
52 | if(fn == null)
53 | {
54 | try
55 | {
56 | fn = (IFn) Class.forName(fnClassName,true,loader).getDeclaredConstructor().newInstance();
57 | }
58 | catch(Exception e)
59 | {
60 | throw Util.sneakyThrow(e);
61 | }
62 | v.root = fn;
63 | }
64 | }
65 |
66 | public int getRequiredArity(){
67 | return 0;
68 | }
69 |
70 | public IObj withMeta(IPersistentMap meta){
71 | return this;
72 | }
73 |
74 | public IPersistentMap meta(){
75 | return null;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/server.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ; Author: Alex Miller
10 |
11 | (ns clojure.test-clojure.server
12 | (:import java.util.Random)
13 | (:require [clojure.test :refer :all])
14 | (:require [clojure.core.server :as s]))
15 |
16 | (defn check-invalid-opts
17 | [opts msg]
18 | (try
19 | (#'clojure.core.server/validate-opts opts)
20 | (is nil)
21 | (catch Exception e
22 | (is (= (ex-data e) opts))
23 | (is (= msg (.getMessage e))))))
24 |
25 | (defn create-random-thread
26 | []
27 | (Thread.
28 | (fn []
29 | (let [random (new Random)]
30 | (while (not (.isInterrupted (Thread/currentThread)))
31 | (System/setProperty (Integer/toString (.nextInt random)) (Integer/toString (.nextInt random))))))))
32 |
33 | (deftest test-validate-opts
34 | (check-invalid-opts {} "Missing required socket server property :name")
35 | (check-invalid-opts {:name "a" :accept 'clojure.core/+} "Missing required socket server property :port")
36 | (doseq [port [-1 "5" 999999]]
37 | (check-invalid-opts {:name "a" :port port :accept 'clojure.core/+} (str "Invalid socket server port: " port)))
38 | (check-invalid-opts {:name "a" :port 5555} "Missing required socket server property :accept"))
39 |
40 | (deftest test-parse-props
41 | (let [thread (create-random-thread)]
42 | (.start thread)
43 | (Thread/sleep 1000)
44 | (try
45 | (is (>= (count
46 | (#'s/parse-props (System/getProperties))) 0))
47 | (finally (.interrupt thread)))))
48 |
--------------------------------------------------------------------------------
/src/clj/clojure/java/basis/impl.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns clojure.java.basis.impl
10 | (:require
11 | [clojure.edn :as edn]
12 | [clojure.java.io :as jio])
13 | (:import
14 | [java.io PushbackReader]))
15 |
16 | (set! *warn-on-reflection* true)
17 |
18 | (defn- read-edn
19 | "Coerce f to a reader via clojure.java.io/reader and read one edn value.
20 | The reader should contain a single value. Empty input returns nil.
21 | The reader will be read to EOF and closed."
22 | [f]
23 | (let [reader (jio/reader f)
24 | EOF (Object.)]
25 | (with-open [rdr (PushbackReader. reader)]
26 | (let [val (edn/read {:default tagged-literal :eof EOF} rdr)]
27 | (if (identical? EOF val)
28 | nil
29 | (if (not (identical? EOF (edn/read {:eof EOF} rdr)))
30 | (throw (ex-info "Invalid file, expected edn to contain a single value." {}))
31 | val))))))
32 |
33 | (defn- read-basis
34 | "Read basis edn from basis file or throw"
35 | [basis-file]
36 | (when-let [f (jio/file basis-file)]
37 | (when (.exists f)
38 | (read-edn f))))
39 |
40 | ;; delay construction until needed, access via initial-basis
41 | (def init-basis
42 | (delay (read-basis (System/getProperty "clojure.basis"))))
43 |
44 | ;; delay construction until needed, access via current-basis
45 | (def the-basis
46 | (delay (atom @init-basis)))
47 |
48 | (defn update-basis!
49 | "Update the runtime basis by applying f with args"
50 | [f & args]
51 | (apply swap! @the-basis f args))
52 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/java/shell.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | (ns clojure.test-clojure.java.shell
10 | (:use clojure.test
11 | [clojure.java.shell :as sh])
12 | (:import (java.io File)))
13 |
14 | (def platform-enc (.name (java.nio.charset.Charset/defaultCharset)))
15 | (def default-enc "UTF-8")
16 |
17 | (deftest test-parse-args
18 | (are [x y] (= x y)
19 | [[] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args [])
20 | [["ls"] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args ["ls"])
21 | [["ls" "-l"] {:in-enc default-enc :out-enc default-enc :dir nil :env nil}] (#'sh/parse-args ["ls" "-l"])
22 | [["ls"] {:in-enc default-enc :out-enc "ISO-8859-1" :dir nil :env nil}] (#'sh/parse-args ["ls" :out-enc "ISO-8859-1"])
23 | [[] {:in-enc platform-enc :out-enc platform-enc :dir nil :env nil}] (#'sh/parse-args [:in-enc platform-enc :out-enc platform-enc])))
24 |
25 | (deftest test-with-sh-dir
26 | (are [x y] (= x y)
27 | nil *sh-dir*
28 | "foo" (with-sh-dir "foo" *sh-dir*)))
29 |
30 | (deftest test-with-sh-env
31 | (are [x y] (= x y)
32 | nil *sh-env*
33 | {:KEY "VAL"} (with-sh-env {:KEY "VAL"} *sh-env*)))
34 |
35 | (deftest test-as-env-strings
36 | (are [x y] (= x y)
37 | nil (#'sh/as-env-strings nil)
38 | ["FOO=BAR"] (seq (#'sh/as-env-strings {"FOO" "BAR"}))
39 | ["FOO_SYMBOL=BAR"] (seq (#'sh/as-env-strings {'FOO_SYMBOL "BAR"}))
40 | ["FOO_KEYWORD=BAR"] (seq (#'sh/as-env-strings {:FOO_KEYWORD "BAR"}))))
41 |
42 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ReaderConditional.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | public class ReaderConditional implements ILookup {
14 |
15 | public static final Keyword FORM_KW = Keyword.intern("form");
16 | public static final Keyword SPLICING_KW = Keyword.intern("splicing?");
17 |
18 | public final Object form;
19 | public final Boolean splicing;
20 |
21 | public static ReaderConditional create(Object form, boolean splicing) {
22 | return new ReaderConditional(form, splicing);
23 | }
24 |
25 | private ReaderConditional(Object form, boolean splicing){
26 | this.form = form;
27 | this.splicing = splicing;
28 | }
29 |
30 |
31 | public Object valAt(Object key) {
32 | return valAt(key, null);
33 | }
34 |
35 | public Object valAt(Object key, Object notFound) {
36 | if (FORM_KW.equals(key)) {
37 | return this.form;
38 | } else if (SPLICING_KW.equals(key)) {
39 | return this.splicing;
40 | } else {
41 | return notFound;
42 | }
43 | }
44 |
45 |
46 | @Override
47 | public boolean equals(Object o) {
48 | if (this == o) return true;
49 | if (o == null || getClass() != o.getClass()) return false;
50 |
51 | ReaderConditional that = (ReaderConditional) o;
52 |
53 | if (form != null ? !form.equals(that.form) : that.form != null) return false;
54 | if (splicing != null ? !splicing.equals(that.splicing) : that.splicing != null)
55 | return false;
56 | return true;
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | int result = Util.hash(form);
62 | result = 31 * result + Util.hash(splicing);
63 | return result;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/StringSeq.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Dec 6, 2007 */
12 |
13 | package clojure.lang;
14 |
15 | import java.util.Iterator;
16 | import java.util.NoSuchElementException;
17 |
18 | public class StringSeq extends ASeq implements IndexedSeq,IDrop,IReduceInit{
19 |
20 | private static final long serialVersionUID = 7975525539139301753L;
21 |
22 | public final CharSequence s;
23 | public final int i;
24 |
25 | static public StringSeq create(CharSequence s){
26 | if(s.length() == 0)
27 | return null;
28 | return new StringSeq(null, s, 0);
29 | }
30 |
31 | StringSeq(IPersistentMap meta, CharSequence s, int i){
32 | super(meta);
33 | this.s = s;
34 | this.i = i;
35 | }
36 |
37 | public Obj withMeta(IPersistentMap meta){
38 | if(meta == meta())
39 | return this;
40 | return new StringSeq(meta, s, i);
41 | }
42 |
43 | public Object first(){
44 | return Character.valueOf(s.charAt(i));
45 | }
46 |
47 | public ISeq next(){
48 | if(i + 1 < s.length())
49 | return new StringSeq(_meta, s, i + 1);
50 | return null;
51 | }
52 |
53 | public int index(){
54 | return i;
55 | }
56 |
57 | public int count(){
58 | return s.length() - i;
59 | }
60 |
61 | public Sequential drop(int n) {
62 | int ii = i + n;
63 | if (ii < s.length()) {
64 | return new StringSeq(null, s, ii);
65 | } else {
66 | return null;
67 | }
68 | }
69 |
70 | public Object reduce(IFn f, Object start) {
71 | Object acc = start;
72 | for(int ii=i; ii < s.length(); ii++) {
73 | acc = f.invoke(acc, s.charAt(ii));
74 | if(RT.isReduced(acc))
75 | return ((IDeref)acc).deref();
76 | }
77 | return acc;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/.github/workflows/doc-build.yml:
--------------------------------------------------------------------------------
1 | name: Build API Docs
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | commit:
7 | description: 'Commit changes to gh-pages branch'
8 | type: boolean
9 | required: true
10 | default: false
11 |
12 | jobs:
13 | build:
14 | runs-on: ubuntu-latest
15 | steps:
16 |
17 | - name: Set up Java
18 | uses: actions/setup-java@v4
19 | with:
20 | java-version: 8
21 | distribution: 'temurin'
22 |
23 | - name: Set up Clojure
24 | uses: DeLaGuardo/setup-clojure@13.1
25 | with:
26 | cli: 'latest'
27 |
28 | - name: Cache clojure dependencies
29 | uses: actions/cache@v4
30 | with:
31 | path: |
32 | ~/.m2/repository
33 | ~/.gitlibs
34 | key: cljdeps-${{ hashFiles('deps.edn') }}
35 | restore-keys: cljdeps-
36 |
37 | - name: Clone clojure api doc repo
38 | uses: actions/checkout@v4
39 | with:
40 | repository: clojure/clojure-api-doc
41 | path: clojure-api-doc
42 | fetch-depth: 0
43 |
44 | - name: Clone clojure source code repo into clojure-api-doc
45 | uses: actions/checkout@v4
46 | with:
47 | path: clojure-api-doc/repo
48 | fetch-depth: 0
49 |
50 | - name: Clone clojure gh-pages branch into clojure-api-doc
51 | uses: actions/checkout@v4
52 | with:
53 | repository: clojure/clojure
54 | path: clojure-api-doc/repo-docs
55 | ref: 'gh-pages'
56 | fetch-depth: 0
57 |
58 | - name: Install markdown
59 | run: sudo apt install markdown
60 |
61 | - name: Call clojure-api-doc build.sh
62 | run: bash ${GITHUB_WORKSPACE}/clojure-api-doc/build.sh
63 |
64 | - name: Commit
65 | if: ${{inputs.commit}}
66 | run: |
67 | git config --global user.name clojure-build
68 | git config --global user.email "clojure-build@users.noreply.github.com"
69 | cd clojure-api-doc/repo-docs
70 | git add -u -v
71 | git commit -m "Autodoc commit"
72 | git push origin gh-pages
73 |
--------------------------------------------------------------------------------
/src/clj/clojure/template.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ;;; template.clj - anonymous functions that pre-evaluate sub-expressions
10 |
11 | ;; By Stuart Sierra
12 | ;; June 23, 2009
13 |
14 | ;; CHANGE LOG
15 | ;;
16 | ;; June 23, 2009: complete rewrite, eliminated _1,_2,... argument
17 | ;; syntax
18 | ;;
19 | ;; January 20, 2009: added "template?" and checks for valid template
20 | ;; expressions.
21 | ;;
22 | ;; December 15, 2008: first version
23 |
24 |
25 | (ns ^{:doc "Macros that expand to repeated copies of a template expression."
26 | :author "Stuart Sierra"}
27 | clojure.template
28 | (:require [clojure.walk :as walk]))
29 |
30 | (defn apply-template
31 | "For use in macros. argv is an argument list, as in defn. expr is
32 | a quoted expression using the symbols in argv. values is a sequence
33 | of values to be used for the arguments.
34 |
35 | apply-template will recursively replace argument symbols in expr
36 | with their corresponding values, returning a modified expr.
37 |
38 | Example: (apply-template '[x] '(+ x x) '[2])
39 | ;=> (+ 2 2)"
40 | [argv expr values]
41 | (assert (vector? argv))
42 | (assert (every? symbol? argv))
43 | (walk/postwalk-replace (zipmap argv values) expr))
44 |
45 | (defmacro do-template
46 | "Repeatedly copies expr (in a do block) for each group of arguments
47 | in values. values are automatically partitioned by the number of
48 | arguments in argv, an argument vector as in defn.
49 |
50 | Example: (macroexpand '(do-template [x y] (+ y x) 2 4 3 5))
51 | ;=> (do (+ 4 2) (+ 5 3))"
52 | [argv expr & values]
53 | (let [c (count argv)]
54 | `(do ~@(map (fn [a] (apply-template argv expr a))
55 | (partition c values)))))
56 |
--------------------------------------------------------------------------------
/src/jvm/clojure/storm/FormRegistry.java:
--------------------------------------------------------------------------------
1 | package clojure.storm;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.concurrent.ConcurrentHashMap;
6 |
7 | import clojure.lang.IPersistentMap;
8 | import clojure.lang.IPersistentVector;
9 | import clojure.lang.ISeq;
10 | import clojure.lang.Keyword;
11 | import clojure.lang.PersistentVector;
12 | import clojure.lang.RT;
13 |
14 | public class FormRegistry {
15 |
16 | final static Keyword FORM_ID_KEY = Keyword.intern("form", "id");
17 | final static Keyword FORM_NS_KEY = Keyword.intern("form", "ns");
18 | final static Keyword FORM_FORM_KEY = Keyword.intern("form", "form");
19 | final static Keyword FORM_DEF_KIND_KEY = Keyword.intern("form", "def-kind");
20 | final static Keyword FORM_FILE_KEY = Keyword.intern("form", "file");
21 | final static Keyword FORM_LINE_KEY = Keyword.intern("form", "line");
22 | final static Keyword MULTIMETHOD_DISPATCH_VAL_KEY = Keyword.intern("multimethod", "dispatch-val");
23 |
24 | private static ConcurrentHashMap formsTable = new ConcurrentHashMap();
25 |
26 | private static IPersistentMap makeFormMap(IForm form) {
27 | Object frmO = form.getForm();
28 | Keyword frmKind = FormObject.formKind(frmO);
29 |
30 | IPersistentMap ret = RT.map(FORM_ID_KEY, form.getId(),
31 | FORM_NS_KEY, form.getNs(),
32 | FORM_FORM_KEY, frmO,
33 | FORM_DEF_KIND_KEY, frmKind,
34 | FORM_FILE_KEY, form.getSourceFile(),
35 | FORM_LINE_KEY, form.getLine()
36 | );
37 |
38 | if (frmKind==FormObject.DEFMETHOD_KEY)
39 | ret=ret.assoc(MULTIMETHOD_DISPATCH_VAL_KEY, FormObject.multiMethodDispatchVal((ISeq)frmO));
40 |
41 | return ret;
42 | }
43 |
44 | public static void registerForm(int formId, IForm form) {
45 | formsTable.put(formId, form);
46 | }
47 |
48 | public static IPersistentVector getAllForms() {
49 | List forms = new ArrayList();
50 | for(IForm form : formsTable.values())
51 | forms.add(makeFormMap(form));
52 |
53 | return PersistentVector.create(forms);
54 | }
55 |
56 | public static IPersistentMap getForm(int formId) {
57 | return makeFormMap(formsTable.get(formId));
58 | }
59 |
60 |
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/clj/clojure/storm/repl.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.storm.repl
2 | (:import [clojure.storm Emitter Tracer]))
3 |
4 | (defn- call-flow-storm [fn-symb & args]
5 | (try
6 | (let [fqsym (symbol "flow-storm.storm-api" (name fn-symb))
7 | f (requiring-resolve fqsym)]
8 | (when f
9 | (apply f args)))
10 | (catch Throwable _)))
11 |
12 | (defn- print-storm-help []
13 | (println "ClojureStorm Help\n")
14 | (println "ClojureStorm settings: \n")
15 | (println (format " Instrumentation enable : %s" (Emitter/getInstrumentationEnable)))
16 | (when-let [pref (Emitter/makePrefixesString (Emitter/getInstrumentationOnlyPrefixes))]
17 | (println (format " Instrument only prefixes : %s" pref)))
18 | (when-let [pref (Emitter/makePrefixesString (Emitter/getInstrumentationSkipPrefixes))]
19 | (println (format " Instrument skip prefixes : %s" pref)))
20 | (when-let [regex (Emitter/getInstrumentationSkipRegex)]
21 | (println (format " Instrument skip regex : %s" (.pattern regex))))
22 | (println)
23 | (println "ClojureStorm Commands: \n")
24 | (println " :inst - Enable instrumentation.")
25 | (println " :noinst - Disable instrumentation. When instrumentation is disable, everything compiled will not be instrumented.")
26 | (println " Useful for profiling, etc. Code already instrumented will remain instrumented until you recompile it.")
27 | (println)
28 | (println "ClojureStorm JVM config properties: \n")
29 | (println " -Dclojure.storm.instrumentEnable [true|false]")
30 | (println " -Dclojure.storm.instrumentSkipPrefixes Ex: clojure.,flow-storm.,cider.,nrepl.")
31 | (println " -Dclojure.storm.instrumentOnlyPrefixes Ex: my-project-ns.,my-lib-ns.core")
32 | (println)
33 | (call-flow-storm 'print-flow-storm-help))
34 |
35 | (defn maybe-execute-storm-specials [input]
36 | (case input
37 | :help (do (print-storm-help) true)
38 | :inst (do (Emitter/setInstrumentationEnable true) true)
39 | :noinst (do (Emitter/setInstrumentationEnable false) true)
40 | (call-flow-storm 'maybe-execute-flow-storm-specials input)))
41 |
42 | (defn maybe-init-flow-storm []
43 | (call-flow-storm 'start-recorder))
44 |
45 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/IteratorSeq.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | package clojure.lang;
12 |
13 | import java.io.IOException;
14 | import java.io.NotSerializableException;
15 | import java.util.Iterator;
16 |
17 | public class IteratorSeq extends ASeq{
18 |
19 | private static final long serialVersionUID = -2631916503522522760L;
20 |
21 | final Iterator iter;
22 | final State state;
23 |
24 | static class State{
25 | volatile Object val;
26 | volatile Object _rest;
27 | }
28 |
29 | public static IteratorSeq create(Iterator iter){
30 | if(iter.hasNext())
31 | return new IteratorSeq(iter);
32 | return null;
33 | }
34 |
35 | IteratorSeq(Iterator iter){
36 | this.iter = iter;
37 | state = new State();
38 | this.state.val = state;
39 | this.state._rest = state;
40 | }
41 |
42 | IteratorSeq(IPersistentMap meta, Iterator iter, State state){
43 | super(meta);
44 | this.iter = iter;
45 | this.state = state;
46 | }
47 |
48 | public Object first(){
49 | if(state.val == state)
50 | synchronized(state)
51 | {
52 | if(state.val == state)
53 | state.val = iter.next();
54 | }
55 | return state.val;
56 | }
57 |
58 | public ISeq next(){
59 | if(state._rest == state)
60 | synchronized(state)
61 | {
62 | if(state._rest == state)
63 | {
64 | first();
65 | state._rest = create(iter);
66 | }
67 | }
68 | return (ISeq) state._rest;
69 | }
70 |
71 | public IteratorSeq withMeta(IPersistentMap meta){
72 | if(meta() == meta)
73 | return this;
74 | return new IteratorSeq(meta, iter, state);
75 | }
76 |
77 | private void writeObject (java.io.ObjectOutputStream out) throws IOException {
78 | throw new NotSerializableException(getClass().getName());
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/atoms.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 |
9 | ;;Author: Frantisek Sodomka
10 |
11 | (ns clojure.test-clojure.atoms
12 | (:use clojure.test))
13 |
14 | ; http://clojure.org/atoms
15 |
16 | ; atom
17 | ; deref, @-reader-macro
18 | ; swap! reset!
19 | ; compare-and-set!
20 |
21 | (deftest swap-vals-returns-old-value
22 | (let [a (atom 0)]
23 | (is (= [0 1] (swap-vals! a inc)))
24 | (is (= [1 2] (swap-vals! a inc)))
25 | (is (= 2 @a))))
26 |
27 | (deftest deref-swap-arities
28 | (binding [*warn-on-reflection* true]
29 | (let [a (atom 0)]
30 | (is (= [0 1] (swap-vals! a + 1)))
31 | (is (= [1 3] (swap-vals! a + 1 1)))
32 | (is (= [3 6] (swap-vals! a + 1 1 1)))
33 | (is (= [6 10] (swap-vals! a + 1 1 1 1)))
34 | (is (= 10 @a)))))
35 |
36 | (deftest deref-reset-returns-old-value
37 | (let [a (atom 0)]
38 | (is (= [0 :b] (reset-vals! a :b)))
39 | (is (= [:b 45M] (reset-vals! a 45M)))
40 | (is (= 45M @a))))
41 |
42 | (deftest reset-on-deref-reset-equality
43 | (let [a (atom :usual-value)]
44 | (is (= :usual-value (reset! a (first (reset-vals! a :almost-never-seen-value)))))))
45 |
46 | (deftest atoms-are-suppliers
47 | (let [a (atom 10)]
48 | (is (instance? java.util.function.Supplier a))
49 | (is (= 10 (.get ^java.util.function.Supplier a)))
50 | (swap! a inc)
51 | (is (= 11 (.get ^java.util.function.Supplier a)))
52 |
53 | (is (instance? java.util.function.IntSupplier a))
54 | (is (= 11 (.getAsInt a)))
55 |
56 | (is (instance? java.util.function.LongSupplier a))
57 | (is (= 11 (.getAsLong a)))
58 |
59 | (is (instance? java.util.function.BooleanSupplier a))
60 | (is (true? (.getAsBoolean a)))
61 |
62 | (is (instance? java.util.function.DoubleSupplier a))
63 | (is (= 11.0 (.getAsDouble a)))))
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/EnumerationSeq.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Mar 3, 2008 */
12 |
13 | package clojure.lang;
14 |
15 | import java.io.IOException;
16 | import java.io.NotSerializableException;
17 | import java.util.Enumeration;
18 |
19 | public class EnumerationSeq extends ASeq{
20 |
21 | private static final long serialVersionUID = 5227192199685595994L;
22 |
23 | final Enumeration iter;
24 | final State state;
25 |
26 | static class State{
27 | volatile Object val;
28 | volatile Object _rest;
29 | }
30 |
31 | public static EnumerationSeq create(Enumeration iter){
32 | if(iter.hasMoreElements())
33 | return new EnumerationSeq(iter);
34 | return null;
35 | }
36 |
37 | EnumerationSeq(Enumeration iter){
38 | this.iter = iter;
39 | state = new State();
40 | this.state.val = state;
41 | this.state._rest = state;
42 | }
43 |
44 | EnumerationSeq(IPersistentMap meta, Enumeration iter, State state){
45 | super(meta);
46 | this.iter = iter;
47 | this.state = state;
48 | }
49 |
50 | public Object first(){
51 | if(state.val == state)
52 | synchronized(state)
53 | {
54 | if(state.val == state)
55 | state.val = iter.nextElement();
56 | }
57 | return state.val;
58 | }
59 |
60 | public ISeq next(){
61 | if(state._rest == state)
62 | synchronized(state)
63 | {
64 | if(state._rest == state)
65 | {
66 | first();
67 | state._rest = create(iter);
68 | }
69 | }
70 | return (ISeq) state._rest;
71 | }
72 |
73 | public EnumerationSeq withMeta(IPersistentMap meta){
74 | if(meta() == meta)
75 | return this;
76 | return new EnumerationSeq(meta, iter, state);
77 | }
78 |
79 | private void writeObject (java.io.ObjectOutputStream out) throws IOException {
80 | throw new NotSerializableException(getClass().getName());
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ARef.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Jan 1, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | import java.util.Map;
16 |
17 | public abstract class ARef extends AReference implements IRef{
18 | protected volatile IFn validator = null;
19 | private volatile IPersistentMap watches = PersistentHashMap.EMPTY;
20 |
21 | public ARef(){
22 | super();
23 | }
24 |
25 | public ARef(IPersistentMap meta){
26 | super(meta);
27 | }
28 |
29 | void validate(IFn vf, Object val){
30 | try
31 | {
32 | if(vf != null && !RT.booleanCast(vf.invoke(val)))
33 | throw new IllegalStateException("Invalid reference state");
34 | }
35 | catch(RuntimeException re)
36 | {
37 | throw re;
38 | }
39 | catch(Exception e)
40 | {
41 | throw new IllegalStateException("Invalid reference state", e);
42 | }
43 | }
44 |
45 | void validate(Object val){
46 | validate(validator, val);
47 | }
48 |
49 | public void setValidator(IFn vf){
50 | validate(vf, deref());
51 | validator = vf;
52 | }
53 |
54 | public IFn getValidator(){
55 | return validator;
56 | }
57 |
58 | public IPersistentMap getWatches(){
59 | return watches;
60 | }
61 |
62 | synchronized public IRef addWatch(Object key, IFn callback){
63 | watches = watches.assoc(key, callback);
64 | return this;
65 | }
66 |
67 | synchronized public IRef removeWatch(Object key){
68 | watches = watches.without(key);
69 | return this;
70 | }
71 |
72 | public void notifyWatches(Object oldval, Object newval){
73 | IPersistentMap ws = watches;
74 | if(ws.count() > 0)
75 | {
76 | for(ISeq s = ws.seq(); s != null; s = s.next())
77 | {
78 | Map.Entry e = (Map.Entry) s.first();
79 | IFn fn = (IFn) e.getValue();
80 | if(fn != null)
81 | fn.invoke(e.getKey(), this, oldval, newval);
82 | }
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/clj/clojure/pprint.clj:
--------------------------------------------------------------------------------
1 | ;;; pprint.clj -- Pretty printer and Common Lisp compatible format function (cl-format) for Clojure
2 |
3 | ; Copyright (c) Rich Hickey. All rights reserved.
4 | ; The use and distribution terms for this software are covered by the
5 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
6 | ; which can be found in the file epl-v10.html at the root of this distribution.
7 | ; By using this software in any fashion, you are agreeing to be bound by
8 | ; the terms of this license.
9 | ; You must not remove this notice, or any other, from this software.
10 |
11 | ;; Author: Tom Faulhaber
12 | ;; April 3, 2009
13 |
14 | (ns
15 | ^{:author "Tom Faulhaber",
16 | :doc "A Pretty Printer for Clojure
17 |
18 | clojure.pprint implements a flexible system for printing structured data
19 | in a pleasing, easy-to-understand format. Basic use of the pretty printer is
20 | simple, just call pprint instead of println. More advanced users can use
21 | the building blocks provided to create custom output formats.
22 |
23 | Out of the box, pprint supports a simple structured format for basic data
24 | and a specialized format for Clojure source code. More advanced formats,
25 | including formats that don't look like Clojure data at all like XML and
26 | JSON, can be rendered by creating custom dispatch functions.
27 |
28 | In addition to the pprint function, this module contains cl-format, a text
29 | formatting function which is fully compatible with the format function in
30 | Common Lisp. Because pretty printing directives are directly integrated with
31 | cl-format, it supports very concise custom dispatch. It also provides
32 | a more powerful alternative to Clojure's standard format function.
33 |
34 | See documentation for pprint and cl-format for more information or
35 | complete documentation on the Clojure web site on GitHub.",
36 | :added "1.2"}
37 | clojure.pprint
38 | (:refer-clojure :exclude (deftype))
39 | (:use [clojure.walk :only [walk]]))
40 |
41 | (set! *warn-on-reflection* true)
42 |
43 | (load "pprint/utilities")
44 | (load "pprint/column_writer")
45 | (load "pprint/pretty_writer")
46 | (load "pprint/pprint_base")
47 | (load "pprint/cl_format")
48 | (load "pprint/dispatch")
49 | (load "pprint/print_table")
50 |
51 | nil
52 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/ProxyHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Oct 4, 2007 */
12 |
13 | package clojure.lang;
14 |
15 | import java.lang.reflect.InvocationHandler;
16 | import java.lang.reflect.Method;
17 |
18 | public class ProxyHandler implements InvocationHandler{
19 | //method-name-string->fn
20 | final IPersistentMap fns;
21 |
22 |
23 | public ProxyHandler(IPersistentMap fns){
24 | this.fns = fns;
25 | }
26 |
27 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable{
28 | Class rt = method.getReturnType();
29 | IFn fn = (IFn) fns.valAt(method.getName());
30 | if(fn == null)
31 | {
32 | if(rt == Void.TYPE)
33 | return null;
34 | else if(method.getName().equals("equals"))
35 | {
36 | return proxy == args[0];
37 | }
38 | else if(method.getName().equals("hashCode"))
39 | {
40 | return System.identityHashCode(proxy);
41 | }
42 | else if(method.getName().equals("toString"))
43 | {
44 | return "Proxy: " + System.identityHashCode(proxy);
45 | }
46 | throw new UnsupportedOperationException();
47 | }
48 | Object ret = fn.applyTo(ArraySeq.create(args));
49 | if(rt == Void.TYPE)
50 | return null;
51 | else if(rt.isPrimitive())
52 | {
53 | if(rt == Character.TYPE)
54 | return ret;
55 | else if(rt == Integer.TYPE)
56 | return ((Number) ret).intValue();
57 | else if(rt == Long.TYPE)
58 | return ((Number) ret).longValue();
59 | else if(rt == Float.TYPE)
60 | return ((Number) ret).floatValue();
61 | else if(rt == Double.TYPE)
62 | return ((Number) ret).doubleValue();
63 | else if(rt == Boolean.TYPE && !(ret instanceof Boolean))
64 | return ret == null ? Boolean.FALSE : Boolean.TRUE;
65 | else if(rt == Byte.TYPE)
66 | return (byte) ((Number) ret).intValue();
67 | else if(rt == Short.TYPE)
68 | return (short) ((Number) ret).intValue();
69 | }
70 | return ret;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/jvm/clojure/storm/FormLocation.java:
--------------------------------------------------------------------------------
1 | package clojure.storm;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.io.InputStreamReader;
6 | import java.io.PushbackReader;
7 |
8 | import clojure.lang.IPersistentMap;
9 | import clojure.lang.Keyword;
10 | import clojure.lang.LineNumberingPushbackReader;
11 | import clojure.lang.LispReader;
12 | import clojure.lang.Namespace;
13 | import clojure.lang.RT;
14 | import clojure.lang.Symbol;
15 | import clojure.lang.Var;
16 |
17 | public class FormLocation implements IForm {
18 | public int formId;
19 | public String sourceFile;
20 | public int line;
21 | public String formNamespace;
22 |
23 | private static Keyword READ_COND_KEY = Keyword.intern(null, "read-cond");
24 | private static Keyword ALLOW_KEY = Keyword.intern(null, "allow");
25 |
26 | public FormLocation(int formId,String sourceFile, String ns, int line) {
27 | this.sourceFile = sourceFile;
28 | this.line = line;
29 | this.formId = formId;
30 | this.formNamespace = ns;
31 | }
32 |
33 | public int getLine() {
34 | return line;
35 | }
36 |
37 | public String getSourceFile() {
38 | return sourceFile;
39 | }
40 |
41 | public Object getForm() {
42 | try {
43 | Namespace ns = Namespace.find(Symbol.intern(formNamespace));
44 |
45 | Var.pushThreadBindings(RT.map(RT.CURRENT_NS, ns));
46 |
47 | IPersistentMap opts = RT.map(READ_COND_KEY, ALLOW_KEY);
48 |
49 | InputStream strm = RT.baseLoader().getResourceAsStream(sourceFile);
50 | if(strm != null) {
51 | LineNumberingPushbackReader rdr = new LineNumberingPushbackReader(new InputStreamReader(strm));
52 |
53 | // discard lines until right before this.line
54 | for(int l=0; l x class .getName symbol))
28 | v))))
29 |
30 | (defn nav
31 | "Returns (possibly transformed) v in the context of coll and k (a
32 | key/index or nil). Callers should attempt to provide the key/index
33 | context k for Indexed/Associative/ILookup colls if possible, but not
34 | to fabricate one e.g. for sequences (pass nil). nav returns the
35 | value of clojure.core.protocols/nav."
36 | [coll k v]
37 | (p/nav coll k v))
38 |
39 | (defn- sortmap [m]
40 | (into (sorted-map) m))
41 |
42 | (extend-protocol p/Datafiable
43 | Throwable
44 | (datafy [x]
45 | (Throwable->map x))
46 |
47 | clojure.lang.IRef
48 | (datafy [r]
49 | (with-meta [(deref r)] (meta r)))
50 |
51 | clojure.lang.Namespace
52 | (datafy [n]
53 | (with-meta {:name (.getName n)
54 | :publics (-> n ns-publics sortmap)
55 | :imports (-> n ns-imports sortmap)
56 | :interns (-> n ns-interns sortmap)}
57 | (meta n)))
58 |
59 | java.lang.Class
60 | (datafy [c]
61 | (let [{:keys [members] :as ret} ((requiring-resolve 'clojure.reflect/reflect) c)]
62 | (assoc ret :name (-> c .getName symbol) :members (->> members (group-by :name) sortmap)))))
63 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/test_fixtures.clj:
--------------------------------------------------------------------------------
1 | ; Copyright (c) Rich Hickey. All rights reserved.
2 | ; The use and distribution terms for this software are covered by the
3 | ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ; which can be found in the file epl-v10.html at the root of this distribution.
5 | ; By using this software in any fashion, you are agreeing to be bound by
6 | ; the terms of this license.
7 | ; You must not remove this notice, or any other, from this software.
8 | ;
9 | ;;; test_fixtures.clj: unit tests for fixtures in test.clj
10 |
11 | ;; by Stuart Sierra
12 | ;; March 28, 2009
13 |
14 | (ns clojure.test-clojure.test-fixtures
15 | (:use clojure.test))
16 |
17 | (declare ^:dynamic *a* ^:dynamic *b* ^:dynamic *c* ^:dynamic *d*)
18 |
19 | (def ^:dynamic *n* 0)
20 |
21 | (defn fixture-a [f]
22 | (binding [*a* 3] (f)))
23 |
24 | (defn fixture-b [f]
25 | (binding [*b* 5] (f)))
26 |
27 | (defn fixture-c [f]
28 | (binding [*c* 7] (f)))
29 |
30 | (defn fixture-d [f]
31 | (binding [*d* 11] (f)))
32 |
33 | (defn inc-n-fixture [f]
34 | (binding [*n* (inc *n*)] (f)))
35 |
36 | (def side-effects (atom 0))
37 | (defn side-effecting-fixture [f]
38 | (swap! side-effects inc)
39 | (f))
40 |
41 | (use-fixtures :once fixture-a fixture-b)
42 |
43 | (use-fixtures :each fixture-c fixture-d inc-n-fixture side-effecting-fixture)
44 | (use-fixtures :each fixture-c fixture-d inc-n-fixture side-effecting-fixture)
45 |
46 | (deftest can-use-once-fixtures
47 | (is (= 3 *a*))
48 | (is (= 5 *b*)))
49 |
50 | (deftest can-use-each-fixtures
51 | (is (= 7 *c*))
52 | (is (= 11 *d*)))
53 |
54 | (deftest use-fixtures-replaces
55 | (is (= *n* 1)))
56 |
57 | (deftest can-run-a-single-test-with-fixtures
58 | ;; We have to use a side-effecting fixture to test that the fixtures are
59 | ;; running, in order to distinguish fixtures run because of our call to
60 | ;; test-vars below from the same fixtures running prior to this test
61 | (let [side-effects-so-far @side-effects
62 | reported (atom [])]
63 | (binding [report (fn [m] (swap! reported conj (:type m)))]
64 | (test-vars [#'can-use-each-fixtures]))
65 | (is (= [:begin-test-var :pass :pass :end-test-var] @reported))
66 | (is (= (inc side-effects-so-far) @side-effects))))
67 |
68 | (defn should-not-trigger-fixtures [])
69 |
70 | (deftest a-var-lacking-test-meta-should-not-trigger-fixtures
71 | (let [side-effects-so-far @side-effects]
72 | (test-vars [#'should-not-trigger-fixtures])
73 | (is (= side-effects-so-far @side-effects))))
74 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/reflect.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.reflect
2 | (:use clojure.data [clojure.reflect :as reflect] clojure.test clojure.pprint)
3 | (:import [clojure.reflect AsmReflector JavaReflector]
4 | [reflector IBar$Factory]))
5 |
6 | (defn nodiff
7 | [x y]
8 | (let [[x-only y-only common] (diff x y)]
9 | (when (or x-only y-only)
10 | (is false (with-out-str (pprint {:x-only x-only
11 | :y-only y-only
12 | :common common}))))))
13 |
14 | #_(deftest compare-reflect-and-asm
15 | (let [cl (.getContextClassLoader (Thread/currentThread))
16 | asm-reflector (AsmReflector. cl)
17 | java-reflector (JavaReflector. cl)]
18 | (doseq [classname '[java.lang.Runnable
19 | java.lang.Object
20 | java.io.FileInputStream
21 | clojure.lang.Compiler
22 | clojure.lang.PersistentVector
23 | java.lang.SuppressWarnings]]
24 | (nodiff (type-reflect classname :reflector asm-reflector)
25 | (type-reflect classname :reflector java-reflector)))))
26 |
27 | (deftest field-descriptor->class-symbol-test
28 | (are [s d] (= s (@#'reflect/field-descriptor->class-symbol d))
29 | 'clojure.asm.Type<><> "[[Lclojure/asm/Type;"
30 | 'int "I"
31 | 'java.lang.Object "Ljava.lang.Object;"))
32 |
33 | (deftest internal-name->class-symbol-test
34 | (are [s n] (= s (@#'reflect/internal-name->class-symbol n))
35 | 'java.lang.Exception "java/lang/Exception"))
36 |
37 | (def inst (IBar$Factory/get))
38 | (deftest invoking-nonpublic-super
39 | (is (= "stuff" (.stuff inst))))
40 |
41 | (defn- checkCLJ2066 [f]
42 | ;; intentionally reflective call
43 | (is (not (nil? (.createXMLStreamReader f (java.io.StringReader. ""))))))
44 |
45 | (defn- checkCLJ2414 [p]
46 | ;; intentionally reflective call
47 | (is (false? (.startsWith p "s"))))
48 |
49 | (deftest invoke-checks-accessibility
50 | ;; CLJ-2066 - reflector finds method in private class. this is invokable, but an illegal access per modules
51 | (checkCLJ2066 (javax.xml.stream.XMLInputFactory/newInstance))
52 |
53 | ;; CLJ-2414 - find default method on interface of inaccessible class
54 | (checkCLJ2414 (java.nio.file.Paths/get "src" (into-array String []))))
55 |
56 | (defn sleep [ms]
57 | ;; in Java <19, does not reflect. Java >= 19, does reflect
58 | (Thread/sleep ms))
59 |
60 |
61 | (deftest check-CLJ-2843
62 | (sleep 1)
63 | (sleep (Integer/valueOf 1)))
64 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/MethodImplCache.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Nov 8, 2009 */
12 |
13 | package clojure.lang;
14 |
15 | import java.util.Map;
16 |
17 | public final class MethodImplCache{
18 |
19 | static public class Entry{
20 | final public Class c;
21 | final public IFn fn;
22 |
23 | public Entry(Class c, IFn fn){
24 | this.c = c;
25 | this.fn = fn;
26 | }
27 | }
28 |
29 | public final IPersistentMap protocol;
30 | public final Symbol sym;
31 | public final Keyword methodk;
32 | public final int shift;
33 | public final int mask;
34 | public final Object[] table; //[class, entry. class, entry ...]
35 | public final Map map;
36 |
37 | Entry mre = null;
38 |
39 | public MethodImplCache(Symbol sym,IPersistentMap protocol, Keyword methodk){
40 | this(sym, protocol, methodk, 0, 0, RT.EMPTY_ARRAY);
41 | }
42 |
43 | public MethodImplCache(Symbol sym, IPersistentMap protocol, Keyword methodk, int shift, int mask, Object[] table){
44 | this.sym = sym;
45 | this.protocol = protocol;
46 | this.methodk = methodk;
47 | this.shift = shift;
48 | this.mask = mask;
49 | this.table = table;
50 | this.map = null;
51 | }
52 |
53 | public MethodImplCache(Symbol sym, IPersistentMap protocol, Keyword methodk, Map map){
54 | this.sym = sym;
55 | this.protocol = protocol;
56 | this.methodk = methodk;
57 | this.shift = 0;
58 | this.mask = 0;
59 | this.table = null;
60 | this.map = map;
61 | }
62 |
63 | public IFn fnFor(Class c){
64 | Entry last = mre;
65 | if(last != null && last.c == c)
66 | return last.fn;
67 | return findFnFor(c);
68 | }
69 |
70 | IFn findFnFor(Class c){
71 | if (map != null)
72 | {
73 | Entry e = (Entry) map.get(c);
74 | mre = e;
75 | return e != null ? e.fn : null;
76 | }
77 | else
78 | {
79 | int idx = ((Util.hash(c) >> shift) & mask) << 1;
80 | if(idx < table.length && table[idx] == c)
81 | {
82 | Entry e = ((Entry) table[idx + 1]);
83 | mre = e;
84 | return e != null ? e.fn : null;
85 | }
86 | return null;
87 | }
88 | }
89 |
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/test/clojure/test_clojure/repl.clj:
--------------------------------------------------------------------------------
1 | (ns clojure.test-clojure.repl
2 | (:use clojure.test
3 | clojure.repl
4 | [clojure.test-helper :only [platform-newlines]]
5 | clojure.test-clojure.repl.example)
6 | (:require [clojure.string :as str]))
7 |
8 | (deftest test-doc
9 | (testing "with namespaces"
10 | (is (= "clojure.pprint"
11 | (second (str/split-lines (with-out-str (doc clojure.pprint)))))))
12 | (testing "with special cases"
13 | (is (= (with-out-str (doc catch)) (with-out-str (doc try))))))
14 |
15 | (deftest test-source
16 | (is (= "(defn foo [])" (source-fn 'clojure.test-clojure.repl.example/foo)))
17 | (is (= (platform-newlines "(defn foo [])\n") (with-out-str (source clojure.test-clojure.repl.example/foo))))
18 | (is (nil? (source-fn 'non-existent-fn))))
19 |
20 | (deftest test-source-read-eval-unknown
21 | (is (thrown? IllegalStateException (binding [*read-eval* :unknown] (source reduce)))))
22 |
23 | (deftest test-source-read-eval-false
24 | (is (binding [*read-eval* false] (with-out-str (source reduce)))))
25 |
26 | (deftest test-dir
27 | (is (thrown? Exception (dir-fn 'non-existent-ns)))
28 | (is (= '[bar foo] (dir-fn 'clojure.test-clojure.repl.example)))
29 | (binding [*ns* (the-ns 'clojure.test-clojure.repl)]
30 | (is (= (dir-fn 'clojure.string) (dir-fn 'str))))
31 | (is (= (platform-newlines "bar\nfoo\n") (with-out-str (dir clojure.test-clojure.repl.example)))))
32 |
33 | (deftest test-apropos
34 | (testing "with a regular expression"
35 | (is (= '[clojure.core/defmacro] (apropos #"^defmacro$")))
36 | (is (some #{'clojure.core/defmacro} (apropos #"def.acr.")))
37 | (is (= [] (apropos #"nothing-has-this-name"))))
38 |
39 | (testing "with a string"
40 | (is (some #{'clojure.core/defmacro} (apropos "defmacro")))
41 | (is (some #{'clojure.core/defmacro} (apropos "efmac")))
42 | (is (= [] (apropos "nothing-has-this-name"))))
43 |
44 | (testing "with a symbol"
45 | (is (some #{'clojure.core/defmacro} (apropos 'defmacro)))
46 | (is (some #{'clojure.core/defmacro} (apropos 'efmac)))
47 | (is (= [] (apropos 'nothing-has-this-name)))))
48 |
49 |
50 | (defmacro call-ns
51 | "Call ns with a unique namespace name. Return the result of calling ns"
52 | [] `(ns a#))
53 | (defmacro call-ns-sym
54 | "Call ns wih a unique namespace name. Return the namespace symbol."
55 | [] `(do (ns a#) 'a#))
56 |
57 | (deftest test-dynamic-ns
58 | (testing "a call to ns returns nil"
59 | (is (= nil (call-ns))))
60 | (testing "requiring a dynamically created ns should not throw an exception"
61 | (is (= nil (let [a (call-ns-sym)] (require a))))))
62 |
--------------------------------------------------------------------------------
/test/java/clojure/test/SwissArmy.java:
--------------------------------------------------------------------------------
1 | package clojure.test;
2 |
3 | import clojure.java.api.Clojure;
4 | import clojure.lang.IFn;
5 |
6 | public class SwissArmy {
7 | public static String doppelganger = "static-field";
8 | public String ctorId;
9 | public static IFn idFn = Clojure.var("clojure.core", "identity");
10 |
11 | public SwissArmy() {this.ctorId = "1";}
12 | public SwissArmy(int a, long b) {this.ctorId = "2";}
13 | public SwissArmy(long a, int b) {this.ctorId = "3";}
14 | public SwissArmy(boolean a, boolean b) {this.ctorId = "4";}
15 | public SwissArmy(long[] a, int b) {this.ctorId = "5";}
16 | public SwissArmy(String[] a, long b) {this.ctorId = "6";}
17 | public SwissArmy(int[][] a, long b) {this.ctorId = "7";}
18 |
19 | public String noArgs() {return "";}
20 | public String twoArgsIL(int a, long b) {return "int-long";}
21 | public String twoArgsLI(long a, int b) {return "long-int";}
22 | public String twoArgsBB(boolean a, boolean b) {return "boolean-boolean";}
23 | // public String twoArgsLAI(long[] a, int b) {return "long<>-int";}
24 | public String twoArgsSAL(String[] a, long b) {return "java.lang.String<>-long";}
25 | // public String twoArgsMDIL(int[][] a, long b) {return "int<><>-long";}
26 | public String arityOverloadMethod(int a) {return "int";}
27 | public String arityOverloadMethod(int a, int b) {return "int-int";}
28 | public String arityOverloadMethod(int a, int b, int c) {return "int-int-int";}
29 | public String doppelganger(int a, int b) {return "int-int";}
30 |
31 | public static String staticNoArgs() {return "";}
32 | public static String staticOneArg(boolean a) {return "boolean";}
33 | public static String staticTwoArgsIL(int a, long b) {return "int-long";}
34 | public static String staticTwoArgsLI(long a, int b) {return "long-int";}
35 | public static String staticTwoArgsBB(boolean a, boolean b) {return "boolean-boolean";}
36 | public static String staticTwoArgsSAL(String[] a, long b) {return "java.lang.String<>-long";}
37 | // public static String staticTwoArgsMDIL(int[][] a, long b) {return "int<><>-long";}
38 | // public static String couldReflect(long[] a, int b) {return "long<>-int";}
39 | public static String couldReflect(Object[] a, int b) {return "java.lang.Object<>-int";}
40 | public static String staticArityOverloadMethod(int a) {return "int";}
41 | public static String staticArityOverloadMethod(int a, int b) {return "int-int";}
42 | public static String staticArityOverloadMethod(int a, int b, int c) {return "int-int-int";}
43 | public static String doppelganger(int a, int b, long c) {return "int-int-long";}
44 | public static String doppelganger() {return "";}
45 | }
46 |
--------------------------------------------------------------------------------
/src/jvm/clojure/lang/XMLHandler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rich Hickey. All rights reserved.
3 | * The use and distribution terms for this software are covered by the
4 | * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
5 | * which can be found in the file epl-v10.html at the root of this distribution.
6 | * By using this software in any fashion, you are agreeing to be bound by
7 | * the terms of this license.
8 | * You must not remove this notice, or any other, from this software.
9 | **/
10 |
11 | /* rich Dec 17, 2007 */
12 |
13 | package clojure.lang;
14 |
15 | import org.xml.sax.Attributes;
16 | import org.xml.sax.ContentHandler;
17 | import org.xml.sax.Locator;
18 | import org.xml.sax.SAXException;
19 | import org.xml.sax.helpers.DefaultHandler;
20 |
21 | public class XMLHandler extends DefaultHandler{
22 | ContentHandler h;
23 |
24 |
25 | public XMLHandler(ContentHandler h){
26 | this.h = h;
27 | }
28 |
29 | public void setDocumentLocator(Locator locator){
30 | h.setDocumentLocator(locator);
31 | }
32 |
33 | public void startDocument() throws SAXException{
34 | h.startDocument();
35 | }
36 |
37 | public void endDocument() throws SAXException{
38 | h.endDocument();
39 | }
40 |
41 | public void startPrefixMapping(String prefix, String uri) throws SAXException{
42 | h.startPrefixMapping(prefix, uri);
43 | }
44 |
45 | public void endPrefixMapping(String prefix) throws SAXException{
46 | h.endPrefixMapping(prefix);
47 | }
48 |
49 | public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException{
50 | h.startElement(uri, localName, qName, atts);
51 | }
52 |
53 | public void endElement(String uri, String localName, String qName) throws SAXException{
54 | h.endElement(uri, localName, qName);
55 | }
56 |
57 | public void characters(char ch[], int start, int length) throws SAXException{
58 | h.characters(ch, start, length);
59 | }
60 |
61 | public void ignorableWhitespace(char ch[], int start, int length) throws SAXException{
62 | h.ignorableWhitespace(ch, start, length);
63 | }
64 |
65 | public void processingInstruction(String target, String data) throws SAXException{
66 | h.processingInstruction(target, data);
67 | }
68 |
69 | public void skippedEntity(String name) throws SAXException{
70 | h.skippedEntity(name);
71 | }
72 |
73 | /*
74 | public static void main(String[] args){
75 | try
76 | {
77 | ContentHandler dummy = new DefaultHandler();
78 | SAXParserFactory f = SAXParserFactory.newInstance();
79 | //f.setNamespaceAware(true);
80 | SAXParser p = f.newSAXParser();
81 | p.parse("http://arstechnica.com/journals.rssx",new XMLHandler(dummy));
82 | }
83 | catch(Exception e)
84 | {
85 | e.printStackTrace();
86 | }
87 | }
88 | //*/
89 | }
90 |
--------------------------------------------------------------------------------
/src/jvm/clojure/asm/CurrentFrame.java:
--------------------------------------------------------------------------------
1 | // ASM: a very small and fast Java bytecode manipulation framework
2 | // Copyright (c) 2000-2011 INRIA, France Telecom
3 | // All rights reserved.
4 | //
5 | // Redistribution and use in source and binary forms, with or without
6 | // modification, are permitted provided that the following conditions
7 | // are met:
8 | // 1. Redistributions of source code must retain the above copyright
9 | // notice, this list of conditions and the following disclaimer.
10 | // 2. Redistributions in binary form must reproduce the above copyright
11 | // notice, this list of conditions and the following disclaimer in the
12 | // documentation and/or other materials provided with the distribution.
13 | // 3. Neither the name of the copyright holders nor the names of its
14 | // contributors may be used to endorse or promote products derived from
15 | // this software without specific prior written permission.
16 | //
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 | // THE POSSIBILITY OF SUCH DAMAGE.
28 |
29 | package clojure.asm;
30 |
31 | /**
32 | * Information about the input stack map frame at the "current" instruction of a method. This is
33 | * implemented as a Frame subclass for a "basic block" containing only one instruction.
34 | *
35 | * @author Eric Bruneton
36 | */
37 | final class CurrentFrame extends Frame {
38 |
39 | CurrentFrame(final Label owner) {
40 | super(owner);
41 | }
42 |
43 | /**
44 | * Sets this CurrentFrame to the input stack map frame of the next "current" instruction, i.e. the
45 | * instruction just after the given one. It is assumed that the value of this object when this
46 | * method is called is the stack map frame status just before the given instruction is executed.
47 | */
48 | @Override
49 | void execute(
50 | final int opcode, final int arg, final Symbol symbolArg, final SymbolTable symbolTable) {
51 | super.execute(opcode, arg, symbolArg, symbolTable);
52 | Frame successor = new Frame(null);
53 | merge(symbolTable, successor, 0);
54 | copyFrom(successor);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/jvm/clojure/java/api/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 | Clojure interop from Java.
14 |
15 |
The clojure.java.api package provides a minimal interface to bootstrap
16 | Clojure access from other JVM languages. It does this by providing:
17 |
18 |
19 |
20 |
The ability to use Clojure's namespaces to locate an arbitrary
21 | var, returning the
22 | var's clojure.lang.IFn interface.
23 |
A convenience method read for reading data using
24 | Clojure's edn reader
25 |
26 |
27 |
IFns provide complete access to
28 | Clojure's APIs.
29 | You can also access any other library written in Clojure, after adding
30 | either its source or compiled form to the classpath.
31 |
32 |
The public Java API for Clojure consists of the following classes
33 | and interfaces:
34 |
35 |
36 |
37 |
clojure.java.api.Clojure
38 |
clojure.lang.IFn
39 |
40 |
41 |
All other Java classes should be treated as implementation details,
42 | and applications should avoid relying on them.