├── .editorconfig ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── README.md ├── VERSION ├── astylerc ├── build.xml ├── circle.yml ├── doc └── clojure │ └── pprint │ ├── CommonLispFormat.markdown │ └── PrettyPrinting.markdown ├── etc ├── bin │ ├── antsetup.sh │ ├── check-changelog.sh │ ├── check-whitespace.sh │ ├── circle-deps.sh │ ├── make-astyle.sh │ ├── run-tests.sh │ ├── test-cider.sh │ └── whitespace.sh ├── img │ ├── gh-banner.png │ ├── icon-128x128.png │ ├── icon-64x64.png │ ├── icon.png │ └── large-banner.png └── licenses │ ├── apache.txt │ ├── epl-v10.txt │ └── inria.txt ├── pom.xml ├── project.clj ├── settings.xml ├── src ├── assembly │ ├── distribution.xml │ └── slim.xml ├── clj │ └── clojure │ │ ├── core.clj │ │ ├── core │ │ ├── compiler.clj │ │ ├── protocols.clj │ │ ├── reducers.clj │ │ └── server.clj │ │ ├── core_deftype.clj │ │ ├── core_print.clj │ │ ├── core_proxy.clj │ │ ├── data.clj │ │ ├── edn.clj │ │ ├── genclass.clj │ │ ├── gvec.clj │ │ ├── inspector.clj │ │ ├── instant.clj │ │ ├── java │ │ ├── browse.clj │ │ ├── browse_ui.clj │ │ ├── io.clj │ │ ├── javadoc.clj │ │ └── shell.clj │ │ ├── main.clj │ │ ├── parallel.clj │ │ ├── pprint.clj │ │ ├── pprint │ │ ├── cl_format.clj │ │ ├── column_writer.clj │ │ ├── dispatch.clj │ │ ├── pprint_base.clj │ │ ├── pretty_writer.clj │ │ ├── print_table.clj │ │ └── utilities.clj │ │ ├── reflect.clj │ │ ├── reflect │ │ └── java.clj │ │ ├── repl.clj │ │ ├── set.clj │ │ ├── stacktrace.clj │ │ ├── string.clj │ │ ├── template.clj │ │ ├── test.clj │ │ ├── test │ │ ├── junit.clj │ │ └── tap.clj │ │ ├── uuid.clj │ │ ├── walk.clj │ │ ├── xml.clj │ │ └── zip.clj ├── jvm │ └── clojure │ │ ├── asm │ │ ├── AnnotationVisitor.java │ │ ├── AnnotationWriter.java │ │ ├── Attribute.java │ │ ├── ByteVector.java │ │ ├── ClassReader.java │ │ ├── ClassVisitor.java │ │ ├── ClassWriter.java │ │ ├── Context.java │ │ ├── Edge.java │ │ ├── FieldVisitor.java │ │ ├── FieldWriter.java │ │ ├── Frame.java │ │ ├── Handle.java │ │ ├── Handler.java │ │ ├── Item.java │ │ ├── Label.java │ │ ├── MethodVisitor.java │ │ ├── MethodWriter.java │ │ ├── Opcodes.java │ │ ├── Type.java │ │ ├── commons │ │ │ ├── AdviceAdapter.java │ │ │ ├── AnalyzerAdapter.java │ │ │ ├── CodeSizeEvaluator.java │ │ │ ├── GeneratorAdapter.java │ │ │ ├── InstructionAdapter.java │ │ │ ├── LocalVariablesSorter.java │ │ │ ├── Method.java │ │ │ ├── SerialVersionUIDAdder.java │ │ │ ├── StaticInitMerger.java │ │ │ ├── TableSwitchGenerator.java │ │ │ └── package.html │ │ └── package.html │ │ ├── java │ │ └── api │ │ │ ├── Clojure.java │ │ │ └── package.html │ │ ├── lang │ │ ├── AFn.java │ │ ├── AFunction.java │ │ ├── AMapEntry.java │ │ ├── APersistentMap.java │ │ ├── APersistentSet.java │ │ ├── APersistentVector.java │ │ ├── ARef.java │ │ ├── AReference.java │ │ ├── ASeq.java │ │ ├── ATransientMap.java │ │ ├── ATransientSet.java │ │ ├── Agent.java │ │ ├── ArityException.java │ │ ├── ArrayChunk.java │ │ ├── ArrayIter.java │ │ ├── ArraySeq.java │ │ ├── Associative.java │ │ ├── Atom.java │ │ ├── BigInt.java │ │ ├── Binding.java │ │ ├── Box.java │ │ ├── ChunkBuffer.java │ │ ├── ChunkedCons.java │ │ ├── Compile.java │ │ ├── Compiler.java │ │ ├── Cons.java │ │ ├── Counted.java │ │ ├── Cycle.java │ │ ├── Delay.java │ │ ├── DynamicClassLoader.java │ │ ├── EdnReader.java │ │ ├── EnumerationSeq.java │ │ ├── ExceptionInfo.java │ │ ├── Fn.java │ │ ├── FnLoaderThunk.java │ │ ├── IAtom.java │ │ ├── IBlockingDeref.java │ │ ├── IChunk.java │ │ ├── IChunkedSeq.java │ │ ├── IDeref.java │ │ ├── IEditableCollection.java │ │ ├── IExceptionInfo.java │ │ ├── IFn.java │ │ ├── IHashEq.java │ │ ├── IKVReduce.java │ │ ├── IKeywordLookup.java │ │ ├── ILookup.java │ │ ├── ILookupSite.java │ │ ├── ILookupThunk.java │ │ ├── IMapEntry.java │ │ ├── IMapIterable.java │ │ ├── IMeta.java │ │ ├── IObj.java │ │ ├── IPending.java │ │ ├── IPersistentCollection.java │ │ ├── IPersistentList.java │ │ ├── IPersistentMap.java │ │ ├── IPersistentSet.java │ │ ├── IPersistentStack.java │ │ ├── IPersistentVector.java │ │ ├── IProxy.java │ │ ├── IRecord.java │ │ ├── IReduce.java │ │ ├── IReduceInit.java │ │ ├── IRef.java │ │ ├── IReference.java │ │ ├── ISeq.java │ │ ├── ITransientAssociative.java │ │ ├── ITransientCollection.java │ │ ├── ITransientMap.java │ │ ├── ITransientSet.java │ │ ├── ITransientVector.java │ │ ├── IType.java │ │ ├── Indexed.java │ │ ├── IndexedSeq.java │ │ ├── Intrinsics.java │ │ ├── Iterate.java │ │ ├── IteratorSeq.java │ │ ├── Keyword.java │ │ ├── KeywordLookupSite.java │ │ ├── LazilyPersistentVector.java │ │ ├── LazySeq.java │ │ ├── LineNumberingPushbackReader.java │ │ ├── LispReader.java │ │ ├── LockingTransaction.java │ │ ├── LongRange.java │ │ ├── MapEntry.java │ │ ├── MapEquivalence.java │ │ ├── MethodImplCache.java │ │ ├── MultiFn.java │ │ ├── Murmur3.java │ │ ├── Named.java │ │ ├── Namespace.java │ │ ├── Numbers.java │ │ ├── Obj.java │ │ ├── PersistentArrayMap.java │ │ ├── PersistentHashMap.java │ │ ├── PersistentHashSet.java │ │ ├── PersistentList.java │ │ ├── PersistentQueue.java │ │ ├── PersistentStructMap.java │ │ ├── PersistentTreeMap.java │ │ ├── PersistentTreeSet.java │ │ ├── PersistentVector.java │ │ ├── ProxyHandler.java │ │ ├── RT.java │ │ ├── Range.java │ │ ├── Ratio.java │ │ ├── ReaderConditional.java │ │ ├── RecordIterator.java │ │ ├── Reduced.java │ │ ├── Ref.java │ │ ├── Reflector.java │ │ ├── Repeat.java │ │ ├── Repl.java │ │ ├── RestFn.java │ │ ├── Reversible.java │ │ ├── Script.java │ │ ├── SeqEnumeration.java │ │ ├── SeqIterator.java │ │ ├── Seqable.java │ │ ├── Sequential.java │ │ ├── Settable.java │ │ ├── Sorted.java │ │ ├── StringSeq.java │ │ ├── Symbol.java │ │ ├── TaggedLiteral.java │ │ ├── TransactionalHashMap.java │ │ ├── TransformerIterator.java │ │ ├── Tuple.java │ │ ├── Util.java │ │ ├── Var.java │ │ ├── Volatile.java │ │ ├── WarnBoxedMath.java │ │ ├── XMLHandler.java │ │ └── package.html │ │ └── main.java └── script │ ├── run_test.clj │ └── run_test_generative.clj └── test ├── clojure ├── test_clojure │ ├── agents.clj │ ├── annotations.clj │ ├── annotations │ │ ├── java_5.clj │ │ └── java_6.clj │ ├── api.clj │ ├── atoms.clj │ ├── clojure_set.clj │ ├── clojure_walk.clj │ ├── clojure_xml.clj │ ├── clojure_zip.clj │ ├── compilation.clj │ ├── compilation │ │ ├── clj_over_cljc.clj │ │ ├── clj_over_cljc.cljc │ │ ├── examples.clj │ │ ├── jnt_first.clj │ │ ├── jnt_first.jnt │ │ ├── just_cljc.cljc │ │ ├── line_number_examples.clj │ │ └── load_ns.clj │ ├── control.clj │ ├── data.clj │ ├── data_structures.clj │ ├── data_structures_interop.clj │ ├── def.clj │ ├── delays.clj │ ├── edn.clj │ ├── errors.clj │ ├── evaluation.clj │ ├── fn.clj │ ├── for.clj │ ├── genclass.clj │ ├── genclass │ │ └── examples.clj │ ├── generators.clj │ ├── java │ │ ├── io.clj │ │ ├── javadoc.clj │ │ └── shell.clj │ ├── java_interop.clj │ ├── keywords.clj │ ├── logic.clj │ ├── macros.clj │ ├── main.clj │ ├── metadata.clj │ ├── multimethods.clj │ ├── ns_libs.clj │ ├── numbers.clj │ ├── other_functions.clj │ ├── parallel.clj │ ├── pprint.clj │ ├── pprint │ │ ├── test_cl_format.clj │ │ ├── test_helper.clj │ │ └── test_pretty.clj │ ├── predicates.clj │ ├── printer.clj │ ├── protocols.clj │ ├── protocols │ │ ├── examples.clj │ │ ├── hash_collisions.clj │ │ └── more_examples.clj │ ├── reader.cljc │ ├── reducers.clj │ ├── reflect.clj │ ├── refs.clj │ ├── repl.clj │ ├── repl │ │ └── example.clj │ ├── rt.clj │ ├── sequences.clj │ ├── serialization.clj │ ├── server.clj │ ├── special.clj │ ├── string.clj │ ├── test.clj │ ├── test_fixtures.clj │ ├── transducers.clj │ ├── transients.clj │ ├── try_catch.clj │ ├── vars.clj │ ├── vectors.clj │ └── volatiles.clj └── test_helper.clj └── java ├── clojure └── test │ └── ReflectorTryCatchFixture.java ├── compilation └── TestDispatch.java └── reflector └── IBar.java /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_style = space 7 | insert_final_newline = true 8 | indent_size = 2 9 | max_line_length = 100 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.jar 2 | target 3 | clojure.iws 4 | clojure.ipr 5 | nbproject/private/ 6 | maven-classpath 7 | maven-classpath.properties 8 | .idea/ 9 | user.clj 10 | *.html 11 | .lein-env 12 | *.iml 13 | cider-nrepl 14 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open and 4 | welcoming community, we pledge to respect all people who contribute through reporting issues, 5 | posting feature requests, updating documentation, submitting pull requests or patches, and other 6 | activities. 7 | 8 | We are committed to making participation in this project a harassment-free experience for everyone, 9 | regardless of level of experience, gender, gender identity and expression, sexual orientation, 10 | disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. 11 | 12 | Examples of unacceptable behavior by participants include: 13 | 14 | * The use of sexualized language or imagery 15 | * Personal attacks 16 | * Trolling or insulting/derogatory comments 17 | * Public or private harassment 18 | * Publishing other's private information, such as physical or electronic addresses, without explicit 19 | permission 20 | * Other unethical or unprofessional conduct 21 | 22 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, 23 | code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or 24 | to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, 25 | threatening, offensive, or harmful. 26 | 27 | By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently 28 | applying these principles to every aspect of managing this project. Project maintainers who do not 29 | follow or enforce the Code of Conduct may be permanently removed from the project team. 30 | 31 | This Code of Conduct applies both within project spaces and in public spaces when an individual is 32 | representing the project or its community. 33 | 34 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a 35 | project maintainer at [me+jaunt+coc@arrdem.com](mailto:me+jaunt+coc@arrdem.com). All complaints will 36 | be reviewed and investigated and will result in a response that is deemed necessary and appropriate 37 | to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the 38 | reporter of an incident. 39 | 40 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.3.0, available 41 | at [http://contributor-covenant.org/version/1/3/0/][version] 42 | 43 | [homepage]: http://contributor-covenant.org 44 | [version]: http://contributor-covenant.org/version/1/3/0/ 45 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 0.3.0 2 | -------------------------------------------------------------------------------- /astylerc: -------------------------------------------------------------------------------- 1 | style=java 2 | indent=spaces=2 3 | pad-header 4 | add-brackets 5 | convert-tabs 6 | suffix=none 7 | recursive 8 | convert-tabs 9 | max-code-length=140 10 | lineend=linux -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | java: 3 | version: oraclejdk8 4 | environment: 5 | _JAVA_OPTIONS: -Xmx2g 6 | 7 | dependencies: 8 | cache_directories: 9 | - ~/bin 10 | pre: 11 | - sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0/bin/java 12 | - sudo update-alternatives --set javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 13 | - echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' >> ~/.circlerc 14 | - bash etc/bin/make-astyle.sh 15 | - bash etc/bin/circle-deps.sh 16 | post: 17 | - mvn dependency:resolve-plugins 18 | 19 | test: 20 | pre: 21 | - bash etc/bin/check-whitespace.sh 22 | - bash etc/bin/check-changelog.sh 23 | - lein cljfmt check 24 | - grep -Hnr '[[:blank:]]\+$' src test && exit 1 || exit 0 25 | override: 26 | - bash etc/bin/run-tests.sh: 27 | parallel: true 28 | post: 29 | - ant jar 30 | 31 | deployment: 32 | staging: 33 | branch: /develop/ 34 | commands: 35 | - mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$(cat VERSION)-SNAPSHOT 36 | - mvn -Dmaven.test.skip=true -s settings.xml deploy 37 | release: 38 | tag: /v[0-9]+(\.[0-9]+)*/ 39 | commands: 40 | - mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$(cat VERSION) 41 | - mvn -Dmaven.test.skip=true -s settings.xml deploy 42 | 43 | notify: 44 | webhooks: 45 | - url: https://webhooks.gitter.im/e/568057f9a2c7ed9fb7f1 46 | -------------------------------------------------------------------------------- /etc/bin/antsetup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ROOT=$(git rev-parse --show-toplevel) 3 | mvn -q dependency:build-classpath -Dmdep.outputFile=$ROOT/maven-classpath 4 | cat <$ROOT/maven-classpath.properties 5 | maven.compile.classpath=`cat $ROOT/maven-classpath` 6 | maven.test.classpath=`cat $ROOT/maven-classpath` 7 | EOF 8 | rm $ROOT/maven-classpath 9 | echo "Wrote maven-classpath.properties for standalone ant use" 10 | -------------------------------------------------------------------------------- /etc/bin/check-changelog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BRANCH=$(git name-rev --name-only HEAD) 4 | 5 | case $BRANCH in 6 | master|develop|release*) 7 | exit 0 8 | ;; 9 | 10 | *) 11 | if ! git diff --name-only origin/develop HEAD | grep -ie changelog.md > /dev/null 12 | then 13 | echo "No changelog entry in this patch!" 14 | exit 1 15 | fi 16 | ;; 17 | esac 18 | -------------------------------------------------------------------------------- /etc/bin/check-whitespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | astyle --dry-run --options=astylerc src/jvm/*.java | grep Formatted && exit 1 || exit 0 4 | -------------------------------------------------------------------------------- /etc/bin/circle-deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | M2="$HOME/.m2" 4 | FLAGS="$M2/tags" 5 | mkdir -p "$FLAGS" 6 | FILE="$FLAGS/$(cat pom.xml build.xml etc/bin/circle-deps.sh | grep -v ".*" | shasum -a 512 | awk '{print $1}')" 7 | if [ ! -e "$FILE" ] || (( RANDOM % 2 ==0 )) 8 | then 9 | # Do a deploy 10 | # - Forces a build 11 | # - Forces but does not run tests 12 | # - Uses all plugins 13 | # - Without a profile, the deploy fails 14 | mvn deploy -Dmaven.test.skip=true 15 | 16 | # use the versions plugin 17 | mvn versions:set -DgenerateBackupPoms=false -DnewVersion=whatever 18 | git checkout pom.xml 19 | 20 | # purge jaunt from m2 21 | # no reason to leave those lying about 22 | rm -r "$M2/repository/org/jaunt-lang/jaunt/" 23 | 24 | # leave the flag file behind 25 | touch "$FILE" 26 | fi 27 | -------------------------------------------------------------------------------- /etc/bin/make-astyle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -f ~/bin/astyle ]; then 4 | curl -L http://downloads.sourceforge.net/project/astyle/astyle/astyle%202.05.1/astyle_2.05.1_linux.tar.gz\ 5 | -o astyle.tar.gz 6 | tar -xzf astyle.tar.gz 7 | cd astyle/build/gcc; make 8 | sudo mv bin/astyle ~/bin/ 9 | fi 10 | -------------------------------------------------------------------------------- /etc/bin/run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function do_tests () { 4 | case $CIRCLE_NODE_INDEX in 5 | 0) 6 | ant test-example 2>&1 | tee test-example.log 7 | return $? 8 | ;; 9 | 1) 10 | ant test-generative 2>&1 | tee test-generative.log 11 | return $? 12 | ;; 13 | 2) 14 | bash etc/bin/test-cider.sh 2>&1 | tee test-cider.log 15 | return $? 16 | ;; 17 | esac 18 | } 19 | 20 | mvn clean compile # git info file, classfiles 21 | bash etc/bin/antsetup.sh # set up standalone classpath 22 | 23 | if [ -n "$CIRCLE_NODE_INDEX" ] 24 | then 25 | do_tests 26 | exit $? 27 | else 28 | ( export CIRCLE_NODE_INDEX=0; 29 | do_tests > /dev/null ) & 30 | tex=$1 31 | 32 | ( export CIRCLE_NODE_INDEX=1; 33 | do_tests > /dev/null ) & 34 | teg=$1 35 | 36 | ( export CIRCLE_NODE_INDEX=2; 37 | do_tests > /dev/null ) & 38 | tec=$1 39 | 40 | wait $tex 41 | texr=$? 42 | wait $teg 43 | tegr=$? 44 | wait $tec 45 | tecr=$? 46 | 47 | if [ $texr ] && [ $tegr ] && [ $tecr ] 48 | then 49 | echo "Tests OK!" 50 | else 51 | [ ! $texr ] && echo "Example tests failed, see test-example.log" 52 | [ ! $tegr ] && echo "Generative tests failed, see test-generative.log" 53 | [ ! $tecr ] && echo "CIDER tests failed, see test-cider.log" 54 | echo "Tests failed :(" 55 | exit 1 56 | fi 57 | fi 58 | -------------------------------------------------------------------------------- /etc/bin/test-cider.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION="$(cat VERSION)-test-SNAPSHOT" 4 | mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$VERSION 5 | mvn install -Dmaven.test.skip=true 6 | 7 | if [ ! -d "cider-nrepl" ] 8 | then 9 | git clone git@github.com:clojure-emacs/cider-nrepl.git 10 | else 11 | (cd cider-nrepl; git reset --hard origin/master; git pull) 12 | fi 13 | 14 | cd cider-nrepl && 15 | lein do clean, source-deps :project-prefix cider.inlined-deps && 16 | lein with-profile +plugin.mranderson/config,+test-clj,+test-cljs update-in :dependencies conj "[org.jaunt-lang/jaunt \"$VERSION\"]" -- test 17 | -------------------------------------------------------------------------------- /etc/bin/whitespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | astyle --options=astylerc src/jvm/*.java 4 | -------------------------------------------------------------------------------- /etc/img/gh-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaunt-lang/jaunt/828a69527dc3b8051c32eba67b56a255d9101cc9/etc/img/gh-banner.png -------------------------------------------------------------------------------- /etc/img/icon-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaunt-lang/jaunt/828a69527dc3b8051c32eba67b56a255d9101cc9/etc/img/icon-128x128.png -------------------------------------------------------------------------------- /etc/img/icon-64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaunt-lang/jaunt/828a69527dc3b8051c32eba67b56a255d9101cc9/etc/img/icon-64x64.png -------------------------------------------------------------------------------- /etc/img/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaunt-lang/jaunt/828a69527dc3b8051c32eba67b56a255d9101cc9/etc/img/icon.png -------------------------------------------------------------------------------- /etc/img/large-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jaunt-lang/jaunt/828a69527dc3b8051c32eba67b56a255d9101cc9/etc/img/large-banner.png -------------------------------------------------------------------------------- /etc/licenses/inria.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2000-2005 INRIA, France Telecom 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holders nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29 | THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject org.jaunt-lang/jaunt (. ^String (slurp "VERSION") (trim)) 2 | :source-paths ["src/clj"] 3 | :java-source-paths ["src/jvm" "test/java"] 4 | :test-paths ["test/clojure"] 5 | :resource-paths ["src/resources" 6 | "target/resources"] 7 | :exclusions [org.clojure/clojure] 8 | :profiles {:dev {:plugins [[lein-cljfmt "0.5.0"]] 9 | :cljfmt {:indents {fn* [[:inner 0]] 10 | as-> [[:inner 0]] 11 | with-debug-bindings [[:inner 0]] 12 | merge-meta [[:inner 0]] 13 | add-doc-and-meta [[:inner 0]]}}}}) 14 | -------------------------------------------------------------------------------- /settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | clojars 5 | ${env.CLOJARS_USERNAME} 6 | ${env.CLOJARS_PASSWORD} 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /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/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/clj/clojure/core/compiler.clj: -------------------------------------------------------------------------------- 1 | ;; Copyright (c) Reid McKenzie. 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.core.compiler 10 | "EXPERIMENTAL and definitely unstable. 11 | 12 | Compiler and runtime introspection utilities." 13 | {:authors ["Reid 'arrdem' McKenzie "] 14 | :added "0.2.0"} 15 | (:import [clojure.lang PersistentQueue])) 16 | 17 | (defn uses 18 | "EXPERIMENTAL 19 | 20 | Returns the use set of a Fn, or of a Var bound to a Fn. The use set of other values is defined to 21 | the empty set." 22 | [o] 23 | (cond (fn? o) (:uses (meta o) #{}) 24 | (var? o) (recur (deref o)) 25 | :else #{})) 26 | 27 | (defn reaches 28 | "EXPERIMENTAL 29 | 30 | Returns the reach set of a Fn, or of a Var bound to a Fn. The reach set of other values is defined 31 | to be the empty set." 32 | [o] 33 | (loop [acc #{} 34 | [o & worklist' :as wl] (into PersistentQueue/EMPTY (uses o))] 35 | (if-not (empty? wl) 36 | (let [acc' (conj acc o)] 37 | (recur (into acc' (uses o)) 38 | (into worklist' (remove acc' (uses o))))) 39 | acc))) 40 | -------------------------------------------------------------------------------- /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 clojure.edn 10 | {:doc "edn reading." 11 | :author "Rich Hickey" 12 | :added "0.1.0"} 13 | (:refer-clojure :exclude [read read-string])) 14 | 15 | (defn read 16 | "Reads the next object from stream, which must be an instance of 17 | java.io.PushbackReader or some derivee. stream defaults to the 18 | current value of *in*. 19 | 20 | Reads data in the edn format (subset of Clojure data): 21 | http://edn-format.org 22 | 23 | opts is a map that can include the following keys: 24 | :eof - value to return on end-of-file. When not supplied, eof throws an exception. 25 | :readers - a map of tag symbols to data-reader functions to be considered before default-data-readers. 26 | When not supplied, only the default-data-readers will be used. 27 | :default - A function of two args, that will, if present and no reader is found for a tag, 28 | be called with the tag and the value." 29 | 30 | {:added "0.1.0"} 31 | ([] 32 | (read *in*)) 33 | ([stream] 34 | (read {} stream)) 35 | ([opts stream] 36 | (clojure.lang.EdnReader/read stream opts))) 37 | 38 | (defn read-string 39 | "Reads one object from the string s. Returns nil when s is nil or empty. 40 | 41 | Reads data in the edn format (subset of Clojure data): 42 | http://edn-format.org 43 | 44 | opts is a map as per clojure.edn/read" 45 | {:added "0.1.0"} 46 | ([s] (read-string {:eof nil} s)) 47 | ([opts s] (when s (clojure.lang.EdnReader/readString s opts)))) 48 | -------------------------------------------------------------------------------- /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 clojure.java.browse-ui 10 | "Helper namespace for clojure.java.browse. 11 | Prevents console apps from becoming GUI unnecessarily." 12 | {:authors ["Christophe Grand "] 13 | :added "0.1.0"}) 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 | (.show)))) 30 | 31 | -------------------------------------------------------------------------------- /src/clj/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 | ;; April 3, 2009 11 | 12 | (ns clojure.pprint 13 | "A Pretty Printer for Clojure 14 | 15 | clojure.pprint implements a flexible system for printing structured data 16 | in a pleasing, easy-to-understand format. Basic use of the pretty printer is 17 | simple, just call pprint instead of println. More advanced users can use 18 | the building blocks provided to create custom output formats. 19 | 20 | Out of the box, pprint supports a simple structured format for basic data 21 | and a specialized format for Clojure source code. More advanced formats, 22 | including formats that don't look like Clojure data at all like XML and 23 | JSON, can be rendered by creating custom dispatch functions. 24 | 25 | In addition to the pprint function, this module contains cl-format, a text 26 | formatting function which is fully compatible with the format function in 27 | Common Lisp. Because pretty printing directives are directly integrated with 28 | cl-format, it supports very concise custom dispatch. It also provides 29 | a more powerful alternative to Clojure's standard format function. 30 | 31 | See documentation for pprint and cl-format for more information or 32 | complete documentation on the the clojure web site on github." 33 | {:authors ["Tom Faulhaber "] 34 | :added "0.1.0"} 35 | (:refer-clojure :exclude (deftype)) 36 | (:require [clojure.walk :refer [walk]])) 37 | 38 | (set! *warn-on-reflection* true) 39 | 40 | (load "pprint/utilities") 41 | (load "pprint/column_writer") 42 | (load "pprint/pretty_writer") 43 | (load "pprint/pprint_base") 44 | (load "pprint/cl_format") 45 | (load "pprint/dispatch") 46 | (load "pprint/print_table") 47 | 48 | nil 49 | -------------------------------------------------------------------------------- /src/clj/clojure/pprint/column_writer.clj: -------------------------------------------------------------------------------- 1 | ;;; column_writer.clj -- part of the pretty printer for Clojure 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 | ;; Author: Tom Faulhaber 13 | ;; April 3, 2009 14 | ;; Revised to use proxy instead of gen-class April 2010 15 | 16 | ;; This module implements a column-aware wrapper around an instance of java.io.Writer 17 | 18 | (in-ns 'clojure.pprint) 19 | 20 | (import [clojure.lang IDeref] 21 | [java.io Writer]) 22 | 23 | (def ^:dynamic ^{:private true} *default-page-width* 72) 24 | 25 | (defn- get-field [^Writer this sym] 26 | (sym @@this)) 27 | 28 | (defn- set-field [^Writer this sym new-val] 29 | (alter @this assoc sym new-val)) 30 | 31 | (defn- get-column [this] 32 | (get-field this :cur)) 33 | 34 | (defn- get-line [this] 35 | (get-field this :line)) 36 | 37 | (defn- get-max-column [this] 38 | (get-field this :max)) 39 | 40 | (defn- set-max-column [this new-max] 41 | (dosync (set-field this :max new-max)) 42 | nil) 43 | 44 | (defn- get-writer [this] 45 | (get-field this :base)) 46 | 47 | (defn- c-write-char [^Writer this ^Integer c] 48 | (dosync (if (= c (int \newline)) 49 | (do 50 | (set-field this :cur 0) 51 | (set-field this :line (inc (get-field this :line)))) 52 | (set-field this :cur (inc (get-field this :cur))))) 53 | (.write ^Writer (get-field this :base) c)) 54 | 55 | (defn- column-writer 56 | ([writer] (column-writer writer *default-page-width*)) 57 | ([^Writer writer max-columns] 58 | (let [fields (ref {:max max-columns, :cur 0, :line 0 :base writer})] 59 | (proxy [Writer IDeref] [] 60 | (deref [] fields) 61 | (flush [] 62 | (.flush writer)) 63 | (write 64 | ([^chars cbuf ^Integer off ^Integer len] 65 | (let [^Writer writer (get-field this :base)] 66 | (.write writer cbuf off len))) 67 | ([x] 68 | (condp = (class x) 69 | String 70 | (let [^String s x 71 | nl (.lastIndexOf s (int \newline))] 72 | (dosync (if (neg? nl) 73 | (set-field this :cur (+ (get-field this :cur) (count s))) 74 | (do 75 | (set-field this :cur (- (count s) nl 1)) 76 | (set-field this :line (+ (get-field this :line) 77 | (count (filter #(= % \newline) s))))))) 78 | (.write ^Writer (get-field this :base) s)) 79 | 80 | Integer 81 | (c-write-char this x) 82 | Long 83 | (c-write-char this x)))))))) 84 | -------------------------------------------------------------------------------- /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 "0.1.0"} 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 | -------------------------------------------------------------------------------- /src/clj/clojure/stacktrace.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 | ;;; stacktrace.clj: print Clojure-centric stack traces 10 | 11 | ;; by Stuart Sierra 12 | ;; January 6, 2009 13 | 14 | (ns clojure.stacktrace 15 | "Print stack traces oriented towards Clojure, not Java." 16 | {:authors ["Stuart Sierra "] 17 | :added "0.1.0"}) 18 | 19 | (defn root-cause 20 | "Returns the last 'cause' Throwable in a chain of Throwables." 21 | {:added "0.1.0"} 22 | [tr] 23 | (if-let [cause (.getCause tr)] 24 | (recur cause) 25 | tr)) 26 | 27 | (defn print-trace-element 28 | "Prints a Clojure-oriented view of one element in a stack trace." 29 | {:added "0.1.0"} 30 | [e] 31 | (let [class (.getClassName e) 32 | method (.getMethodName e)] 33 | (let [match (re-matches #"^([A-Za-z0-9_.-]+)\$(\w+)__\d+$" (str class))] 34 | (if (and match (= "invoke" method)) 35 | (apply printf "%s/%s" (rest match)) 36 | (printf "%s.%s" class method)))) 37 | (printf " (%s:%d)" (or (.getFileName e) "") (.getLineNumber e))) 38 | 39 | (defn print-throwable 40 | "Prints the class and message of a Throwable." 41 | {:added "0.1.0"} 42 | [tr] 43 | (printf "%s: %s" (.getName (class tr)) (.getMessage tr))) 44 | 45 | (defn print-stack-trace 46 | "Prints a Clojure-oriented stack trace of tr, a Throwable. 47 | Prints a maximum of n stack frames (default: unlimited). 48 | Does not print chained exceptions (causes)." 49 | {:added "0.1.0"} 50 | ([tr] (print-stack-trace tr nil)) 51 | ([^Throwable tr n] 52 | (let [st (.getStackTrace tr)] 53 | (print-throwable tr) 54 | (newline) 55 | (print " at ") 56 | (if-let [e (first st)] 57 | (print-trace-element e) 58 | (print "[empty stack trace]")) 59 | (newline) 60 | (doseq [e (if (nil? n) 61 | (rest st) 62 | (take (dec n) (rest st)))] 63 | (print " ") 64 | (print-trace-element e) 65 | (newline))))) 66 | 67 | (defn print-cause-trace 68 | "Like print-stack-trace but prints chained exceptions (causes)." 69 | {:added "0.1.0"} 70 | ([tr] (print-cause-trace tr nil)) 71 | ([tr n] 72 | (print-stack-trace tr n) 73 | (when-let [cause (.getCause tr)] 74 | (print "Caused by: ") 75 | (recur cause n)))) 76 | 77 | (defn e 78 | "REPL utility. Prints a brief stack trace for the root cause of the 79 | most recent exception." 80 | {:added "0.1.0"} 81 | [] 82 | (print-stack-trace (root-cause *e) 8)) 83 | -------------------------------------------------------------------------------- /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 | (ns clojure.template 25 | "Macros that expand to repeated copies of a template expression." 26 | {:authors ["Stuart Sierra "] 27 | :added "0.1.0"} 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/clj/clojure/uuid.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.uuid 10 | "Reading and printing support for #uuid" 11 | {:authors ["Michael Fogus "] 12 | :added "0.1.0"}) 13 | 14 | (defn- default-uuid-reader [form] 15 | {:pre [(string? form)]} 16 | (java.util.UUID/fromString form)) 17 | 18 | (defmethod print-method java.util.UUID [uuid ^java.io.Writer w] 19 | (.write w (str "#uuid \"" (str uuid) "\""))) 20 | 21 | (defmethod print-dup java.util.UUID [o w] 22 | (print-method o w)) 23 | -------------------------------------------------------------------------------- /src/jvm/clojure/asm/commons/TableSwitchGenerator.java: -------------------------------------------------------------------------------- 1 | /*** 2 | * ASM: a very small and fast Java bytecode manipulation framework 3 | * Copyright (c) 2000-2011 INRIA, France Telecom 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. Neither the name of the copyright holders nor the names of its 15 | * contributors may be used to endorse or promote products derived from 16 | * this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | * THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package clojure.asm.commons; 31 | 32 | import clojure.asm.Label; 33 | 34 | /** 35 | * A code generator for switch statements. 36 | * 37 | * @author Juozas Baliuka 38 | * @author Chris Nokleberg 39 | * @author Eric Bruneton 40 | */ 41 | public interface TableSwitchGenerator { 42 | 43 | /** 44 | * Generates the code for a switch case. 45 | * 46 | * @param key 47 | * the switch case key. 48 | * @param end 49 | * a label that corresponds to the end of the switch statement. 50 | */ 51 | void generateCase(int key, Label end); 52 | 53 | /** 54 | * Generates the code for the default switch case. 55 | */ 56 | void generateDefault(); 57 | } 58 | -------------------------------------------------------------------------------- /src/jvm/clojure/asm/commons/package.html: -------------------------------------------------------------------------------- 1 | 2 | 31 | 32 | Provides some useful class and method adapters. The preferred way of using 33 | these adapters is by chaining them together and to custom adapters (instead of 34 | inheriting from them). Indeed this approach provides more combination 35 | possibilities than inheritance. For instance, suppose you want to implement an 36 | adapter MyAdapter than needs sorted local variables and intermediate stack map 37 | frame values taking into account the local variables sort. By using inheritance, 38 | this would require MyAdapter to extend AnalyzerAdapter, itself extending 39 | LocalVariablesSorter. But AnalyzerAdapter is not a subclass of 40 | LocalVariablesSorter, so this is not possible. On the contrary, by using 41 | delegation, you can make LocalVariablesSorter delegate to AnalyzerAdapter, 42 | itself delegating to MyAdapter. In this case AnalyzerAdapter computes 43 | intermediate frames based on the output of LocalVariablesSorter, and MyAdapter 44 | can add new locals by calling the newLocal method on LocalVariablesSorter, and 45 | can get the stack map frame state before each instruction by reading the locals 46 | and stack fields in AnalyzerAdapter (this requires references from MyAdapter 47 | back to LocalVariablesSorter and AnalyzerAdapter). 48 | -------------------------------------------------------------------------------- /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 |
  1. The ability to use Clojure's namespaces to locate an arbitrary 21 | var, returning the 22 | var's clojure.lang.IFn interface.
  2. 23 |
  3. A convenience method read for reading data using 24 | Clojure's edn reader
  4. 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 |
  1. clojure.java.api.Clojure
  2. 38 |
  3. clojure.lang.IFn
  4. 39 |
40 | 41 |

All other Java classes should be treated as implementation details, 42 | and applications should avoid relying on them.

43 | 44 |

To lookup and call a Clojure function: 45 |

46 | IFn plus = Clojure.var("clojure.core", "+");
47 | plus.invoke(1, 2);
48 | 
49 |

50 | 51 |

Functions in clojure.core are automatically loaded. Other 52 | namespaces can be loaded via require: 53 |

54 | IFn require = Clojure.var("clojure.core", "require");
55 | require.invoke(Clojure.read("clojure.set"));
56 | 
57 |

58 | 59 |

IFns can be passed to higher order functions, e.g. the 60 | example below passes plus to read: 61 |

62 | IFn map = Clojure.var("clojure.core", "map");
63 | IFn inc = Clojure.var("clojure.core", "inc");
64 | map.invoke(inc, Clojure.read("[1 2 3]"));
65 | 
66 |

67 | 68 |

Most IFns in Clojure refer to functions. A few, however, refer to 69 | non-function data values. To access these, use deref 70 | instead of fn:

71 | 72 |
73 | IFn printLength = Clojure.var("clojure.core", "*print-length*");
74 | IFn deref = Clojure.var("clojure.core", "deref");
75 | deref.invoke(printLength);
76 | 
77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /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 | public volatile MethodImplCache __methodImplCache; 21 | 22 | public IPersistentMap meta() { 23 | return null; 24 | } 25 | 26 | public int compare(Object o1, Object o2) { 27 | Object o = invoke(o1, o2); 28 | 29 | if (o instanceof Boolean) { 30 | if (RT.booleanCast(o)) { 31 | return -1; 32 | } 33 | return RT.booleanCast(invoke(o2,o1))? 1 : 0; 34 | } 35 | 36 | Number n = (Number) o; 37 | return n.intValue(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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 | if (vf != null && !RT.booleanCast(vf.invoke(val))) { 32 | throw new IllegalStateException("Invalid reference state"); 33 | } 34 | } catch (RuntimeException re) { 35 | throw re; 36 | } catch (Exception e) { 37 | throw new IllegalStateException("Invalid reference state", e); 38 | } 39 | } 40 | 41 | void validate(Object val) { 42 | validate(validator, val); 43 | } 44 | 45 | public void setValidator(IFn vf) { 46 | validate(vf, deref()); 47 | validator = vf; 48 | } 49 | 50 | public IFn getValidator() { 51 | return validator; 52 | } 53 | 54 | public IPersistentMap getWatches() { 55 | return watches; 56 | } 57 | 58 | synchronized public IRef addWatch(Object key, IFn callback) { 59 | watches = watches.assoc(key, callback); 60 | return this; 61 | } 62 | 63 | synchronized public IRef removeWatch(Object key) { 64 | watches = watches.without(key); 65 | return this; 66 | } 67 | 68 | public void notifyWatches(Object oldval, Object newval) { 69 | IPersistentMap ws = watches; 70 | if (ws.count() > 0) { 71 | for (ISeq s = ws.seq(); s != null; s = s.next()) { 72 | Map.Entry e = (Map.Entry) s.first(); 73 | IFn fn = (IFn) e.getValue(); 74 | if (fn != null) { 75 | fn.invoke(e.getKey(), this, oldval, newval); 76 | } 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/ATransientMap.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 | import clojure.lang.PersistentHashMap.INode; 16 | 17 | public abstract class ATransientMap extends AFn implements ITransientMap { 18 | abstract void ensureEditable(); 19 | abstract ITransientMap doAssoc(Object key, Object val); 20 | abstract ITransientMap doWithout(Object key); 21 | abstract Object doValAt(Object key, Object notFound); 22 | abstract int doCount(); 23 | abstract IPersistentMap doPersistent(); 24 | 25 | public ITransientMap conj(Object o) { 26 | ensureEditable(); 27 | if (o instanceof Map.Entry) { 28 | Map.Entry e = (Map.Entry) o; 29 | 30 | return assoc(e.getKey(), e.getValue()); 31 | } else if (o instanceof IPersistentVector) { 32 | IPersistentVector v = (IPersistentVector) o; 33 | if (v.count() != 2) { 34 | throw new IllegalArgumentException("Vector arg to map conj must be a pair"); 35 | } 36 | return assoc(v.nth(0), v.nth(1)); 37 | } 38 | 39 | ITransientMap ret = this; 40 | for (ISeq es = RT.seq(o); es != null; es = es.next()) { 41 | Map.Entry e = (Map.Entry) es.first(); 42 | ret = ret.assoc(e.getKey(), e.getValue()); 43 | } 44 | return ret; 45 | } 46 | 47 | public final Object invoke(Object arg1) { 48 | return valAt(arg1); 49 | } 50 | 51 | public final Object invoke(Object arg1, Object notFound) { 52 | return valAt(arg1, notFound); 53 | } 54 | 55 | public final Object valAt(Object key) { 56 | return valAt(key, null); 57 | } 58 | 59 | public final ITransientMap assoc(Object key, Object val) { 60 | ensureEditable(); 61 | return doAssoc(key, val); 62 | } 63 | 64 | public final ITransientMap without(Object key) { 65 | ensureEditable(); 66 | return doWithout(key); 67 | } 68 | 69 | public final IPersistentMap persistent() { 70 | ensureEditable(); 71 | return doPersistent(); 72 | } 73 | 74 | public final Object valAt(Object key, Object notFound) { 75 | ensureEditable(); 76 | return doValAt(key, notFound); 77 | } 78 | 79 | public final int count() { 80 | ensureEditable(); 81 | return doCount(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /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) { 29 | this.impl = m; 30 | } 31 | return this; 32 | } 33 | 34 | public boolean contains(Object key) { 35 | return this != impl.valAt(key, this); 36 | } 37 | 38 | public ITransientSet disjoin(Object key) { 39 | ITransientMap m = impl.without(key); 40 | if (m != impl) { 41 | this.impl = m; 42 | } 43 | return this; 44 | } 45 | 46 | public Object get(Object key) { 47 | return impl.valAt(key); 48 | } 49 | 50 | public Object invoke(Object key, Object notFound) { 51 | return impl.valAt(key, notFound); 52 | } 53 | 54 | public Object invoke(Object key) { 55 | return impl.valAt(key); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /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 0.1.0 15 | */ 16 | public class ArityException extends IllegalArgumentException { 17 | 18 | final public int actual; 19 | 20 | final public String name; 21 | 22 | public ArityException(int actual, String name) { 23 | this(actual, name, null); 24 | } 25 | 26 | public ArityException(int actual, String name, Throwable cause) { 27 | super("Wrong number of args (" + actual + ") passed to: " + name, cause); 28 | this.actual = actual; 29 | this.name = name; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /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 | final Object[] array; 20 | final int off; 21 | final int end; 22 | 23 | public ArrayChunk(Object[] array) { 24 | this(array, 0, array.length); 25 | } 26 | 27 | public ArrayChunk(Object[] array, int off) { 28 | this(array, off, array.length); 29 | } 30 | 31 | public ArrayChunk(Object[] array, int off, int end) { 32 | this.array = array; 33 | this.off = off; 34 | this.end = end; 35 | } 36 | 37 | public Object nth(int i) { 38 | return array[off + i]; 39 | } 40 | 41 | public Object nth(int i, Object notFound) { 42 | if (i >= 0 && i < count()) { 43 | return nth(i); 44 | } 45 | return notFound; 46 | } 47 | 48 | public int count() { 49 | return end - off; 50 | } 51 | 52 | public IChunk dropFirst() { 53 | if (off==end) { 54 | throw new IllegalStateException("dropFirst of empty chunk"); 55 | } 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 | } 64 | for (int x = off + 1; x < end; x++) { 65 | ret = f.invoke(ret, array[x]); 66 | if (RT.isReduced(ret)) { 67 | return ret; 68 | } 69 | } 70 | return ret; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Atom.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.concurrent.atomic.AtomicReference; 16 | 17 | final public class Atom extends ARef implements IAtom { 18 | final AtomicReference state; 19 | 20 | public Atom(Object state) { 21 | this.state = new AtomicReference(state); 22 | } 23 | 24 | public Atom(Object state, IPersistentMap meta) { 25 | super(meta); 26 | this.state = new AtomicReference(state); 27 | } 28 | 29 | public Object deref() { 30 | return state.get(); 31 | } 32 | 33 | public Object swap(IFn f) { 34 | for (; ;) { 35 | Object v = deref(); 36 | Object newv = f.invoke(v); 37 | validate(newv); 38 | if (state.compareAndSet(v, newv)) { 39 | notifyWatches(v, newv); 40 | return newv; 41 | } 42 | } 43 | } 44 | 45 | public Object swap(IFn f, Object arg) { 46 | for (; ;) { 47 | Object v = deref(); 48 | Object newv = f.invoke(v, arg); 49 | validate(newv); 50 | if (state.compareAndSet(v, newv)) { 51 | notifyWatches(v, newv); 52 | return newv; 53 | } 54 | } 55 | } 56 | 57 | public Object swap(IFn f, Object arg1, Object arg2) { 58 | for (; ;) { 59 | Object v = deref(); 60 | Object newv = f.invoke(v, arg1, arg2); 61 | validate(newv); 62 | if (state.compareAndSet(v, newv)) { 63 | notifyWatches(v, newv); 64 | return newv; 65 | } 66 | } 67 | } 68 | 69 | public Object swap(IFn f, Object x, Object y, ISeq args) { 70 | for (; ;) { 71 | Object v = deref(); 72 | Object newv = f.applyTo(RT.listStar(v, x, y, args)); 73 | validate(newv); 74 | if (state.compareAndSet(v, newv)) { 75 | notifyWatches(v, newv); 76 | return newv; 77 | } 78 | } 79 | } 80 | 81 | public boolean compareAndSet(Object oldv, Object newv) { 82 | validate(newv); 83 | boolean ret = state.compareAndSet(oldv, newv); 84 | if (ret) { 85 | notifyWatches(oldv, newv); 86 | } 87 | return ret; 88 | } 89 | 90 | public Object reset(Object newval) { 91 | Object oldval = state.get(); 92 | validate(newval); 93 | state.set(newval); 94 | notifyWatches(oldval, newval); 95 | return newval; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Binding.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 Binding { 14 | public T val; 15 | public final Binding rest; 16 | 17 | public Binding(T val) { 18 | this.val = val; 19 | this.rest = null; 20 | } 21 | 22 | public Binding(T val, Binding rest) { 23 | this.val = val; 24 | this.rest = rest; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /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/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/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 | final IChunk chunk; 18 | final ISeq _more; 19 | 20 | ChunkedCons(IPersistentMap meta, IChunk chunk, ISeq more) { 21 | super(meta); 22 | this.chunk = chunk; 23 | this._more = more; 24 | } 25 | 26 | public ChunkedCons(IChunk chunk, ISeq more) { 27 | this(null,chunk, more); 28 | } 29 | 30 | public Obj withMeta(IPersistentMap meta) { 31 | if (meta != _meta) { 32 | return new ChunkedCons(meta, chunk, _more); 33 | } 34 | return this; 35 | } 36 | 37 | public Object first() { 38 | return chunk.nth(0); 39 | } 40 | 41 | public ISeq next() { 42 | if (chunk.count() > 1) { 43 | return new ChunkedCons(chunk.dropFirst(), _more); 44 | } 45 | return chunkedNext(); 46 | } 47 | 48 | public ISeq more() { 49 | if (chunk.count() > 1) { 50 | return new ChunkedCons(chunk.dropFirst(), _more); 51 | } 52 | if (_more == null) { 53 | return PersistentList.EMPTY; 54 | } 55 | return _more; 56 | } 57 | 58 | public IChunk chunkedFirst() { 59 | return chunk; 60 | } 61 | 62 | public ISeq chunkedNext() { 63 | return chunkedMore().seq(); 64 | } 65 | 66 | public ISeq chunkedMore() { 67 | if (_more == null) { 68 | return PersistentList.EMPTY; 69 | } 70 | return _more; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Compile.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 | 12 | package clojure.lang; 13 | 14 | import java.io.OutputStreamWriter; 15 | import java.io.PrintWriter; 16 | import java.io.IOException; 17 | 18 | // Compiles libs and generates class files stored within the directory 19 | // named by the Java System property "clojure.compile.path". Arguments are 20 | // strings naming the libs to be compiled. The libs and compile-path must 21 | // all be within CLASSPATH. 22 | 23 | public class Compile { 24 | 25 | private static final String PATH_PROP = "clojure.compile.path"; 26 | private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection"; 27 | private static final String UNCHECKED_MATH_PROP = "clojure.compile.unchecked-math"; 28 | 29 | private static final Var compile_path = RT.var("clojure.core", "*compile-path*"); 30 | private static final Var compile = RT.var("clojure.core", "compile"); 31 | private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*"); 32 | private static final Var unchecked_math = RT.var("clojure.core", "*unchecked-math*"); 33 | 34 | public static void main(String[] args) throws IOException { 35 | 36 | OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref(); 37 | PrintWriter err = RT.errPrintWriter(); 38 | String path = System.getProperty(PATH_PROP); 39 | int count = args.length; 40 | 41 | if (path == null) { 42 | err.println("ERROR: Must set system property " + PATH_PROP + 43 | "\nto the location for compiled .class files." + 44 | "\nThis directory must also be on your CLASSPATH."); 45 | System.exit(1); 46 | } 47 | 48 | boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true"); 49 | String uncheckedMathProp = System.getProperty(UNCHECKED_MATH_PROP); 50 | Object uncheckedMath = Boolean.FALSE; 51 | if ("true".equals(uncheckedMathProp)) { 52 | uncheckedMath = Boolean.TRUE; 53 | } else if ("warn-on-boxed".equals(uncheckedMathProp)) { 54 | uncheckedMath = Keyword.intern("warn-on-boxed"); 55 | } 56 | 57 | try { 58 | Var.pushThreadBindings(RT.map(compile_path, path, 59 | warn_on_reflection, warnOnReflection, 60 | unchecked_math, uncheckedMath)); 61 | 62 | for (String lib : args) { 63 | out.write("Compiling " + lib + " to " + path + "\n"); 64 | out.flush(); 65 | compile.invoke(Symbol.intern(lib)); 66 | } 67 | } finally { 68 | Var.popThreadBindings(); 69 | try { 70 | out.flush(); 71 | } catch (IOException e) { 72 | e.printStackTrace(err); 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /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 final Object _first; 20 | private final ISeq _more; 21 | 22 | public Cons(Object first, ISeq _more) { 23 | this._first = first; 24 | this._more = _more; 25 | } 26 | 27 | 28 | public Cons(IPersistentMap meta, Object _first, ISeq _more) { 29 | super(meta); 30 | this._first = _first; 31 | this._more = _more; 32 | } 33 | 34 | public Object first() { 35 | return _first; 36 | } 37 | 38 | public ISeq next() { 39 | return more().seq(); 40 | } 41 | 42 | public ISeq more() { 43 | if (_more == null) { 44 | return PersistentList.EMPTY; 45 | } 46 | return _more; 47 | } 48 | 49 | public int count() { 50 | return 1 + RT.count(_more); 51 | } 52 | 53 | public Cons withMeta(IPersistentMap meta) { 54 | return new Cons(meta, _first, _more); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /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/Cycle.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 | /* Alex Miller, Dec 5, 2014 */ 14 | 15 | public class Cycle extends ASeq implements IReduce, IPending { 16 | 17 | private final ISeq all; // never null 18 | private final ISeq prev; 19 | private volatile ISeq _current; // lazily realized 20 | private volatile ISeq _next; // cached 21 | 22 | private Cycle(ISeq all, ISeq prev, ISeq current) { 23 | this.all = all; 24 | this.prev = prev; 25 | this._current = current; 26 | } 27 | 28 | private Cycle(IPersistentMap meta, ISeq all, ISeq prev, ISeq current, ISeq next) { 29 | super(meta); 30 | this.all = all; 31 | this.prev = prev; 32 | this._current = current; 33 | this._next = next; 34 | } 35 | 36 | public static ISeq create(ISeq vals) { 37 | if (vals == null) { 38 | return PersistentList.EMPTY; 39 | } 40 | return new Cycle(vals, null, vals); 41 | } 42 | 43 | // realization for use of current 44 | private ISeq current() { 45 | if (_current == null) { 46 | ISeq current = prev.next(); 47 | _current = (current == null) ? all : current; 48 | } 49 | return _current; 50 | } 51 | 52 | public boolean isRealized() { 53 | return _current != null; 54 | } 55 | 56 | public Object first() { 57 | return current().first(); 58 | } 59 | 60 | public ISeq next() { 61 | if (_next == null) { 62 | _next = new Cycle(all, current(), null); 63 | } 64 | return _next; 65 | } 66 | 67 | public Cycle withMeta(IPersistentMap meta) { 68 | return new Cycle(meta, all, prev, _current, _next); 69 | } 70 | 71 | public Object reduce(IFn f) { 72 | ISeq s = current(); 73 | Object ret = s.first(); 74 | while (true) { 75 | s = s.next(); 76 | if (s == null) { 77 | s = all; 78 | } 79 | ret = f.invoke(ret, s.first()); 80 | if (RT.isReduced(ret)) { 81 | return ((IDeref)ret).deref(); 82 | } 83 | } 84 | } 85 | 86 | public Object reduce(IFn f, Object start) { 87 | Object ret = start; 88 | ISeq s = current(); 89 | while (true) { 90 | ret = f.invoke(ret, s.first()); 91 | if (RT.isReduced(ret)) { 92 | return ((IDeref)ret).deref(); 93 | } 94 | s = s.next(); 95 | if (s == null) { 96 | s = all; 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /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 | public class Delay implements IDeref, IPending { 16 | Object val; 17 | Throwable exception; 18 | IFn fn; 19 | 20 | public Delay(IFn fn) { 21 | this.fn = fn; 22 | this.val = null; 23 | this.exception = null; 24 | } 25 | 26 | static public Object force(Object x) { 27 | return (x instanceof Delay) ? 28 | ((Delay) x).deref() 29 | : x; 30 | } 31 | 32 | synchronized public Object deref() { 33 | if (fn != null) { 34 | try { 35 | val = fn.invoke(); 36 | } catch (Throwable t) { 37 | exception = t; 38 | } 39 | fn = null; 40 | } 41 | if (exception != null) { 42 | throw Util.sneakyThrow(exception); 43 | } 44 | return val; 45 | } 46 | 47 | synchronized public boolean isRealized() { 48 | return fn == null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /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 | final Enumeration iter; 21 | final State state; 22 | 23 | static class State { 24 | volatile Object val; 25 | volatile Object _rest; 26 | } 27 | 28 | public static EnumerationSeq create(Enumeration iter) { 29 | if (iter.hasMoreElements()) { 30 | return new EnumerationSeq(iter); 31 | } 32 | return null; 33 | } 34 | 35 | EnumerationSeq(Enumeration iter) { 36 | this.iter = iter; 37 | state = new State(); 38 | this.state.val = state; 39 | this.state._rest = state; 40 | } 41 | 42 | EnumerationSeq(IPersistentMap meta, Enumeration 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 | if (state.val == state) { 52 | state.val = iter.nextElement(); 53 | } 54 | } 55 | return state.val; 56 | } 57 | 58 | public ISeq next() { 59 | if (state._rest == state) 60 | synchronized (state) { 61 | if (state._rest == state) { 62 | first(); 63 | state._rest = create(iter); 64 | } 65 | } 66 | return (ISeq) state._rest; 67 | } 68 | 69 | public EnumerationSeq withMeta(IPersistentMap meta) { 70 | return new EnumerationSeq(meta, iter, state); 71 | } 72 | 73 | private void writeObject (java.io.ObjectOutputStream out) throws IOException { 74 | throw new NotSerializableException(getClass().getName()); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /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 | public final IPersistentMap data; 20 | 21 | public ExceptionInfo(String s, IPersistentMap data) { 22 | this(s, data, null); 23 | } 24 | 25 | public ExceptionInfo(String s, IPersistentMap data, Throwable throwable) { 26 | // null cause is equivalent to not passing a cause 27 | super(s, throwable); 28 | if (data != null) { 29 | this.data = data; 30 | } else { 31 | throw new IllegalArgumentException("Additional data must be non-nil."); 32 | } 33 | } 34 | 35 | public IPersistentMap getData() { 36 | return data; 37 | } 38 | 39 | public String toString() { 40 | return "clojure.lang.ExceptionInfo: " + getMessage() + " " + data.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /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/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 | final Var v; 18 | final ClassLoader loader; 19 | final String fnClassName; 20 | IFn fn; 21 | 22 | public FnLoaderThunk(Var v, String fnClassName) { 23 | this.v = v; 24 | this.loader = (ClassLoader) RT.FN_LOADER_VAR.get(); 25 | this.fnClassName = fnClassName; 26 | fn = null; 27 | } 28 | 29 | public Object invoke(Object arg1) { 30 | load(); 31 | return fn.invoke(arg1); 32 | } 33 | 34 | public Object invoke(Object arg1, Object arg2) { 35 | load(); 36 | return fn.invoke(arg1,arg2); 37 | } 38 | 39 | public Object invoke(Object arg1, Object arg2, Object arg3) { 40 | load(); 41 | return fn.invoke(arg1,arg2,arg3); 42 | } 43 | 44 | protected Object doInvoke(Object args) { 45 | load(); 46 | return fn.applyTo((ISeq) args); 47 | } 48 | 49 | private void load() { 50 | if (fn == null) { 51 | try { 52 | fn = (IFn) Class.forName(fnClassName,true,loader).newInstance(); 53 | } catch (Exception e) { 54 | throw Util.sneakyThrow(e); 55 | } 56 | v.root = fn; 57 | } 58 | } 59 | 60 | public int getRequiredArity() { 61 | return 0; 62 | } 63 | 64 | public IObj withMeta(IPersistentMap meta) { 65 | return this; 66 | } 67 | 68 | public IPersistentMap meta() { 69 | return null; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IAtom.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 IAtom { 16 | Object swap(IFn f); 17 | 18 | Object swap(IFn f, Object arg); 19 | 20 | Object swap(IFn f, Object arg1, Object arg2); 21 | 22 | Object swap(IFn f, Object x, Object y, ISeq args); 23 | 24 | boolean compareAndSet(Object oldv, Object newv); 25 | 26 | Object reset(Object newval); 27 | } 28 | -------------------------------------------------------------------------------- /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/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/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/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 | public interface IDeref { 16 | Object deref() ; 17 | } 18 | -------------------------------------------------------------------------------- /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/IExceptionInfo.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 | * Interface for exceptions that carry data (a map) as additional payload. Clojure 15 | * programs that need richer semantics for exceptions should use this in lieu of 16 | * defining project-specific exception classes. 17 | */ 18 | public interface IExceptionInfo { 19 | public IPersistentMap getData(); 20 | } 21 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IMapIterable.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 | /* Alex Miller Dec 3, 2014 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.util.Iterator; 16 | 17 | /** 18 | * Indicate a map can provide more efficient key and val iterators. 19 | */ 20 | public interface IMapIterable { 21 | 22 | Iterator keyIterator(); 23 | 24 | Iterator valIterator(); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/IPersistentMap.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 IPersistentMap extends Iterable, Associative, Counted { 15 | 16 | 17 | IPersistentMap assoc(Object key, Object val); 18 | 19 | IPersistentMap assocEx(Object key, Object val) ; 20 | 21 | IPersistentMap without(Object key) ; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentSet.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 IPersistentSet extends IPersistentCollection, Counted { 16 | public IPersistentSet disjoin(Object key) ; 17 | public boolean contains(Object key); 18 | public Object get(Object key); 19 | } 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IPersistentVector.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 | public interface IPersistentVector extends Associative, Sequential, IPersistentStack, Reversible, Indexed { 14 | int length(); 15 | 16 | IPersistentVector assocN(int i, Object val); 17 | 18 | IPersistentVector cons(Object o); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/IProxy.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 27, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IProxy { 16 | 17 | public void __initClojureFnMappings(IPersistentMap m); 18 | public void __updateClojureFnMappings(IPersistentMap m); 19 | public IPersistentMap __getClojureFnMappings(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/IRef.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 18, 2007 */ 12 | 13 | package clojure.lang; 14 | 15 | public interface IRef extends IDeref { 16 | 17 | void setValidator(IFn vf); 18 | 19 | IFn getValidator(); 20 | 21 | IPersistentMap getWatches(); 22 | 23 | IRef addWatch(Object key, IFn callback); 24 | 25 | IRef removeWatch(Object key); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /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/ISeq.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 | * A persistent, functional, sequence interface 15 | *

16 | * ISeqs are immutable values, i.e. neither first(), nor rest() changes 17 | * or invalidates the ISeq 18 | */ 19 | public interface ISeq extends IPersistentCollection { 20 | 21 | Object first(); 22 | 23 | ISeq next(); 24 | 25 | ISeq more(); 26 | 27 | ISeq cons(Object o); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /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/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/ITransientMap.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 ITransientMap extends ITransientAssociative, Counted { 16 | 17 | ITransientMap assoc(Object key, Object val); 18 | 19 | ITransientMap without(Object key); 20 | 21 | IPersistentMap persistent(); 22 | } 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/Iterate.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 | /* Alex Miller, Dec 5, 2014 */ 14 | 15 | public class Iterate extends ASeq implements IReduce, IPending { 16 | 17 | private static final Object UNREALIZED_SEED = new Object(); 18 | private final IFn f; // never null 19 | private final Object prevSeed; 20 | private volatile Object _seed; // lazily realized 21 | private volatile ISeq _next; // cached 22 | 23 | private Iterate(IFn f, Object prevSeed, Object seed) { 24 | this.f = f; 25 | this.prevSeed = prevSeed; 26 | this._seed = seed; 27 | } 28 | 29 | private Iterate(IPersistentMap meta, IFn f, Object prevSeed, Object seed, ISeq next) { 30 | super(meta); 31 | this.f = f; 32 | this.prevSeed = prevSeed; 33 | this._seed = seed; 34 | this._next = next; 35 | } 36 | 37 | public static ISeq create(IFn f, Object seed) { 38 | return new Iterate(f, null, seed); 39 | } 40 | 41 | public boolean isRealized() { 42 | return _seed != UNREALIZED_SEED; 43 | } 44 | 45 | public Object first() { 46 | if (_seed == UNREALIZED_SEED) { 47 | _seed = f.invoke(prevSeed); 48 | } 49 | return _seed; 50 | } 51 | 52 | public ISeq next() { 53 | if (_next == null) { 54 | _next = new Iterate(f, first(), UNREALIZED_SEED); 55 | } 56 | return _next; 57 | } 58 | 59 | public Iterate withMeta(IPersistentMap meta) { 60 | return new Iterate(meta, f, prevSeed, _seed, _next); 61 | } 62 | 63 | public Object reduce(IFn rf) { 64 | Object first = first(); 65 | Object ret = first; 66 | Object v = f.invoke(first); 67 | while (true) { 68 | ret = rf.invoke(ret, v); 69 | if (RT.isReduced(ret)) { 70 | return ((IDeref)ret).deref(); 71 | } 72 | v = f.invoke(v); 73 | } 74 | } 75 | 76 | public Object reduce(IFn rf, Object start) { 77 | Object ret = start; 78 | Object v = first(); 79 | while (true) { 80 | ret = rf.invoke(ret, v); 81 | if (RT.isReduced(ret)) { 82 | return ((IDeref)ret).deref(); 83 | } 84 | v = f.invoke(v); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /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 | final Iterator iter; 19 | final State state; 20 | 21 | static class State { 22 | volatile Object val; 23 | volatile Object _rest; 24 | } 25 | 26 | public static IteratorSeq create(Iterator iter) { 27 | if (iter.hasNext()) { 28 | return new IteratorSeq(iter); 29 | } 30 | return null; 31 | } 32 | 33 | IteratorSeq(Iterator iter) { 34 | this.iter = iter; 35 | state = new State(); 36 | this.state.val = state; 37 | this.state._rest = state; 38 | } 39 | 40 | IteratorSeq(IPersistentMap meta, Iterator iter, State state) { 41 | super(meta); 42 | this.iter = iter; 43 | this.state = state; 44 | } 45 | 46 | public Object first() { 47 | if (state.val == state) 48 | synchronized (state) { 49 | if (state.val == state) { 50 | state.val = iter.next(); 51 | } 52 | } 53 | return state.val; 54 | } 55 | 56 | public ISeq next() { 57 | if (state._rest == state) 58 | synchronized (state) { 59 | if (state._rest == state) { 60 | first(); 61 | state._rest = create(iter); 62 | } 63 | } 64 | return (ISeq) state._rest; 65 | } 66 | 67 | public IteratorSeq withMeta(IPersistentMap meta) { 68 | return new IteratorSeq(meta, iter, state); 69 | } 70 | 71 | private void writeObject (java.io.ObjectOutputStream out) throws IOException { 72 | throw new NotSerializableException(getClass().getName()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /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 | return install(target); 26 | } else if (target instanceof ILookup) { 27 | return ilookupThunk(target.getClass()); 28 | } 29 | return this; 30 | } 31 | 32 | public Object get(Object target) { 33 | if (target instanceof IKeywordLookup || target instanceof ILookup) { 34 | return this; 35 | } 36 | return RT.get(target,k); 37 | } 38 | 39 | private ILookupThunk ilookupThunk(final Class c) { 40 | return new ILookupThunk() { 41 | public Object get(Object target) { 42 | if (target != null && target.getClass() == c) { 43 | return ((ILookup) target).valAt(k); 44 | } 45 | return this; 46 | } 47 | }; 48 | } 49 | 50 | private ILookupThunk install(Object target) { 51 | ILookupThunk t = ((IKeywordLookup)target).getLookupThunk(k); 52 | if (t != null) { 53 | return t; 54 | } 55 | return ilookupThunk(target.getClass()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /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 | } 28 | return PersistentVector.create(items); 29 | } 30 | 31 | static int fcount(Object c) { 32 | if (c instanceof Counted) { 33 | return ((Counted) c).count(); 34 | } 35 | return ((Collection)c).size(); 36 | } 37 | 38 | static public IPersistentVector create(Object obj) { 39 | // if((obj instanceof Counted || obj instanceof RandomAccess) 40 | // && fcount(obj) <= Tuple.MAX_SIZE) 41 | // return Tuple.createFromColl(obj); 42 | // else 43 | if (obj instanceof IReduceInit) { 44 | return PersistentVector.create((IReduceInit) obj); 45 | } else if (obj instanceof ISeq) { 46 | return PersistentVector.create(RT.seq(obj)); 47 | } else if (obj instanceof Iterable) { 48 | return PersistentVector.create((Iterable)obj); 49 | } else { 50 | return createOwning(RT.toArray(obj)); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/LineNumberingPushbackReader.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.PushbackReader; 14 | import java.io.Reader; 15 | import java.io.LineNumberReader; 16 | import java.io.IOException; 17 | 18 | 19 | public class LineNumberingPushbackReader extends PushbackReader { 20 | 21 | // This class is a PushbackReader that wraps a LineNumberReader. The code 22 | // here to handle line terminators only mentions '\n' because 23 | // LineNumberReader collapses all occurrences of CR, LF, and CRLF into a 24 | // single '\n'. 25 | 26 | private static final int newline = (int) '\n'; 27 | 28 | private boolean _atLineStart = true; 29 | private boolean _prev; 30 | private int _columnNumber = 1; 31 | 32 | public LineNumberingPushbackReader(Reader r) { 33 | super(new LineNumberReader(r)); 34 | } 35 | 36 | public LineNumberingPushbackReader(Reader r, int size) { 37 | super(new LineNumberReader(r, size)); 38 | } 39 | 40 | public int getLineNumber() { 41 | return ((LineNumberReader) in).getLineNumber() + 1; 42 | } 43 | 44 | public void setLineNumber(int line) { 45 | ((LineNumberReader) in).setLineNumber(line - 1); 46 | } 47 | 48 | public int getColumnNumber() { 49 | return _columnNumber; 50 | } 51 | 52 | public int read() throws IOException { 53 | int c = super.read(); 54 | _prev = _atLineStart; 55 | if ((c == newline) || (c == -1)) { 56 | _atLineStart = true; 57 | _columnNumber = 1; 58 | } else { 59 | _atLineStart = false; 60 | _columnNumber++; 61 | } 62 | return c; 63 | } 64 | 65 | public void unread(int c) throws IOException { 66 | super.unread(c); 67 | _atLineStart = _prev; 68 | _columnNumber--; 69 | } 70 | 71 | public String readLine() throws IOException { 72 | int c = read(); 73 | String line; 74 | switch (c) { 75 | case -1: 76 | line = null; 77 | break; 78 | case newline: 79 | line = ""; 80 | break; 81 | default: 82 | String first = String.valueOf((char) c); 83 | String rest = ((LineNumberReader)in).readLine(); 84 | line = (rest == null) ? first : first + rest; 85 | _prev = false; 86 | _atLineStart = true; 87 | _columnNumber = 1; 88 | break; 89 | } 90 | return line; 91 | } 92 | 93 | public boolean atLineStart() { 94 | return _atLineStart; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /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 | final Object _key; 17 | final Object _val; 18 | 19 | static public MapEntry create(Object key, Object val) { 20 | return new MapEntry(key, val); 21 | } 22 | 23 | public MapEntry(Object key, Object val) { 24 | this._key = key; 25 | this._val = val; 26 | } 27 | 28 | public Object key() { 29 | return _key; 30 | } 31 | 32 | public Object val() { 33 | return _val; 34 | } 35 | 36 | public Object getKey() { 37 | return key(); 38 | } 39 | 40 | public Object getValue() { 41 | return val(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /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/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 Keyword methodk; 31 | public final int shift; 32 | public final int mask; 33 | public final Object[] table; //[class, entry. class, entry ...] 34 | public final Map map; 35 | 36 | Entry mre = null; 37 | 38 | public MethodImplCache(IPersistentMap protocol, Keyword methodk) { 39 | this(protocol, methodk, 0, 0, RT.EMPTY_ARRAY); 40 | } 41 | 42 | public MethodImplCache(IPersistentMap protocol, Keyword methodk, int shift, int mask, Object[] table) { 43 | this.protocol = protocol; 44 | this.methodk = methodk; 45 | this.shift = shift; 46 | this.mask = mask; 47 | this.table = table; 48 | this.map = null; 49 | } 50 | 51 | public MethodImplCache(IPersistentMap protocol, Keyword methodk, Map map) { 52 | this.protocol = protocol; 53 | this.methodk = methodk; 54 | this.shift = 0; 55 | this.mask = 0; 56 | this.table = null; 57 | this.map = map; 58 | } 59 | 60 | public IFn fnFor(Class c) { 61 | Entry last = mre; 62 | if (last != null && last.c == c) { 63 | return last.fn; 64 | } 65 | return findFnFor(c); 66 | } 67 | 68 | IFn findFnFor(Class c) { 69 | if (map != null) { 70 | Entry e = (Entry) map.get(c); 71 | mre = e; 72 | return e != null ? e.fn : null; 73 | } else { 74 | int idx = ((Util.hash(c) >> shift) & mask) << 1; 75 | if (idx < table.length && table[idx] == c) { 76 | Entry e = ((Entry) table[idx + 1]); 77 | mre = e; 78 | return e != null ? e.fn : null; 79 | } 80 | return null; 81 | } 82 | } 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /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/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 | final IPersistentMap _meta; 20 | 21 | public Obj(IPersistentMap meta) { 22 | this._meta = meta; 23 | } 24 | 25 | public Obj() { 26 | _meta = null; 27 | } 28 | 29 | final public IPersistentMap meta() { 30 | return _meta; 31 | } 32 | 33 | abstract public Obj withMeta(IPersistentMap meta); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/PersistentTreeSet.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.Comparator; 16 | 17 | public class PersistentTreeSet extends APersistentSet implements IObj, Reversible, Sorted { 18 | static public final PersistentTreeSet EMPTY = new PersistentTreeSet(null, PersistentTreeMap.EMPTY); 19 | final IPersistentMap _meta; 20 | 21 | 22 | static public PersistentTreeSet create(ISeq items) { 23 | PersistentTreeSet ret = EMPTY; 24 | for (; items != null; items = items.next()) { 25 | ret = (PersistentTreeSet) ret.cons(items.first()); 26 | } 27 | return ret; 28 | } 29 | 30 | static public PersistentTreeSet create(Comparator comp, ISeq items) { 31 | PersistentTreeSet ret = new PersistentTreeSet(null, new PersistentTreeMap(null, comp)); 32 | for (; items != null; items = items.next()) { 33 | ret = (PersistentTreeSet) ret.cons(items.first()); 34 | } 35 | return ret; 36 | } 37 | 38 | PersistentTreeSet(IPersistentMap meta, IPersistentMap impl) { 39 | super(impl); 40 | this._meta = meta; 41 | } 42 | 43 | public IPersistentSet disjoin(Object key) { 44 | if (contains(key)) { 45 | return new PersistentTreeSet(meta(),impl.without(key)); 46 | } 47 | return this; 48 | } 49 | 50 | public IPersistentSet cons(Object o) { 51 | if (contains(o)) { 52 | return this; 53 | } 54 | return new PersistentTreeSet(meta(),impl.assoc(o,o)); 55 | } 56 | 57 | public IPersistentCollection empty() { 58 | return new PersistentTreeSet(meta(),(PersistentTreeMap)impl.empty()); 59 | } 60 | 61 | public ISeq rseq() { 62 | return APersistentMap.KeySeq.create(((Reversible) impl).rseq()); 63 | } 64 | 65 | public PersistentTreeSet withMeta(IPersistentMap meta) { 66 | return new PersistentTreeSet(meta, impl); 67 | } 68 | 69 | public Comparator comparator() { 70 | return ((Sorted)impl).comparator(); 71 | } 72 | 73 | public Object entryKey(Object entry) { 74 | return entry; 75 | } 76 | 77 | public ISeq seq(boolean ascending) { 78 | PersistentTreeMap m = (PersistentTreeMap) impl; 79 | return RT.keys(m.seq(ascending)); 80 | } 81 | 82 | public ISeq seqFrom(Object key, boolean ascending) { 83 | PersistentTreeMap m = (PersistentTreeMap) impl; 84 | return RT.keys(m.seqFrom(key,ascending)); 85 | } 86 | 87 | public IPersistentMap meta() { 88 | return _meta; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /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 | if (rt == Void.TYPE) { 32 | return null; 33 | } else if (method.getName().equals("equals")) { 34 | return proxy == args[0]; 35 | } else if (method.getName().equals("hashCode")) { 36 | return System.identityHashCode(proxy); 37 | } else if (method.getName().equals("toString")) { 38 | return "Proxy: " + System.identityHashCode(proxy); 39 | } 40 | throw new UnsupportedOperationException(); 41 | } 42 | Object ret = fn.applyTo(ArraySeq.create(args)); 43 | if (rt == Void.TYPE) { 44 | return null; 45 | } else if (rt.isPrimitive()) { 46 | if (rt == Character.TYPE) { 47 | return ret; 48 | } else if (rt == Integer.TYPE) { 49 | return ((Number) ret).intValue(); 50 | } else if (rt == Long.TYPE) { 51 | return ((Number) ret).longValue(); 52 | } else if (rt == Float.TYPE) { 53 | return ((Number) ret).floatValue(); 54 | } else if (rt == Double.TYPE) { 55 | return ((Number) ret).doubleValue(); 56 | } else if (rt == Boolean.TYPE && !(ret instanceof Boolean)) { 57 | return ret == null ? Boolean.FALSE : Boolean.TRUE; 58 | } else if (rt == Byte.TYPE) { 59 | return (byte) ((Number) ret).intValue(); 60 | } else if (rt == Short.TYPE) { 61 | return (short) ((Number) ret).intValue(); 62 | } 63 | } 64 | return ret; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/jvm/clojure/lang/Ratio.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 31, 2008 */ 12 | 13 | package clojure.lang; 14 | 15 | import java.math.BigInteger; 16 | import java.math.BigDecimal; 17 | import java.math.MathContext; 18 | 19 | public class Ratio extends Number implements Comparable { 20 | final public BigInteger numerator; 21 | final public BigInteger denominator; 22 | 23 | public Ratio(BigInteger numerator, BigInteger denominator) { 24 | this.numerator = numerator; 25 | this.denominator = denominator; 26 | } 27 | 28 | public boolean equals(Object arg0) { 29 | return arg0 != null 30 | && arg0 instanceof Ratio 31 | && ((Ratio) arg0).numerator.equals(numerator) 32 | && ((Ratio) arg0).denominator.equals(denominator); 33 | } 34 | 35 | public int hashCode() { 36 | return numerator.hashCode() ^ denominator.hashCode(); 37 | } 38 | 39 | public String toString() { 40 | return numerator.toString() + "/" + denominator.toString(); 41 | } 42 | 43 | public int intValue() { 44 | return (int) doubleValue(); 45 | } 46 | 47 | public long longValue() { 48 | return bigIntegerValue().longValue(); 49 | } 50 | 51 | public float floatValue() { 52 | return (float)doubleValue(); 53 | } 54 | 55 | public double doubleValue() { 56 | return decimalValue(MathContext.DECIMAL64).doubleValue(); 57 | } 58 | 59 | public BigDecimal decimalValue() { 60 | return decimalValue(MathContext.UNLIMITED); 61 | } 62 | 63 | public BigDecimal decimalValue(MathContext mc) { 64 | BigDecimal numerator = new BigDecimal(this.numerator); 65 | BigDecimal denominator = new BigDecimal(this.denominator); 66 | 67 | return numerator.divide(denominator, mc); 68 | } 69 | 70 | public BigInteger bigIntegerValue() { 71 | return numerator.divide(denominator); 72 | } 73 | 74 | public int compareTo(Object o) { 75 | Number other = (Number)o; 76 | return Numbers.compare(this, other); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /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) { 49 | return true; 50 | } 51 | if (o == null || getClass() != o.getClass()) { 52 | return false; 53 | } 54 | 55 | ReaderConditional that = (ReaderConditional) o; 56 | 57 | if (form != null ? !form.equals(that.form) : that.form != null) { 58 | return false; 59 | } 60 | if (splicing != null ? !splicing.equals(that.splicing) : that.splicing != null) { 61 | return false; 62 | } 63 | return true; 64 | } 65 | 66 | @Override 67 | public int hashCode() { 68 | int result = Util.hash(form); 69 | result = 31 * result + Util.hash(splicing); 70 | return result; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /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/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/Repeat.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 | /* Alex Miller, Dec 5, 2014 */ 14 | 15 | public class Repeat extends ASeq implements IReduce { 16 | 17 | private static final long INFINITE = -1; 18 | 19 | private final long count; // always INFINITE or >0 20 | private final Object val; 21 | private volatile ISeq _next; // cached 22 | 23 | private Repeat(long count, Object val) { 24 | this.count = count; 25 | this.val = val; 26 | } 27 | 28 | private Repeat(IPersistentMap meta, long count, Object val) { 29 | super(meta); 30 | this.count = count; 31 | this.val = val; 32 | } 33 | 34 | public static Repeat create(Object val) { 35 | return new Repeat(INFINITE, val); 36 | } 37 | 38 | public static ISeq create(long count, Object val) { 39 | if (count <= 0) { 40 | return PersistentList.EMPTY; 41 | } 42 | return new Repeat(count, val); 43 | } 44 | 45 | public Object first() { 46 | return val; 47 | } 48 | 49 | public ISeq next() { 50 | if (_next == null) { 51 | if (count > 1) { 52 | _next = new Repeat(count - 1, val); 53 | } else if (count == INFINITE) { 54 | _next = this; 55 | } 56 | } 57 | return _next; 58 | } 59 | 60 | public Repeat withMeta(IPersistentMap meta) { 61 | return new Repeat(meta, count, val); 62 | } 63 | 64 | public Object reduce(IFn f) { 65 | Object ret = val; 66 | if (count == INFINITE) { 67 | while (true) { 68 | ret = f.invoke(ret, val); 69 | if (RT.isReduced(ret)) { 70 | return ((IDeref)ret).deref(); 71 | } 72 | } 73 | } else { 74 | for (long i=1; i 2 | 3 | 12 | 13 | Clojure language implementation. 14 | 15 |

The clojure.lang package holds the implementation for Clojure. 16 | The only class considered part of the public API is 17 | {@link clojure.lang.IFn}. All other classes should be considered 18 | implementation details.

19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /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 | REQUIRE.invoke(CLOJURE_MAIN); 27 | LEGACY_REPL.invoke(RT.seq(args)); 28 | } 29 | 30 | public static void legacy_script(String[] args) { 31 | REQUIRE.invoke(CLOJURE_MAIN); 32 | LEGACY_SCRIPT.invoke(RT.seq(args)); 33 | } 34 | 35 | public static void main(String[] args) { 36 | REQUIRE.invoke(CLOJURE_MAIN); 37 | MAIN.applyTo(RT.seq(args)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/annotations.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 | ;; Authors: Stuart Halloway, Rich Hickey 10 | 11 | (ns clojure.test-clojure.annotations 12 | (:require [clojure.test :refer :all])) 13 | 14 | (case (System/getProperty "java.specification.version") 15 | "1.6" (load "annotations/java_6") 16 | nil) 17 | 18 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/annotations/java_5.clj: -------------------------------------------------------------------------------- 1 | ;; java 5 annotation tests 2 | (in-ns 'clojure.test-clojure.annotations) 3 | 4 | (import [java.lang.annotation Annotation Retention RetentionPolicy Target ElementType]) 5 | (definterface Foo (foo [])) 6 | 7 | (deftype #^{Deprecated true 8 | Retention RetentionPolicy/RUNTIME} 9 | Bar [#^int a 10 | #^{:tag int 11 | Deprecated true 12 | Retention RetentionPolicy/RUNTIME} b] 13 | Foo (#^{Deprecated true 14 | Retention RetentionPolicy/RUNTIME} 15 | foo [this] 42)) 16 | 17 | (defn annotation->map 18 | "Converts a Java annotation (which conceals data) 19 | into a map (which makes is usable). Not lazy. 20 | Works recursively. Returns non-annotations unscathed." 21 | [#^java.lang.annotation.Annotation o] 22 | (cond 23 | (instance? Annotation o) 24 | (let [type (.annotationType o) 25 | itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation)) 26 | data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))] 27 | (into 28 | {:annotationType (.annotationType o)} 29 | (map 30 | (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))]) 31 | data-methods))) 32 | (or (sequential? o) (.isArray (class o))) 33 | (map annotation->map o) 34 | :else o)) 35 | 36 | (def expected-annotations 37 | #{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME} 38 | {:annotationType java.lang.Deprecated}}) 39 | 40 | (deftest test-annotations-on-type 41 | (is (= 42 | expected-annotations 43 | (into #{} (map annotation->map (.getAnnotations Bar)))))) 44 | 45 | (deftest test-annotations-on-field 46 | (is (= 47 | expected-annotations 48 | (into #{} (map annotation->map (.getAnnotations (.getField Bar "b"))))))) 49 | 50 | (deftest test-annotations-on-method 51 | (is (= 52 | expected-annotations 53 | (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil))))))) 54 | 55 | (gen-class :name foo.Bar 56 | :extends clojure.lang.Box 57 | :constructors {^{Deprecated true} [Object] [Object]} 58 | :init init 59 | :prefix "foo") 60 | 61 | (defn foo-init [obj] 62 | [[obj] nil]) 63 | 64 | (deftest test-annotations-on-constructor 65 | (is (some #(instance? Deprecated %) 66 | (for [ctor (.getConstructors (Class/forName "foo.Bar")) 67 | annotation (.getAnnotations ctor)] 68 | annotation)))) 69 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all])) 13 | 14 | ;; http://clojure.org/atoms 15 | 16 | ;; atom 17 | ;; deref, @-reader-macro 18 | ;; swap! reset! 19 | ;; compare-and-set! 20 | 21 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/clojure_walk.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.clojure-walk 2 | (:require [clojure.walk :as w] 3 | [clojure.test :refer :all])) 4 | 5 | (deftest t-prewalk-replace 6 | (is (= (w/prewalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)]) 7 | [:b {:b :b} (list 3 :c :b)]))) 8 | 9 | (deftest t-postwalk-replace 10 | (is (= (w/postwalk-replace {:a :b} [:a {:a :a} (list 3 :c :a)]) 11 | [:b {:b :b} (list 3 :c :b)]))) 12 | 13 | (deftest t-stringify-keys 14 | (is (= (w/stringify-keys {:a 1, nil {:b 2 :c 3}, :d 4}) 15 | {"a" 1, nil {"b" 2 "c" 3}, "d" 4}))) 16 | 17 | (deftest t-prewalk-order 18 | (is (= (let [a (atom [])] 19 | (w/prewalk (fn [form] (swap! a conj form) form) 20 | [1 2 {:a 3} (list 4 [5])]) 21 | @a) 22 | [[1 2 {:a 3} (list 4 [5])] 23 | 1 2 {:a 3} [:a 3] :a 3 (list 4 [5]) 24 | 4 [5] 5]))) 25 | 26 | (deftest t-postwalk-order 27 | (is (= (let [a (atom [])] 28 | (w/postwalk (fn [form] (swap! a conj form) form) 29 | [1 2 {:a 3} (list 4 [5])]) 30 | @a) 31 | [1 2 32 | :a 3 [:a 3] {:a 3} 33 | 4 5 [5] (list 4 [5]) 34 | [1 2 {:a 3} (list 4 [5])]]))) 35 | 36 | (defrecord Foo [a b c]) 37 | 38 | (deftest walk 39 | "Checks that walk returns the correct result and type of collection" 40 | (let [colls ['(1 2 3) 41 | [1 2 3] 42 | #{1 2 3} 43 | (sorted-set-by > 1 2 3) 44 | {:a 1, :b 2, :c 3} 45 | (sorted-map-by > 1 10, 2 20, 3 30) 46 | (->Foo 1 2 3) 47 | (map->Foo {:a 1 :b 2 :c 3 :extra 4})]] 48 | (doseq [c colls] 49 | (let [walked (w/walk identity identity c)] 50 | (is (= c walked)) 51 | ;;(is (= (type c) (type walked))) 52 | (if (map? c) 53 | (is (= (w/walk #(update-in % [1] inc) #(reduce + (vals %)) c) 54 | (reduce + (map (comp inc val) c)))) 55 | (is (= (w/walk inc #(reduce + %) c) 56 | (reduce + (map inc c))))) 57 | (when (or (instance? clojure.lang.PersistentTreeMap c) 58 | (instance? clojure.lang.PersistentTreeSet c)) 59 | (is (= (.comparator c) (.comparator walked)))))))) 60 | 61 | -------------------------------------------------------------------------------- /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 | (ns clojure.test-clojure.clojure-xml 12 | (:require [clojure.test :refer :all] 13 | [clojure.xml :as xml])) 14 | 15 | ;; parse 16 | 17 | ;; emit-element 18 | ;; emit 19 | 20 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all] 14 | [clojure.zip :as zip])) 15 | 16 | ;; zipper 17 | ; 18 | ;; seq-zip 19 | ;; vector-zip 20 | ;; xml-zip 21 | ; 22 | ;; node 23 | ;; branch? 24 | ;; children 25 | ;; make-node 26 | ;; path 27 | ;; lefts 28 | ;; rights 29 | ;; down 30 | ;; up 31 | ;; root 32 | ;; right 33 | ;; rightmost 34 | ;; left 35 | ;; leftmost 36 | ; 37 | ;; insert-left 38 | ;; insert-right 39 | ;; replace 40 | ;; edit 41 | ;; insert-child 42 | ;; append-child 43 | ;; next 44 | ;; prev 45 | ;; end? 46 | ;; remove 47 | 48 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/compilation/clj_over_cljc.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.compilation.clj-over-cljc) 2 | 3 | (set! *1 :clj) 4 | 5 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/compilation/clj_over_cljc.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.compilation.clj-over-cljc) 2 | 3 | (set! *1 :cljc) 4 | 5 | -------------------------------------------------------------------------------- /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/compilation/jnt_first.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.compilation.jnt-first) 2 | 3 | (set! *1 :clj) 4 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/compilation/jnt_first.jnt: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.compilation.jnt-first) 2 | 3 | (set! *1 :jnt) 4 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/compilation/just_cljc.cljc: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.compilation.just-cljc) 2 | 3 | (set! *1 :cljc) 4 | 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | (:require [clojure.data :refer [diff]] 11 | [clojure.test :refer [deftest are]]) 12 | (import java.util.HashSet)) 13 | 14 | (deftest diff-test 15 | (are [d x y] (= d (diff x y)) 16 | [nil nil nil] nil nil 17 | [1 2 nil] 1 2 18 | [nil nil [1 2 3]] [1 2 3] '(1 2 3) 19 | [1 [:a :b] nil] 1 [:a :b] 20 | [{:a 1} :b nil] {:a 1} :b 21 | [:team #{:p1 :p2} nil] :team #{:p1 :p2} 22 | [{0 :a} [:a] nil] {0 :a} [:a] 23 | [nil [nil 2] [1]] [1] [1 2] 24 | [nil nil [1 2]] [1 2] (into-array [1 2]) 25 | [#{:a} #{:b} #{:c :d}] #{:a :c :d} #{:b :c :d} 26 | [nil nil {:a 1}] {:a 1} {:a 1} 27 | [{:a #{2}} {:a #{4}} {:a #{3}}] {:a #{2 3}} {:a #{3 4}} 28 | [#{1} #{3} #{2}] (HashSet. [1 2]) (HashSet. [2 3]) 29 | [nil nil [1 2]] [1 2] (into-array [1 2]) 30 | [nil nil [1 2]] (into-array [1 2]) [1 2] 31 | [{:a {:c [1]}} {:a {:c [0]}} {:a {:c [nil 2] :b 1}}] {:a {:b 1 :c [1 2]}} {:a {:b 1 :c [0 2]}} 32 | [{:a nil} {:a false} {:b nil :c false}] {:a nil :b nil :c false} {:a false :b nil :c false})) 33 | 34 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/delays.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.delays 2 | (:require [clojure.test :refer [deftest is]])) 3 | 4 | (deftest calls-once 5 | (let [a (atom 0) 6 | d (delay (swap! a inc))] 7 | (is (= 0 @a)) 8 | (is (= 1 @d)) 9 | (is (= 1 @d)) 10 | (is (= 1 @a)))) 11 | 12 | (deftest saves-exceptions 13 | (let [f #(do (throw (Exception. "broken")) 14 | 1) 15 | d (delay (f)) 16 | try-call #(try 17 | @d 18 | (catch Exception e e)) 19 | first-result (try-call)] 20 | (is (instance? Exception first-result)) 21 | (is (identical? first-result (try-call))))) 22 | -------------------------------------------------------------------------------- /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 | (ns clojure.test-clojure.edn 12 | (:require [clojure.test.generative :refer (defspec)] 13 | [clojure.test-clojure.generators :as cgen] 14 | [clojure.edn :as edn])) 15 | 16 | (defn roundtrip 17 | "Print an object and read it back as edn. Returns rather than throws 18 | any exceptions." 19 | [o] 20 | (binding [*print-length* nil 21 | *print-dup* nil 22 | *print-level* nil] 23 | (try 24 | (-> o pr-str edn/read-string) 25 | (catch Throwable t t)))) 26 | 27 | (defspec types-that-should-roundtrip 28 | roundtrip 29 | [^{:tag cgen/ednable} o] 30 | (when-not (= o %) 31 | (throw (ex-info "Value cannot roundtrip, see ex-data" {:printed o :read %})))) 32 | 33 | (defspec types-that-should-not-roundtrip 34 | roundtrip 35 | [^{:tag cgen/non-ednable} o] 36 | (when-not (instance? Throwable %) 37 | (throw (ex-info "edn/read should have thrown, see ex-data" {:printed o :read %})))) 38 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/fn.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: Ambrose Bonnaire-Sergeant 10 | 11 | (ns clojure.test-clojure.fn 12 | (:require [clojure.test :refer :all])) 13 | 14 | (deftest fn-error-checking 15 | (testing "bad arglist" 16 | (is (fails-with-cause? java.lang.IllegalArgumentException 17 | #"Parameter declaration a should be a vector" 18 | (eval '(fn "a" a))))) 19 | 20 | (testing "treat first param as args" 21 | (is (fails-with-cause? java.lang.IllegalArgumentException 22 | #"Parameter declaration a should be a vector" 23 | (eval '(fn "a" []))))) 24 | 25 | (testing "looks like listy signature, but malformed declaration" 26 | (is (fails-with-cause? java.lang.IllegalArgumentException 27 | #"Parameter declaration 1 should be a vector" 28 | (eval '(fn (1)))))) 29 | 30 | (testing "checks each signature" 31 | (is (fails-with-cause? java.lang.IllegalArgumentException 32 | #"Parameter declaration a should be a vector" 33 | (eval '(fn 34 | ([a] 1) 35 | ("a" 2)))))) 36 | 37 | (testing "correct name but invalid args" 38 | (is (fails-with-cause? java.lang.IllegalArgumentException 39 | #"Parameter declaration a should be a vector" 40 | (eval '(fn a "a"))))) 41 | 42 | (testing "first sig looks multiarity, rest of sigs should be lists" 43 | (is (fails-with-cause? java.lang.IllegalArgumentException 44 | #"Invalid signature \[a b\] should be a list" 45 | (eval '(fn a 46 | ([a] 1) 47 | [a b]))))) 48 | 49 | (testing "missing parameter declaration" 50 | (is (fails-with-cause? java.lang.IllegalArgumentException 51 | #"Parameter declaration missing" 52 | (eval '(fn a)))) 53 | (is (fails-with-cause? java.lang.IllegalArgumentException 54 | #"Parameter declaration missing" 55 | (eval '(fn)))))) 56 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all] 11 | [clojure.java.javadoc :as j]) 12 | (:import (java.io File))) 13 | 14 | (deftest javadoc-url-test 15 | (testing "for a core api" 16 | (binding [j/*feeling-lucky* false] 17 | (are [x y] (= x (#'j/javadoc-url y)) 18 | nil "foo.Bar" 19 | (str j/*core-java-api* "java/lang/String.html") "java.lang.String"))) 20 | (testing "for a remote javadoc" 21 | (binding [j/*remote-javadocs* (ref (sorted-map "java." "http://example.com/"))] 22 | (is (= "http://example.com/java/lang/Number.html" (#'j/javadoc-url "java.lang.Number")))))) 23 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all] 11 | [clojure.java.shell :as sh]) 12 | (:import [java.io File])) 13 | 14 | (def platform-enc 15 | (.name (java.nio.charset.Charset/defaultCharset))) 16 | 17 | (def default-enc 18 | "UTF-8") 19 | 20 | (deftest test-parse-args 21 | (let [o1 {:in-enc default-enc 22 | :out-enc default-enc 23 | :dir nil 24 | :env nil} 25 | o2 {:in-enc default-enc 26 | :out-enc "ISO-8859-1" 27 | :dir nil 28 | :env nil}] 29 | (are [x y] (= x y) 30 | [[] o1] (#'sh/parse-args []) 31 | [["ls"] o1] (#'sh/parse-args ["ls"]) 32 | [["ls" "-l"] o1] (#'sh/parse-args ["ls" "-l"]) 33 | [["ls"] o2] (#'sh/parse-args ["ls" :out-enc "ISO-8859-1"]) 34 | [[] o1] (#'sh/parse-args [:in-enc platform-enc :out-enc platform-enc])))) 35 | 36 | (deftest test-with-sh-dir 37 | (are [x y] (= x y) 38 | nil sh/*sh-dir* 39 | "foo" (sh/with-sh-dir "foo" sh/*sh-dir*))) 40 | 41 | (deftest test-with-sh-env 42 | (are [x y] (= x y) 43 | nil sh/*sh-env* 44 | {:KEY "VAL"} (sh/with-sh-env {:KEY "VAL"} sh/*sh-env*))) 45 | 46 | (deftest test-as-env-strings 47 | (are [x y] (= x y) 48 | nil (#'sh/as-env-strings nil) 49 | ["FOO=BAR"] (seq (#'sh/as-env-strings {"FOO" "BAR"})) 50 | ["FOO_SYMBOL=BAR"] (seq (#'sh/as-env-strings {'FOO_SYMBOL "BAR"})) 51 | ["FOO_KEYWORD=BAR"] (seq (#'sh/as-env-strings {:FOO_KEYWORD "BAR"})))) 52 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all])) 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 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/main.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.main 13 | (:require [clojure.test :refer :all] 14 | [clojure.test-helper :refer [platform-newlines]] 15 | [clojure.main :as main])) 16 | 17 | (deftest eval-opt 18 | (testing "evals and prints forms" 19 | (is (= (platform-newlines "2\n4\n") (with-out-str (#'clojure.main/eval-opt "(+ 1 1) (+ 2 2)"))))) 20 | 21 | (testing "skips printing nils" 22 | (is (= (platform-newlines ":a\n:c\n") (with-out-str (#'clojure.main/eval-opt ":a nil :c"))))) 23 | 24 | (testing "does not block access to *in* (#299)" 25 | (with-in-str "(+ 1 1)" 26 | (is (= (platform-newlines "(+ 1 1)\n") (with-out-str (#'clojure.main/eval-opt "(read)"))))))) 27 | 28 | (defmacro with-err-str 29 | "Evaluates exprs in a context in which *err* is bound to a fresh 30 | StringWriter. Returns the string created by any nested printing 31 | calls." 32 | [& body] 33 | `(let [s# (new java.io.StringWriter) 34 | p# (new java.io.PrintWriter s#)] 35 | (binding [*err* p#] 36 | ~@body 37 | (str s#)))) 38 | 39 | (defn run-repl-and-return-err 40 | "Run repl, swallowing stdout and returing stderr." 41 | [in-str] 42 | (with-err-str 43 | (with-out-str 44 | (with-in-str in-str 45 | (main/repl))))) 46 | 47 | ;argh - test fragility, please fix 48 | #_(deftest repl-exception-safety 49 | (testing "catches and prints exception on bad equals" 50 | (is (re-matches #"java\.lang\.NullPointerException\r?\n" 51 | (run-repl-and-return-err 52 | "(proxy [Object] [] (equals [o] (.toString nil)))"))))) 53 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all])) 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 | ;; pmap 24 | 25 | (deftest pmap-does-its-thing 26 | ;; regression fixed in r1218; was OutOfMemoryError 27 | (is (= '(1) (pmap inc [0])))) 28 | 29 | (def ^:dynamic *test-value* 1) 30 | 31 | (deftest future-fn-properly-retains-conveyed-bindings 32 | (let [a (atom [])] 33 | (binding [*test-value* 2] 34 | @(future (dotimes [_ 3] 35 | ;; we need some binding to trigger binding pop 36 | (binding [*print-dup* false] 37 | (swap! a conj *test-value*)))) 38 | (is (= [2 2 2] @a))))) 39 | -------------------------------------------------------------------------------- /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 | [clojure.test :refer [deftest is are run-tests]] 15 | [clojure.test-helper :refer [platform-newlines]] 16 | [clojure.test-clojure.pprint.test-helper :refer :all] 17 | [clojure.pprint :refer :all])) 18 | 19 | (load "pprint/test_cl_format") 20 | (load "pprint/test_pretty") 21 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer [deftest is]] 19 | [clojure.test-helper :refer [platform-newlines]])) 20 | 21 | (defn- back-match [x y] 22 | (re-matches y x)) 23 | 24 | (defmacro simple-tests [name & test-pairs] 25 | `(deftest ~name 26 | ~@(for [[x y] (partition 2 test-pairs)] 27 | (cond 28 | (instance? java.util.regex.Pattern y) 29 | `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y)) 30 | (instance? java.lang.String y) `(is (= ~x (platform-newlines ~y))) 31 | :else `(is (= ~x ~y)))))) 32 | 33 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/reflect.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.reflect 2 | (:require [clojure.data :refer :all] 3 | [clojure.reflect :as reflect] 4 | [clojure.test :refer :all] 5 | [clojure.pprint :refer :all]) 6 | (:import [clojure.reflect AsmReflector JavaReflector] 7 | [reflector IBar$Factory])) 8 | 9 | (defn nodiff 10 | [x y] 11 | (let [[x-only y-only common] (diff x y)] 12 | (when (or x-only y-only) 13 | (is false (with-out-str (pprint {:x-only x-only 14 | :y-only y-only 15 | :common common})))))) 16 | 17 | #_(deftest compare-reflect-and-asm 18 | (let [cl (.getContextClassLoader (Thread/currentThread)) 19 | asm-reflector (AsmReflector. cl) 20 | java-reflector (JavaReflector. cl)] 21 | (doseq [classname '[java.lang.Runnable 22 | java.lang.Object 23 | java.io.FileInputStream 24 | clojure.lang.Compiler 25 | clojure.lang.PersistentVector 26 | java.lang.SuppressWarnings]] 27 | (nodiff (type-reflect classname :reflector asm-reflector) 28 | (type-reflect classname :reflector java-reflector))))) 29 | 30 | (deftest field-descriptor->class-symbol-test 31 | (are [s d] (= s (@#'reflect/field-descriptor->class-symbol d)) 32 | 'clojure.asm.Type<><> "[[Lclojure/asm/Type;" 33 | 'int "I" 34 | 'java.lang.Object "Ljava.lang.Object;")) 35 | 36 | (deftest internal-name->class-symbol-test 37 | (are [s n] (= s (@#'reflect/internal-name->class-symbol n)) 38 | 'java.lang.Exception "java/lang/Exception")) 39 | 40 | (def inst (IBar$Factory/get)) 41 | (deftest invoking-nonpublic-super 42 | (is (= "stuff" (.stuff inst)))) 43 | -------------------------------------------------------------------------------- /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 | (ns clojure.test-clojure.refs 12 | (:require [clojure.test :refer :all])) 13 | 14 | ;; http://clojure.org/refs 15 | 16 | ;; ref 17 | ;; deref, @-reader-macro 18 | ;; dosync io! 19 | ;; ensure ref-set alter commute 20 | ;; set-validator get-validator 21 | 22 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/repl.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.repl 2 | (:require [clojure.test :refer :all] 3 | [clojure.repl :refer :all] 4 | [clojure.test-helper :refer [platform-newlines]] 5 | [clojure.test-clojure.repl.example :refer :all] 6 | [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 | 13 | (deftest test-source 14 | (is (= "(defn foo [])" (source-fn 'clojure.test-clojure.repl.example/foo))) 15 | (is (= "(defn qux [] ::s/foo)" (source-fn 'clojure.test-clojure.repl.example/qux))) 16 | (is (= (platform-newlines "(defn foo [])\n") (with-out-str (source clojure.test-clojure.repl.example/foo)))) 17 | (is (nil? (source-fn 'non-existent-fn)))) 18 | 19 | (deftest test-source-read-eval-unknown 20 | (is (thrown? IllegalStateException (binding [*read-eval* :unknown] (source reduce))))) 21 | 22 | (deftest test-source-read-eval-false 23 | (is (binding [*read-eval* false] (with-out-str (source reduce))))) 24 | 25 | (deftest test-dir 26 | (is (thrown? Exception (dir-fn 'non-existent-ns))) 27 | (is (= '[bar foo qux] (dir-fn 'clojure.test-clojure.repl.example))) 28 | (is (= (platform-newlines "bar\nfoo\nqux\n") (with-out-str (dir clojure.test-clojure.repl.example))))) 29 | 30 | (deftest test-apropos 31 | (testing "with a regular expression" 32 | (is (= '[clojure.core/defmacro] (apropos #"^defmacro$"))) 33 | (is (some #{'clojure.core/defmacro} (apropos #"def.acr."))) 34 | (is (= [] (apropos #"nothing-has-this-name")))) 35 | 36 | (testing "with a string" 37 | (is (some #{'clojure.core/defmacro} (apropos "defmacro"))) 38 | (is (some #{'clojure.core/defmacro} (apropos "efmac"))) 39 | (is (= [] (apropos "nothing-has-this-name")))) 40 | 41 | (testing "with a symbol" 42 | (is (some #{'clojure.core/defmacro} (apropos 'defmacro))) 43 | (is (some #{'clojure.core/defmacro} (apropos 'efmac))) 44 | (is (= [] (apropos 'nothing-has-this-name))))) 45 | 46 | (defmacro call-ns 47 | "Call ns with a unique namespace name. Return the result of calling ns" 48 | [] `(ns a#)) 49 | (defmacro call-ns-sym 50 | "Call ns wih a unique namespace name. Return the namespace symbol." 51 | [] `(do (ns a#) 'a#)) 52 | 53 | (deftest test-dynamic-ns 54 | (testing "a call to ns returns nil" 55 | (is (= nil (call-ns)))) 56 | (testing "requiring a dynamically created ns should not throw an exception" 57 | (is (= nil (let [a (call-ns-sym)] (require a)))))) 58 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/repl/example.clj: -------------------------------------------------------------------------------- 1 | (ns clojure.test-clojure.repl.example 2 | (:require [clojure.string :as s])) 3 | 4 | ;; sample namespace for repl tests, don't add anything here 5 | (defn foo []) 6 | (defn bar []) 7 | (defn qux [] ::s/foo) 8 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all]) 13 | (:require [clojure.core.server :as s])) 14 | 15 | (defn check-invalid-opts 16 | [opts msg] 17 | (try 18 | (#'clojure.core.server/validate-opts opts) 19 | (is nil) 20 | (catch Exception e 21 | (is (= (ex-data e) opts)) 22 | (is (= msg (.getMessage e)))))) 23 | 24 | (deftest test-validate-opts 25 | (check-invalid-opts {} "Missing required socket server property :name") 26 | (check-invalid-opts {:name "a" :accept 'clojure.core/+} "Missing required socket server property :port") 27 | (doseq [port [-1 "5" 999999]] 28 | (check-invalid-opts {:name "a" :port port :accept 'clojure.core/+} (str "Invalid socket server port: " port))) 29 | (check-invalid-opts {:name "a" :port 5555} "Missing required socket server property :accept")) 30 | -------------------------------------------------------------------------------- /test/clojure/test_clojure/special.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 | ;; Test special forms, macros and metadata 13 | ;; 14 | 15 | (ns clojure.test-clojure.special 16 | (:require [clojure.test :refer :all])) 17 | 18 | ;; http://clojure.org/special_forms 19 | 20 | ;; let, letfn 21 | ;; quote 22 | ;; var 23 | ;; fn 24 | 25 | (deftest multiple-keys-in-destructuring 26 | (let [foo (fn [& {:keys [x]}] x) 27 | bar (fn [& options] (apply foo :x :b options))] 28 | (is (= (bar) :b)) 29 | (is (= (bar :x :a) :a)))) 30 | 31 | (deftest empty-list-with-:as-destructuring 32 | (let [{:as x} '()] 33 | (is (= {} x)))) 34 | 35 | (deftest keywords-in-destructuring 36 | (let [{:keys [:a :b]} {:a 1 :b 2}] 37 | (is (= 1 a)) 38 | (is (= 2 b)))) 39 | 40 | (deftest namespaced-keywords-in-destructuring 41 | (let [{:keys [:a/b :c/d]} {:a/b 1 :c/d 2}] 42 | (is (= 1 b)) 43 | (is (= 2 d)))) 44 | 45 | (deftest namespaced-keys-in-destructuring 46 | (let [{:keys [a/b c/d]} {:a/b 1 :c/d 2}] 47 | (is (= 1 b)) 48 | (is (= 2 d)))) 49 | 50 | (deftest namespaced-syms-in-destructuring 51 | (let [{:syms [a/b c/d]} {'a/b 1 'c/d 2}] 52 | (is (= 1 b)) 53 | (is (= 2 d)))) 54 | 55 | (deftest keywords-not-allowed-in-let-bindings 56 | (is (thrown-with-msg? Exception #"Unsupported binding form: :a" 57 | (eval '(let [:a 1] a)))) 58 | (is (thrown-with-msg? Exception #"Unsupported binding form: :a/b" 59 | (eval '(let [:a/b 1] b)))) 60 | (is (thrown-with-msg? Exception #"Unsupported binding form: :a" 61 | (eval '(let [[:a] [1]] a)))) 62 | (is (thrown-with-msg? Exception #"Unsupported binding form: :a/b" 63 | (eval '(let [[:a/b] [1]] b))))) 64 | 65 | (deftest namespaced-syms-only-allowed-in-map-destructuring 66 | (is (thrown-with-msg? Exception #"Can't let qualified name: a/x" 67 | (eval '(let [a/x 1, [y] [1]] x)))) 68 | (is (thrown-with-msg? Exception #"Can't let qualified name: a/x" 69 | (eval '(let [[a/x] [1]] x))))) 70 | 71 | (require '[clojure.string :as s]) 72 | (deftest resolve-keyword-ns-alias-in-destructuring 73 | (let [{:keys [::s/x ::s/y]} {:clojure.string/x 1 :clojure.string/y 2}] 74 | (is (= x 1)) 75 | (is (= y 2)))) 76 | 77 | (deftest quote-with-multiple-args 78 | (let [ex (is (thrown? clojure.lang.Compiler$CompilerException 79 | (eval '(quote 1 2 3))))] 80 | (is (= '(quote 1 2 3) 81 | (-> ex 82 | (.getCause) 83 | (ex-data) 84 | (:form)))))) 85 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all])) 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/transients.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.transients 10 | (:require [clojure.test :refer :all])) 11 | 12 | (deftest popping-off 13 | (testing "across a node boundary" 14 | (are [n] 15 | (let [v (-> (range n) vec)] 16 | (= (subvec v 0 (- n 2)) (-> v transient pop! pop! persistent!))) 17 | 33 (+ 32 (inc (* 32 32))) (+ 32 (inc (* 32 32 32))))) 18 | (testing "off the end" 19 | (is (thrown-with-msg? IllegalStateException #"Can't pop empty vector" 20 | (-> [] transient pop!)))) 21 | (testing "copying array from a non-editable when put in tail position") 22 | (is (= 31 (let [pv (vec (range 34))] 23 | (-> pv transient pop! pop! pop! (conj! 42)) 24 | (nth pv 31))))) 25 | 26 | (defn- hash-obj [hash] 27 | (reify Object (hashCode [this] hash))) 28 | 29 | (deftest dissocing 30 | (testing "dissocing colliding keys" 31 | (is (= [0 {}] (let [ks (concat (range 7) [(hash-obj 42) (hash-obj 42)]) 32 | m (zipmap ks ks) 33 | dm (persistent! (reduce dissoc! (transient m) (keys m)))] 34 | [(count dm) dm]))))) 35 | 36 | (deftest test-disj! 37 | (testing "disjoin multiple items in one call" 38 | (is (= #{5 20} (-> #{5 10 15 20} transient (disj! 10 15) persistent!))))) 39 | 40 | (deftest empty-transient 41 | (is (= false (.contains (transient #{}) :bogus-key)))) 42 | 43 | (deftest persistent-assoc-on-collision 44 | (testing "Persistent assoc on a collision node which underwent a transient dissoc" 45 | (let [a (reify Object (hashCode [_] 42)) 46 | b (reify Object (hashCode [_] 42))] 47 | (is (= (-> #{a b} transient (disj! a) persistent! (conj a)) 48 | (-> #{a b} transient (disj! a) persistent! (conj a))))))) 49 | 50 | (deftest transient-mod-after-persistent 51 | (let [v [1 2 3] 52 | t (transient v) 53 | t2 (conj! t 4) 54 | p (persistent! t2)] 55 | (is (= [1 2 3 4] p)) 56 | (is (thrown? IllegalAccessError (conj! t2 5))))) 57 | 58 | (deftest transient-mod-ok-across-threads 59 | (let [v [1 2 3] 60 | t (transient v) 61 | t2 @(future (conj! t 4)) 62 | p (persistent! t2)] 63 | (is (= [1 2 3 4] p)))) 64 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all]) 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 | (defn fail [x] 29 | (ReflectorTryCatchFixture/fail x)) 30 | 31 | (defn make-instance [] 32 | (ReflectorTryCatchFixture.)) 33 | 34 | (deftest catch-receives-checked-exception-from-reflective-call 35 | (is (thrown-with-msg? ReflectorTryCatchFixture$Cookies #"Long" (fail 1))) 36 | (is (thrown-with-msg? ReflectorTryCatchFixture$Cookies #"Double" (fail 1.0))) 37 | (is (thrown-with-msg? ReflectorTryCatchFixture$Cookies #"Wrapped" 38 | (.failWithCause (make-instance) 1.0)))) 39 | -------------------------------------------------------------------------------- /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 | (:require [clojure.test :refer :all])) 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/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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------