diff --git a/.gitignore b/.gitignore
index 4da745791..609f04b03 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,368 +1,368 @@
-
-## Ignore Visual Studio temporary files, build results, and
-## files generated by popular Visual Studio add-ons.
-##
-## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
-
-# User-specific files
-*.rsuser
-*.suo
-*.user
-*.userosscache
-*.sln.docstates
-
-# User-specific files (MonoDevelop/Xamarin Studio)
-*.userprefs
-
-# Mono auto generated files
-mono_crash.*
-
-# Build results
-[Dd]ebug/
-[Dd]ebugPublic/
-[Rr]elease/
-[Rr]eleases/
-x64/
-x86/
-[Aa][Rr][Mm]/
-[Aa][Rr][Mm]64/
-bld/
-[Bb]in/
-[Oo]bj/
-[Ll]og/
-
-# Visual Studio 2015/2017 cache/options directory
-.vs/
-# Uncomment if you have tasks that create the project's static files in wwwroot
-#wwwroot/
-
-# Visual Studio 2017 auto generated files
-Generated\ Files/
-
-# MSTest test Results
-[Tt]est[Rr]esult*/
-[Bb]uild[Ll]og.*
-
-# NUNIT
-*.VisualState.xml
-TestResult.xml
-
-# Build Results of an ATL Project
-[Dd]ebugPS/
-[Rr]eleasePS/
-dlldata.c
-
-# Benchmark Results
-BenchmarkDotNet.Artifacts/
-
-# .NET Core
-project.lock.json
-project.fragment.lock.json
-artifacts/
-
-# StyleCop
-StyleCopReport.xml
-
-# Files built by Visual Studio
-*_i.c
-*_p.c
-*_h.h
-*.ilk
-*.meta
-*.obj
-*.iobj
-*.pch
-*.pdb
-*.ipdb
-*.pgc
-*.pgd
-*.rsp
-*.sbr
-*.tlb
-*.tli
-*.tlh
-*.tmp
-*.tmp_proj
-*_wpftmp.csproj
-*.log
-*.vspscc
-*.vssscc
-.builds
-*.pidb
-*.svclog
-*.scc
-
-# Chutzpah Test files
-_Chutzpah*
-
-# Visual C++ cache files
-ipch/
-*.aps
-*.ncb
-*.opendb
-*.opensdf
-*.sdf
-*.cachefile
-*.VC.db
-*.VC.VC.opendb
-
-# Visual Studio profiler
-*.psess
-*.vsp
-*.vspx
-*.sap
-
-# Visual Studio Trace Files
-*.e2e
-
-# TFS 2012 Local Workspace
-$tf/
-
-# Guidance Automation Toolkit
-*.gpState
-
-# ReSharper is a .NET coding add-in
-_ReSharper*/
-*.[Rr]e[Ss]harper
-*.DotSettings.user
-
-# JustCode is a .NET coding add-in
-.JustCode
-
-# TeamCity is a build add-in
-_TeamCity*
-
-# DotCover is a Code Coverage Tool
-*.dotCover
-
-# AxoCover is a Code Coverage Tool
-.axoCover/*
-!.axoCover/settings.json
-
-# Visual Studio code coverage results
-*.coverage
-*.coveragexml
-
-# NCrunch
-_NCrunch_*
-.*crunch*.local.xml
-nCrunchTemp_*
-
-# MightyMoose
-*.mm.*
-AutoTest.Net/
-
-# Web workbench (sass)
-.sass-cache/
-
-# Installshield output folder
-[Ee]xpress/
-
-# DocProject is a documentation generator add-in
-DocProject/buildhelp/
-DocProject/Help/*.HxT
-DocProject/Help/*.HxC
-DocProject/Help/*.hhc
-DocProject/Help/*.hhk
-DocProject/Help/*.hhp
-DocProject/Help/Html2
-DocProject/Help/html
-
-# Click-Once directory
-publish/
-
-# Publish Web Output
-*.[Pp]ublish.xml
-*.azurePubxml
-# Note: Comment the next line if you want to checkin your web deploy settings,
-# but database connection strings (with potential passwords) will be unencrypted
-*.pubxml
-*.publishproj
-
-# Microsoft Azure Web App publish settings. Comment the next line if you want to
-# checkin your Azure Web App publish settings, but sensitive information contained
-# in these scripts will be unencrypted
-PublishScripts/
-
-# NuGet Packages
-*.nupkg
-# NuGet Symbol Packages
-*.snupkg
-# The packages folder can be ignored because of Package Restore
-**/[Pp]ackages/*
-# except build/, which is used as an MSBuild target.
-!**/[Pp]ackages/build/
-# Uncomment if necessary however generally it will be regenerated when needed
-#!**/[Pp]ackages/repositories.config
-# NuGet v3's project.json files produces more ignorable files
-*.nuget.props
-*.nuget.targets
-
-# Microsoft Azure Build Output
-csx/
-*.build.csdef
-
-# Microsoft Azure Emulator
-ecf/
-rcf/
-
-# Windows Store app package directories and files
-AppPackages/
-BundleArtifacts/
-Package.StoreAssociation.xml
-_pkginfo.txt
-*.appx
-*.appxbundle
-*.appxupload
-
-# Visual Studio cache files
-# files ending in .cache can be ignored
-*.[Cc]ache
-# but keep track of directories ending in .cache
-!?*.[Cc]ache/
-
-# Others
-ClientBin/
-~$*
-*~
-*.dbmdl
-*.dbproj.schemaview
-*.jfm
-*.pfx
-*.publishsettings
-orleans.codegen.cs
-
-# Including strong name files can present a security risk
-# (https://github.com/github/gitignore/pull/2483#issue-259490424)
-#*.snk
-
-# Since there are multiple workflows, uncomment next line to ignore bower_components
-# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
-#bower_components/
-
-# RIA/Silverlight projects
-Generated_Code/
-
-# Backup & report files from converting an old project file
-# to a newer Visual Studio version. Backup files are not needed,
-# because we have git ;-)
-_UpgradeReport_Files/
-Backup*/
-UpgradeLog*.XML
-UpgradeLog*.htm
-ServiceFabricBackup/
-*.rptproj.bak
-
-# SQL Server files
-*.mdf
-*.ldf
-*.ndf
-
-# Business Intelligence projects
-*.rdl.data
-*.bim.layout
-*.bim_*.settings
-*.rptproj.rsuser
-*- [Bb]ackup.rdl
-*- [Bb]ackup ([0-9]).rdl
-*- [Bb]ackup ([0-9][0-9]).rdl
-
-# Microsoft Fakes
-FakesAssemblies/
-
-# GhostDoc plugin setting file
-*.GhostDoc.xml
-
-# Node.js Tools for Visual Studio
-.ntvs_analysis.dat
-node_modules/
-
-# Visual Studio 6 build log
-*.plg
-
-# Visual Studio 6 workspace options file
-*.opt
-
-# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
-*.vbw
-
-# Visual Studio LightSwitch build output
-**/*.HTMLClient/GeneratedArtifacts
-**/*.DesktopClient/GeneratedArtifacts
-**/*.DesktopClient/ModelManifest.xml
-**/*.Server/GeneratedArtifacts
-**/*.Server/ModelManifest.xml
-_Pvt_Extensions
-
-# Paket dependency manager
-.paket/paket.exe
-paket-files/
-
-# FAKE - F# Make
-.fake/
-
-# CodeRush personal settings
-.cr/personal
-
-# Python Tools for Visual Studio (PTVS)
-__pycache__/
-*.pyc
-
-# Cake - Uncomment if you are using it
-# tools/**
-# !tools/packages.config
-
-# Tabs Studio
-*.tss
-
-# Telerik's JustMock configuration file
-*.jmconfig
-
-# BizTalk build output
-*.btp.cs
-*.btm.cs
-*.odx.cs
-*.xsd.cs
-
-# OpenCover UI analysis results
-OpenCover/
-
-# Azure Stream Analytics local run output
-ASALocalRun/
-
-# MSBuild Binary and Structured Log
-*.binlog
-
-# NVidia Nsight GPU debugger configuration file
-*.nvuser
-
-# MFractors (Xamarin productivity tool) working folder
-.mfractor/
-
-# Local History for Visual Studio
-.localhistory/
-
-# BeatPulse healthcheck temp database
-healthchecksdb
-
-# Backup folder for Package Reference Convert tool in Visual Studio 2017
-MigrationBackup/
-
-######
-#
-# Some of my own stuff
-#
-######
-
-####lib/
-
-# Emacs artifacts
-*~
-# Java artifacts
-*.class
-**/pub/
-
-# testing directories
-testing/
-
-Stage/
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUNIT
+*.VisualState.xml
+TestResult.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# JustCode is a .NET coding add-in
+.JustCode
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+######
+#
+# Some of my own stuff
+#
+######
+
+####lib/
+
+# Emacs artifacts
+*~
+# Java artifacts
+*.class
+**/pub/
+
+# testing directories
+testing/
+
+Stage/
diff --git a/Clojure.nuspec b/Clojure.nuspec
index fd7bdc467..82c702fc4 100644
--- a/Clojure.nuspec
+++ b/Clojure.nuspec
@@ -1,38 +1,38 @@
-
-
-
- Clojure
- 1.10.0
- Rich Hickey, Clojure
- false
- http://opensource.org/licenses/eclipse-1.0.php
- https://github.com/clojure/clojure-clr
- http://clojure.org/file/view/clojure-icon.gif
- Clojure for the CLR.
- clojure clojureclr
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ Clojure
+ 1.10.0
+ Rich Hickey, Clojure
+ false
+ http://opensource.org/licenses/eclipse-1.0.php
+ https://github.com/clojure/clojure-clr
+ http://clojure.org/file/view/clojure-icon.gif
+ Clojure for the CLR.
+ clojure clojureclr
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Clojure/Clojure.Compile/Clojure.Compile.csproj b/Clojure/Clojure.Compile/Clojure.Compile.csproj
index e4fb48063..2d7ef37f3 100644
--- a/Clojure/Clojure.Compile/Clojure.Compile.csproj
+++ b/Clojure/Clojure.Compile/Clojure.Compile.csproj
@@ -1,40 +1,40 @@
-
-
-
- Exe
- net462
- BootstrapCompile.Compile
-
-
-
- 0
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $(TargetPath)
- mono $(TargetPath)
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ Exe
+ net462
+ BootstrapCompile.Compile
+
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(TargetPath)
+ mono $(TargetPath)
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Clojure/Clojure.Compile/Compile.cs b/Clojure/Clojure.Compile/Compile.cs
index ee9b24868..78822494f 100644
--- a/Clojure/Clojure.Compile/Compile.cs
+++ b/Clojure/Clojure.Compile/Compile.cs
@@ -1,98 +1,98 @@
-/**
- * Copyright (c) Rich Hickey. All rights reserved.
- * The use and distribution terms for this software are covered by the
- * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
- * which can be found in the file epl-v10.html at the root of this distribution.
- * By using this software in any fashion, you are agreeing to be bound by
- * the terms of this license.
- * You must not remove this notice, or any other, from this software.
- **/
-
-/**
- * Author: David Miller
- **/
-
-using System;
-using System.Diagnostics;
-using System.IO;
-using clojure.lang;
-
-namespace BootstrapCompile
-{
- static class Compile
- {
-
- const string PATH_PROP = "CLOJURE_COMPILE_PATH";
- const string REFLECTION_WARNING_PROP = "CLOJURE_COMPILE_WARN_ON_REFLECTION";
- const string UNCHECKED_MATH_PROP = "CLOJURE_COMPILE_UNCHECKED_MATH";
-
- static void Main(string[] args)
- {
- RT.Init();
-
- TextWriter outTW = (TextWriter)RT.OutVar.deref();
- TextWriter errTW = RT.errPrintWriter();
-
- string path = Environment.GetEnvironmentVariable(PATH_PROP);
-
- path = path ?? ".";
-
- string warnVal = Environment.GetEnvironmentVariable(REFLECTION_WARNING_PROP);
- bool warnOnReflection = warnVal == null ? false : warnVal.Equals("true");
- string mathVal = Environment.GetEnvironmentVariable(UNCHECKED_MATH_PROP);
- object uncheckedMath = false;
-
- if ("true".Equals(mathVal))
- uncheckedMath = true;
- else if ("warn-on-boxed".Equals(mathVal))
- uncheckedMath = Keyword.intern("warn-on-boxed");
-
-
- // Force load to avoid transitive compilation during lazy load
- Compiler.EnsureMacroCheck();
-
- try
- {
- Var.pushThreadBindings(RT.map(
- Compiler.CompilePathVar, path,
- RT.WarnOnReflectionVar, warnOnReflection,
- RT.UncheckedMathVar, uncheckedMath
- ));
-
- Stopwatch sw = new Stopwatch();
-
- foreach (string lib in args)
- {
- sw.Reset();
- sw.Start();
- outTW.Write("Compiling {0} to {1}", lib, path);
- outTW.Flush();
- Compiler.CompileVar.invoke(Symbol.intern(lib));
- sw.Stop();
- outTW.WriteLine(" -- {0} milliseconds.", sw.ElapsedMilliseconds);
- }
- }
- catch (Exception e)
- {
- errTW.WriteLine(e.ToString());
- errTW.Flush();
- Environment.Exit(1);
- }
- finally
- {
- Var.popThreadBindings();
- try {
- outTW.Flush();
- }
- catch ( IOException e)
- {
- errTW.WriteLine(e.StackTrace);
- errTW.Flush();
- }
- }
-
-
-
- }
- }
-}
+/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+ * which can be found in the file epl-v10.html at the root of this distribution.
+ * By using this software in any fashion, you are agreeing to be bound by
+ * the terms of this license.
+ * You must not remove this notice, or any other, from this software.
+ **/
+
+/**
+ * Author: David Miller
+ **/
+
+using System;
+using System.Diagnostics;
+using System.IO;
+using clojure.lang;
+
+namespace BootstrapCompile
+{
+ static class Compile
+ {
+
+ const string PATH_PROP = "CLOJURE_COMPILE_PATH";
+ const string REFLECTION_WARNING_PROP = "CLOJURE_COMPILE_WARN_ON_REFLECTION";
+ const string UNCHECKED_MATH_PROP = "CLOJURE_COMPILE_UNCHECKED_MATH";
+
+ static void Main(string[] args)
+ {
+ RT.Init();
+
+ TextWriter outTW = (TextWriter)RT.OutVar.deref();
+ TextWriter errTW = RT.errPrintWriter();
+
+ string path = Environment.GetEnvironmentVariable(PATH_PROP);
+
+ path = path ?? ".";
+
+ string warnVal = Environment.GetEnvironmentVariable(REFLECTION_WARNING_PROP);
+ bool warnOnReflection = warnVal == null ? false : warnVal.Equals("true");
+ string mathVal = Environment.GetEnvironmentVariable(UNCHECKED_MATH_PROP);
+ object uncheckedMath = false;
+
+ if ("true".Equals(mathVal))
+ uncheckedMath = true;
+ else if ("warn-on-boxed".Equals(mathVal))
+ uncheckedMath = Keyword.intern("warn-on-boxed");
+
+
+ // Force load to avoid transitive compilation during lazy load
+ Compiler.EnsureMacroCheck();
+
+ try
+ {
+ Var.pushThreadBindings(RT.map(
+ Compiler.CompilePathVar, path,
+ RT.WarnOnReflectionVar, warnOnReflection,
+ RT.UncheckedMathVar, uncheckedMath
+ ));
+
+ Stopwatch sw = new Stopwatch();
+
+ foreach (string lib in args)
+ {
+ sw.Reset();
+ sw.Start();
+ outTW.Write("Compiling {0} to {1}", lib, path);
+ outTW.Flush();
+ Compiler.CompileVar.invoke(Symbol.intern(lib));
+ sw.Stop();
+ outTW.WriteLine(" -- {0} milliseconds.", sw.ElapsedMilliseconds);
+ }
+ }
+ catch (Exception e)
+ {
+ errTW.WriteLine(e.ToString());
+ errTW.Flush();
+ Environment.Exit(1);
+ }
+ finally
+ {
+ Var.popThreadBindings();
+ try {
+ outTW.Flush();
+ }
+ catch ( IOException e)
+ {
+ errTW.WriteLine(e.StackTrace);
+ errTW.Flush();
+ }
+ }
+
+
+
+ }
+ }
+}
diff --git a/Clojure/Clojure.Main/Clojure.Main.csproj b/Clojure/Clojure.Main/Clojure.Main.csproj
index d21575f85..8acf599a8 100644
--- a/Clojure/Clojure.Main/Clojure.Main.csproj
+++ b/Clojure/Clojure.Main/Clojure.Main.csproj
@@ -1,27 +1,27 @@
-
-
-
- Exe
- netcoreapp3.1;net6.0;net7.0
- Clojure.CljMain
- true
-
-
-
- ClojureCLR-REPL
- Standard REPL for ClojureCLR.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ Exe
+ netcoreapp3.1;net6.0;net7.0
+ Clojure.CljMain
+ true
+
+
+
+ ClojureCLR-REPL
+ Standard REPL for ClojureCLR.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Clojure/Clojure.Main/Main.cs b/Clojure/Clojure.Main/Main.cs
index afa6589fb..dc3784f26 100644
--- a/Clojure/Clojure.Main/Main.cs
+++ b/Clojure/Clojure.Main/Main.cs
@@ -1,57 +1,57 @@
-/**
- * Copyright (c) Rich Hickey. All rights reserved.
- * The use and distribution terms for this software are covered by the
- * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
- * which can be found in the file epl-v10.html at the root of this distribution.
- * By using this software in any fashion, you are agreeing to be bound by
- * the terms of this license.
- * You must not remove this notice, or any other, from this software.
- **/
-
-/**
- * Author: David Miller
- **/
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using clojure.lang;
-
-namespace Clojure
-{
- public static class CljMain
- {
- private static readonly Symbol CLOJURE_MAIN = Symbol.intern("clojure.main");
- private static readonly Var REQUIRE = RT.var("clojure.core", "require");
- private static readonly Var LEGACY_REPL = RT.var("clojure.main", "legacy-repl");
- private static readonly Var LEGACY_SCRIPT = RT.var("clojure.main", "legacy-script");
- private static readonly Var MAIN = RT.var("clojure.main", "main");
-
- static void Main(string[] args)
- {
- RT.Init();
- REQUIRE.invoke(CLOJURE_MAIN);
- MAIN.applyTo(RT.seq(args));
- }
-
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "ClojureJVM name match")]
- public static void legacy_repl(string[] args)
- {
- RT.Init();
- REQUIRE.invoke(CLOJURE_MAIN);
- LEGACY_REPL.invoke(RT.seq(args));
-
- }
-
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "ClojureJVM name match")]
- public static void legacy_script(string[] args)
- {
- RT.Init();
- REQUIRE.invoke(CLOJURE_MAIN);
- LEGACY_SCRIPT.invoke(RT.seq(args));
- }
-
-
- }
-}
+/**
+ * Copyright (c) Rich Hickey. All rights reserved.
+ * The use and distribution terms for this software are covered by the
+ * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+ * which can be found in the file epl-v10.html at the root of this distribution.
+ * By using this software in any fashion, you are agreeing to be bound by
+ * the terms of this license.
+ * You must not remove this notice, or any other, from this software.
+ **/
+
+/**
+ * Author: David Miller
+ **/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using clojure.lang;
+
+namespace Clojure
+{
+ public static class CljMain
+ {
+ private static readonly Symbol CLOJURE_MAIN = Symbol.intern("clojure.main");
+ private static readonly Var REQUIRE = RT.var("clojure.core", "require");
+ private static readonly Var LEGACY_REPL = RT.var("clojure.main", "legacy-repl");
+ private static readonly Var LEGACY_SCRIPT = RT.var("clojure.main", "legacy-script");
+ private static readonly Var MAIN = RT.var("clojure.main", "main");
+
+ static void Main(string[] args)
+ {
+ RT.Init();
+ REQUIRE.invoke(CLOJURE_MAIN);
+ MAIN.applyTo(RT.seq(args));
+ }
+
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "ClojureJVM name match")]
+ public static void legacy_repl(string[] args)
+ {
+ RT.Init();
+ REQUIRE.invoke(CLOJURE_MAIN);
+ LEGACY_REPL.invoke(RT.seq(args));
+
+ }
+
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "ClojureJVM name match")]
+ public static void legacy_script(string[] args)
+ {
+ RT.Init();
+ REQUIRE.invoke(CLOJURE_MAIN);
+ LEGACY_SCRIPT.invoke(RT.seq(args));
+ }
+
+
+ }
+}
diff --git a/Clojure/Clojure.Source/Clojure.Source.csproj b/Clojure/Clojure.Source/Clojure.Source.csproj
index 6454d1e8e..5705b1c80 100644
--- a/Clojure/Clojure.Source/Clojure.Source.csproj
+++ b/Clojure/Clojure.Source/Clojure.Source.csproj
@@ -1,137 +1,137 @@
-
-
-
- netstandard2.1;netstandard2.0
-
- true
-
-
-
- TRACE;DEBUG
-
-
-
-
-
-
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
- PreserveNewest
-
-
-
-
+
+
+
+ netstandard2.1;netstandard2.0
+
+ true
+
+
+
+ TRACE;DEBUG
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+
+
diff --git a/Clojure/Clojure.Source/clojure/clr/io.clj b/Clojure/Clojure.Source/clojure/clr/io.clj
index 64981b437..a7a47afdb 100644
--- a/Clojure/Clojure.Source/clojure/clr/io.clj
+++ b/Clojure/Clojure.Source/clojure/clr/io.clj
@@ -1,468 +1,468 @@
-; Copyright (c) Rich Hickey. All rights reserved.
-; The use and distribution terms for this software are covered by the
-; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
-; which can be found in the file epl-v10.html at the root of this distribution.
-; By using this software in any fashion, you are agreeing to be bound by
-; the terms of this license.
-; You must not remove this notice, or any other, from this software.
-
-(ns
- ^{:author "David Miller",
- :doc "Shamelessly based on the clojure.java.io package authored by Stuart Sierra, Chas Emerick, Stuart Halloway.
- This file defines polymorphic I/O utility functions for Clojure."}
- clojure.clr.io
- (:import
- (System.IO
- Stream BufferedStream
- FileInfo FileStream MemoryStream
- FileMode FileShare FileAccess FileOptions
- BinaryReader BinaryWriter
- StreamReader StreamWriter
- StringReader StringWriter
- TextReader TextWriter)
- (System.Net.Sockets
- Socket NetworkStream)
- (System.Text
- Encoding UTF8Encoding UnicodeEncoding UTF32Encoding UTF7Encoding ASCIIEncoding Decoder Encoder)
- (System
- Uri UriFormatException)))
-
-
-(defprotocol ^{:added "1.2"} Coercions
- "Coerce between various 'resource-namish' things."
- (^{:tag System.IO.FileInfo, :added "1.2"} as-file [x] "Coerce argument to a file.")
- (^{:tag System.Uri, :added "1.2"} as-uri [x] "Coerce argument to a URI."))
-
-(extend-protocol Coercions
- nil
- (as-file [_] nil)
- (as-uri [_] nil)
-
- String
- (as-file [s] (FileInfo. s))
- (as-uri [s] (Uri. s))
-
- FileInfo
- (as-file [f] f)
- (as-uri [f] (Uri. (str "file://" (.FullName f))))
-
- Uri
- (as-uri [u] u)
- (as-file [u]
- (if (.IsFile u)
- (as-file (.LocalPath u))
- (throw (ArgumentException. (str "Not a file: " u))))))
-
-(defprotocol ^{:added "1.2"} IOFactory
- "Factory functions that create ready-to-use, buffered versions of
- the various Java I/O stream types, on top of anything that can
- be unequivocally converted to the requested kind of stream.
-
- Common options include
-
- :buffer-size Ths size of buffer to use (default: 1024).
- :file-share A value from the System.IO.FileShare enumeration.
- :file-mode A value from the System.IO.FileMode enumeration.
- :file-access A value from the System.IO.FileAccess enumeration.
- :file-options A value from the System.IO.FileOptions enumeration.
- :encoding The encoding to use, either as a string, e.g. \"UTF-8\",
- a keyword, e.g. :utf-8, or a an System.Text.Encoding instance,
- e.g., (System.Text.UTF8Encoding.)
-
- Callers should generally prefer the higher level API provided by
- reader, writer, input-stream, and output-stream."
- (^{:added "1.2"} make-text-reader [x opts] "Creates a TextReader. See also IOFactory docs.")
- (^{:added "1.2"} make-text-writer [x opts] "Creates a TextWriter. See also IOFactory docs.")
- (^{:added "1.2"} make-input-stream [x opts] "Creates a Stream in input mode. See also IOFactory docs.")
- (^{:added "1.2"} make-output-stream [x opts] "Creates a Stream in output mode. See also IOFactory docs.")
- (^{:added "1.2"} make-binary-reader [x opts] "Creates a BinaryReader. See also IOFactory docs.")
- (^{:added "1.2"} make-binary-writer [x opts] "Creates a BinaryWriter. See also IOFactory docs."))
-
-(defn ^TextReader text-reader
- "Attempts to coerce its argument into an open System.IO.TextReader.
-
- Default implementations are provided for Stream, Uri, FileInfo, Socket,
- byte arrays, and String.
-
- If argument is a String, it tries to resolve it first as a URI, then
- as a local file name. URIs with a 'file' protocol are converted to
- local file names.
-
- Should be used inside with-open to ensure the TextReader is properly
- closed."
- {:added "1.2"}
- [x & opts]
- (make-text-reader x (when opts (apply hash-map opts))))
-
-(defn ^TextWriter text-writer
- "Attempts to coerce its argument into an open System.IO.TextWriter.
-
- Default implementations are provided for Stream, Uri, FileInfo, Socket,
- and String.
-
- If the argument is a String, it tries to resolve it first as a URI, then
- as a local file name. URIs with a 'file' protocol are converted to
- local file names.
-
- Should be used inside with-open to ensure the TestWriter is properly
- closed."
- {:added "1.2"}
- [x & opts]
- (make-text-writer x (when opts (apply hash-map opts))))
-
-(defn ^Stream input-stream
- "Attempts to coerce its argument into an open System.IO.Stream
- in input mode.
-
- Default implementations are defined for Stream, FileInfo, Uri,
- Socket, byte array, char array, and String arguments.
-
- If the argument is a String, it tries to resolve it first as a URI, then
- as a local file name. URIs with a 'file' protocol are converted to
- local file names.
-
- Should be used inside with-open to ensure the Stream is properly
- closed."
- {:added "1.2"}
- [x & opts]
- (make-input-stream x (when opts (apply hash-map opts))))
-
-(defn ^Stream output-stream
- "Attempts to coerce its argument into an open System.IO.Stream.
-
- Default implementations are defined for Stream, FileInfo, URI,
- Socket, and String arguments.
-
- If the argument is a String, it tries to resolve it first as a URI, then
- as a local file name. URIs with a 'file' protocol are converted to
- local file names.
-
- Should be used inside with-open to ensure the OutputStream is
- properly closed."
- {:added "1.2"}
- [x & opts]
- (make-output-stream x (when opts (apply hash-map opts))))
-
-
-(defn ^BinaryReader binary-reader
- "Attempt to coerce its argument into an open System.IO.BinaryReader.
-
- Default implementations are defined for Stream, FileInfo, URI, Socket,
- byte array, and String arguments.
-
- If the argument is a String, it tries to resolve it first as a URI, then
- as a local file name. URIs with a 'file' protocol are converted to
- local file names.
-
- Should be used inside with-open to ensure the BinaryReader is
- properly closed."
- {:added "1.2"}
- [x & opts]
- (make-binary-reader x (when opts (apply hash-map opts))))
-
-(defn ^BinaryWriter binary-writer
- "Attempt to coerce its argument into an open System.IO.BinaryWriter.
-
- Default implementations are defined for Stream, FileInfo, URI, Socket,
- and String arguments.
-
- If the argument is a String, it tries to resolve it first as a URI, then
- as a local file name. URIs with a 'file' protocol are converted to
- local file names.
-
- Should be used inside with-open to ensure the BinaryWriter is
- properly closed."
- {:added "1.2"}
- [x & opts]
- (make-binary-writer x (when opts (apply hash-map opts))))
-
-(def string->encoding
- { "UTF-8" (UTF8Encoding.)
- "UTF-16" (UnicodeEncoding.)
- "UTF-32" (UTF32Encoding.)
- "UTF-7" (UTF7Encoding.)
- "ascii" (ASCIIEncoding.)
- "ASCII" (ASCIIEncoding.)
- "us-ascii" (ASCIIEncoding.)
- :utf8 (UTF8Encoding.)
- :utf16 (UnicodeEncoding.)
- :utf32 (UTF32Encoding.)
- :utf7 (UTF7Encoding.)
- :ascii (ASCIIEncoding.)
- :utf-8 (UTF8Encoding.)
- :utf-16 (UnicodeEncoding.)
- :utf-32 (UTF32Encoding.)
- :utf-7 (UTF7Encoding.)
- })
-
-(defn- normalize-encoding [key]
- (if (string? key)
- (get string->encoding key)
- key))
-
-(defn- ^Encoding encoding [opts]
- (or (normalize-encoding (:encoding opts)) (get string->encoding "UTF-8")))
-
-(defn- buffer-size [opts]
- (or (:buffer-size opts) 1024))
-
-(defn- ^FileMode file-mode [mode opts]
- (or (:file-mode opts)
- (if (= mode :read)
- FileMode/Open
- FileMode/OpenOrCreate)))
-
-(defn- ^FileShare file-share [opts]
- (or (:file-share opts) FileShare/None))
-
-(defn- ^FileAccess file-access [mode opts]
- (or (:file-access opts)
- (if (= mode :read)
- FileAccess/Read
- FileAccess/Write)))
-
-(defn- ^FileOptions file-options [opts]
- (or (:file-options opts) FileOptions/None))
-
-
-(def default-streams-impl
- {:make-text-reader (fn [x opts] (make-text-reader (make-input-stream x opts) opts))
- :make-text-writer (fn [x opts] (make-text-writer (make-output-stream x opts) opts))
- :make-binary-reader (fn [x opts] (make-binary-reader (make-input-stream x opts) opts))
- :make-binary-writer (fn [x opts] (make-binary-writer (make-output-stream x opts) opts))
- :make-input-stream (fn [x opts]
- (throw (ArgumentException.
- (str "Cannot open <" (pr-str x) "> as an input Stream."))))
- :make-output-stream (fn [x opts]
- (throw (ArgumentException.
- (str "Cannot open <" (pr-str x) "> as an output Stream."))))})
-
-(extend Stream
- IOFactory
- (assoc default-streams-impl
- :make-text-reader (fn [^Stream x opts] (StreamReader. x (encoding opts)))
- :make-text-writer (fn [^Stream x opts] (StreamWriter. x (encoding opts)))
- :make-binary-reader (fn [^Stream x opts] (BinaryReader. x (encoding opts)))
- :make-binary-writer (fn [^Stream x opts] (BinaryWriter. x (encoding opts)))
- :make-input-stream (fn [^Stream x opts] (if (.CanRead x) x (throw (ArgumentException. "Cannot convert non-reading stream to input stream"))))
- :make-output-stream (fn [^Stream x opts] (if (.CanWrite x) x (throw (ArgumentException. "Cannot convert non-reading stream to input stream"))))))
-
-(extend BinaryReader
- IOFactory
- (assoc default-streams-impl
- :make-binary-reader (fn [x opts] x)
- :make-input-stream (fn [^BinaryReader x opts] (.BaseStream x))
- :make-output-stream (fn [^BinaryReader x opts] (make-output-stream (.BaseStream x) opts))))
-
-(extend BinaryWriter
- IOFactory
- (assoc default-streams-impl
- :make-binary-writer (fn [x opts] x)
- :make-input-stream (fn [^BinaryWriter x opts] (make-input-stream (.BaseStream x) opts))
- :make-output-stream (fn [^BinaryWriter x opts] (.BaseStream x))))
-
-(extend StreamReader
- IOFactory
- (assoc default-streams-impl
- :make-text-reader (fn [x opts] x)
- :make-input-stream (fn [^StreamReader x opts] (.BaseStream x))
- :make-output-stream (fn [^StreamReader x opts] (make-output-stream (.BaseStream x) opts))))
-
-(extend StreamWriter
- IOFactory
- (assoc default-streams-impl
- :make-text-writer (fn [x opts] x)
- :make-input-stream (fn [^StreamWriter x opts] (make-input-stream (.BaseStream x) opts))
- :make-output-stream (fn [^StreamWriter x opts] (.BaseStream x))))
-
-(extend StringReader
- IOFactory
- (assoc default-streams-impl
- :make-text-reader (fn [x opts] x)))
-
-(extend StringWriter
- IOFactory
- (assoc default-streams-impl
- :make-text-writer (fn [x opts] x)))
-
-(extend FileInfo
- IOFactory
- (assoc default-streams-impl
- :make-input-stream (fn [^FileInfo x opts]
- (make-input-stream
- (FileStream. (.FullName x)
- (file-mode :read opts)
- (file-access :read opts)
- (file-share opts)
- (buffer-size opts)
- (file-options opts))
- opts))
- :make-output-stream (fn [^FileInfo x opts]
- (make-output-stream
- (FileStream. (.FullName x)
- (file-mode :write opts)
- (file-access :write opts)
- (file-share opts)
- (buffer-size opts)
- (file-options opts))
- opts))))
-
-(extend String
- IOFactory
- (assoc default-streams-impl
- :make-input-stream (fn [^String x opts]
- (try
- (make-input-stream (Uri. x) opts)
- (catch UriFormatException err
- (make-input-stream (FileInfo. x) opts))))
- :make-output-stream (fn [^String x opts]
- (try
- (make-output-stream (Uri. x) opts)
- (catch UriFormatException err
- (make-output-stream (FileInfo. x) opts))))))
-(extend Socket
- IOFactory
- (assoc default-streams-impl
- :make-input-stream (fn [^Socket x opts] (NetworkStream. x (file-access :read opts)))
- :make-output-stream (fn [^Socket x opts] (NetworkStream. x (file-access :write opts)))))
-
-
-(extend Uri
- IOFactory
- (assoc default-streams-impl
- :make-input-stream (fn [^Uri x opts]
- (if (.IsFile x)
- (make-input-stream (FileInfo. (.LocalPath x)) opts)
- (.OpenRead (System.Net.WebClient.) x)))
- :make-output-stream (fn [^Uri x opts]
- (if (.IsFile x)
- (make-output-stream (FileInfo. (.LocalPath x)) opts)
- (.OpenWrite (System.Net.WebClient.) x)))))
-
-
-(extend |System.Byte[]|
- IOFactory
- (assoc default-streams-impl
- :make-input-stream (fn [^|System.Byte[]| x opts] (MemoryStream. x))))
-
-(extend Object
- IOFactory
- default-streams-impl)
-
-(extend nil
- IOFactory
- (assoc default-streams-impl
- :make-text-reader (fn [x opts]
- (throw (ArgumentException.
- (str "Cannot open <" (pr-str x) "> as a Reader."))))
- :make-text-writer (fn [x opts]
- (throw (ArgumentException.
- (str "Cannot open <" (pr-str x) "> as a Writer."))))))
-
-
-(defmulti
- ^{:doc "Internal helper for copy"
- :private true
- :arglists '([input output opts])}
- do-copy
- (fn [input output opts] [(type input) (type output)]))
-
-(defmethod do-copy [Stream Stream] [^Stream input ^Stream output opts]
- (let [ len (buffer-size opts)
- ^bytes buffer (make-array Byte len)]
- (loop []
- (let [size (.Read input buffer 0 len)]
- (when (pos? size)
- (do (.Write output buffer 0 size)
- (recur)))))))
-
-(defmethod do-copy [Stream TextWriter] [^Stream input ^TextWriter output opts]
- (let [ len (buffer-size opts)
- ^bytes buffer (make-array Byte len)
- ^Decoder decoder (.GetDecoder (encoding opts)) ]
- (loop []
- (let [size (.Read input buffer 0 len)]
- (when (pos? size)
- (let [ cnt (.GetCharCount decoder buffer 0 size)
- chbuf (make-array Char cnt)]
- (do (.GetChars decoder buffer 0 size chbuf 0)
- (.Write output chbuf 0 cnt)
- (recur))))))))
-
-(defmethod do-copy [Stream FileInfo] [^Stream input ^FileInfo output opts]
- (with-open [out (make-output-stream output opts)]
- (do-copy input out opts)))
-
-(defmethod do-copy [TextReader Stream] [^TextReader input ^Stream output opts]
- (let [ len (buffer-size opts)
- ^chars buffer (make-array Char len)
- ^Encoder encoder (.GetEncoder (encoding opts))]
- (loop []
- (let [size (.Read input buffer 0 len)]
- (when (pos? size)
- (let [cnt (.GetByteCount encoder buffer 0 size false)
- bytes (make-array Byte cnt)]
- (do (.GetBytes encoder buffer 0 size bytes 0 false)
- (.Write output bytes 0 cnt)
- (recur))))))))
-
-(defmethod do-copy [TextReader TextWriter] [^TextReader input ^TextWriter output opts]
- (let [ len (buffer-size opts)
- ^chars buffer (make-array Char len)]
- (loop []
- (let [size (.Read input buffer 0 len)]
- (when (pos? size)
- (do (.Write output buffer 0 size)
- (recur)))))))
-
-(defmethod do-copy [TextReader FileInfo] [^TextReader input ^FileInfo output opts]
- (with-open [out (make-output-stream output opts)]
- (do-copy input out opts)))
-
-(defmethod do-copy [FileInfo Stream] [^FileInfo input ^Stream output opts]
- (with-open [in (make-input-stream input opts)]
- (do-copy in output opts)))
-
-(defmethod do-copy [FileInfo TextWriter] [^FileInfo input ^TextWriter output opts]
- (with-open [in (make-input-stream input opts)]
- (do-copy in output opts)))
-
-(defmethod do-copy [FileInfo FileInfo] [^FileInfo input ^FileInfo output opts]
- (with-open [in (make-input-stream input opts)
- out (make-output-stream output opts)]
- (do-copy in out opts)))
-
-(defmethod do-copy [String Stream] [^String input ^Stream output opts]
- (do-copy (StringReader. input) output opts))
-
-(defmethod do-copy [String TextWriter] [^String input ^TextWriter output opts]
- (do-copy (StringReader. input) output opts))
-
-(defmethod do-copy [String FileInfo] [^String input ^FileInfo output opts]
- (do-copy (StringReader. input) output opts))
-
-(defmethod do-copy [|System.Byte[]| Stream] [^bytes input ^Stream output opts]
- (do-copy (MemoryStream. input) output opts))
-
-(defmethod do-copy [|System.Byte[]| TextWriter] [^bytes input ^TextWriter output opts]
- (do-copy (MemoryStream. input) output opts))
-
-(defmethod do-copy [|System.Byte[]| FileInfo] [^bytes input ^FileInfo output opts]
- (do-copy (MemoryStream. input) output opts))
-
-(defn copy
- "Copies input to output. Returns nil or throws IOException.
- Input may be an InputStream, Reader, File, byte[], or String.
- Output may be an OutputStream, Writer, or File.
-
- Options are key/value pairs and may be one of
-
- :buffer-size buffer size to use, default is 1024.
- :encoding encoding to use if converting between
- byte and char streams.
-
- Does not close any streams except those it opens itself
- (on a File)."
- {:added "1.2"}
- [input output & opts]
- (do-copy input output (when opts (apply hash-map opts))))
+; Copyright (c) Rich Hickey. All rights reserved.
+; The use and distribution terms for this software are covered by the
+; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+; which can be found in the file epl-v10.html at the root of this distribution.
+; By using this software in any fashion, you are agreeing to be bound by
+; the terms of this license.
+; You must not remove this notice, or any other, from this software.
+
+(ns
+ ^{:author "David Miller",
+ :doc "Shamelessly based on the clojure.java.io package authored by Stuart Sierra, Chas Emerick, Stuart Halloway.
+ This file defines polymorphic I/O utility functions for Clojure."}
+ clojure.clr.io
+ (:import
+ (System.IO
+ Stream BufferedStream
+ FileInfo FileStream MemoryStream
+ FileMode FileShare FileAccess FileOptions
+ BinaryReader BinaryWriter
+ StreamReader StreamWriter
+ StringReader StringWriter
+ TextReader TextWriter)
+ (System.Net.Sockets
+ Socket NetworkStream)
+ (System.Text
+ Encoding UTF8Encoding UnicodeEncoding UTF32Encoding UTF7Encoding ASCIIEncoding Decoder Encoder)
+ (System
+ Uri UriFormatException)))
+
+
+(defprotocol ^{:added "1.2"} Coercions
+ "Coerce between various 'resource-namish' things."
+ (^{:tag System.IO.FileInfo, :added "1.2"} as-file [x] "Coerce argument to a file.")
+ (^{:tag System.Uri, :added "1.2"} as-uri [x] "Coerce argument to a URI."))
+
+(extend-protocol Coercions
+ nil
+ (as-file [_] nil)
+ (as-uri [_] nil)
+
+ String
+ (as-file [s] (FileInfo. s))
+ (as-uri [s] (Uri. s))
+
+ FileInfo
+ (as-file [f] f)
+ (as-uri [f] (Uri. (str "file://" (.FullName f))))
+
+ Uri
+ (as-uri [u] u)
+ (as-file [u]
+ (if (.IsFile u)
+ (as-file (.LocalPath u))
+ (throw (ArgumentException. (str "Not a file: " u))))))
+
+(defprotocol ^{:added "1.2"} IOFactory
+ "Factory functions that create ready-to-use, buffered versions of
+ the various Java I/O stream types, on top of anything that can
+ be unequivocally converted to the requested kind of stream.
+
+ Common options include
+
+ :buffer-size Ths size of buffer to use (default: 1024).
+ :file-share A value from the System.IO.FileShare enumeration.
+ :file-mode A value from the System.IO.FileMode enumeration.
+ :file-access A value from the System.IO.FileAccess enumeration.
+ :file-options A value from the System.IO.FileOptions enumeration.
+ :encoding The encoding to use, either as a string, e.g. \"UTF-8\",
+ a keyword, e.g. :utf-8, or a an System.Text.Encoding instance,
+ e.g., (System.Text.UTF8Encoding.)
+
+ Callers should generally prefer the higher level API provided by
+ reader, writer, input-stream, and output-stream."
+ (^{:added "1.2"} make-text-reader [x opts] "Creates a TextReader. See also IOFactory docs.")
+ (^{:added "1.2"} make-text-writer [x opts] "Creates a TextWriter. See also IOFactory docs.")
+ (^{:added "1.2"} make-input-stream [x opts] "Creates a Stream in input mode. See also IOFactory docs.")
+ (^{:added "1.2"} make-output-stream [x opts] "Creates a Stream in output mode. See also IOFactory docs.")
+ (^{:added "1.2"} make-binary-reader [x opts] "Creates a BinaryReader. See also IOFactory docs.")
+ (^{:added "1.2"} make-binary-writer [x opts] "Creates a BinaryWriter. See also IOFactory docs."))
+
+(defn ^TextReader text-reader
+ "Attempts to coerce its argument into an open System.IO.TextReader.
+
+ Default implementations are provided for Stream, Uri, FileInfo, Socket,
+ byte arrays, and String.
+
+ If argument is a String, it tries to resolve it first as a URI, then
+ as a local file name. URIs with a 'file' protocol are converted to
+ local file names.
+
+ Should be used inside with-open to ensure the TextReader is properly
+ closed."
+ {:added "1.2"}
+ [x & opts]
+ (make-text-reader x (when opts (apply hash-map opts))))
+
+(defn ^TextWriter text-writer
+ "Attempts to coerce its argument into an open System.IO.TextWriter.
+
+ Default implementations are provided for Stream, Uri, FileInfo, Socket,
+ and String.
+
+ If the argument is a String, it tries to resolve it first as a URI, then
+ as a local file name. URIs with a 'file' protocol are converted to
+ local file names.
+
+ Should be used inside with-open to ensure the TestWriter is properly
+ closed."
+ {:added "1.2"}
+ [x & opts]
+ (make-text-writer x (when opts (apply hash-map opts))))
+
+(defn ^Stream input-stream
+ "Attempts to coerce its argument into an open System.IO.Stream
+ in input mode.
+
+ Default implementations are defined for Stream, FileInfo, Uri,
+ Socket, byte array, char array, and String arguments.
+
+ If the argument is a String, it tries to resolve it first as a URI, then
+ as a local file name. URIs with a 'file' protocol are converted to
+ local file names.
+
+ Should be used inside with-open to ensure the Stream is properly
+ closed."
+ {:added "1.2"}
+ [x & opts]
+ (make-input-stream x (when opts (apply hash-map opts))))
+
+(defn ^Stream output-stream
+ "Attempts to coerce its argument into an open System.IO.Stream.
+
+ Default implementations are defined for Stream, FileInfo, URI,
+ Socket, and String arguments.
+
+ If the argument is a String, it tries to resolve it first as a URI, then
+ as a local file name. URIs with a 'file' protocol are converted to
+ local file names.
+
+ Should be used inside with-open to ensure the OutputStream is
+ properly closed."
+ {:added "1.2"}
+ [x & opts]
+ (make-output-stream x (when opts (apply hash-map opts))))
+
+
+(defn ^BinaryReader binary-reader
+ "Attempt to coerce its argument into an open System.IO.BinaryReader.
+
+ Default implementations are defined for Stream, FileInfo, URI, Socket,
+ byte array, and String arguments.
+
+ If the argument is a String, it tries to resolve it first as a URI, then
+ as a local file name. URIs with a 'file' protocol are converted to
+ local file names.
+
+ Should be used inside with-open to ensure the BinaryReader is
+ properly closed."
+ {:added "1.2"}
+ [x & opts]
+ (make-binary-reader x (when opts (apply hash-map opts))))
+
+(defn ^BinaryWriter binary-writer
+ "Attempt to coerce its argument into an open System.IO.BinaryWriter.
+
+ Default implementations are defined for Stream, FileInfo, URI, Socket,
+ and String arguments.
+
+ If the argument is a String, it tries to resolve it first as a URI, then
+ as a local file name. URIs with a 'file' protocol are converted to
+ local file names.
+
+ Should be used inside with-open to ensure the BinaryWriter is
+ properly closed."
+ {:added "1.2"}
+ [x & opts]
+ (make-binary-writer x (when opts (apply hash-map opts))))
+
+(def string->encoding
+ { "UTF-8" (UTF8Encoding.)
+ "UTF-16" (UnicodeEncoding.)
+ "UTF-32" (UTF32Encoding.)
+ "UTF-7" (UTF7Encoding.)
+ "ascii" (ASCIIEncoding.)
+ "ASCII" (ASCIIEncoding.)
+ "us-ascii" (ASCIIEncoding.)
+ :utf8 (UTF8Encoding.)
+ :utf16 (UnicodeEncoding.)
+ :utf32 (UTF32Encoding.)
+ :utf7 (UTF7Encoding.)
+ :ascii (ASCIIEncoding.)
+ :utf-8 (UTF8Encoding.)
+ :utf-16 (UnicodeEncoding.)
+ :utf-32 (UTF32Encoding.)
+ :utf-7 (UTF7Encoding.)
+ })
+
+(defn- normalize-encoding [key]
+ (if (string? key)
+ (get string->encoding key)
+ key))
+
+(defn- ^Encoding encoding [opts]
+ (or (normalize-encoding (:encoding opts)) (get string->encoding "UTF-8")))
+
+(defn- buffer-size [opts]
+ (or (:buffer-size opts) 1024))
+
+(defn- ^FileMode file-mode [mode opts]
+ (or (:file-mode opts)
+ (if (= mode :read)
+ FileMode/Open
+ FileMode/OpenOrCreate)))
+
+(defn- ^FileShare file-share [opts]
+ (or (:file-share opts) FileShare/None))
+
+(defn- ^FileAccess file-access [mode opts]
+ (or (:file-access opts)
+ (if (= mode :read)
+ FileAccess/Read
+ FileAccess/Write)))
+
+(defn- ^FileOptions file-options [opts]
+ (or (:file-options opts) FileOptions/None))
+
+
+(def default-streams-impl
+ {:make-text-reader (fn [x opts] (make-text-reader (make-input-stream x opts) opts))
+ :make-text-writer (fn [x opts] (make-text-writer (make-output-stream x opts) opts))
+ :make-binary-reader (fn [x opts] (make-binary-reader (make-input-stream x opts) opts))
+ :make-binary-writer (fn [x opts] (make-binary-writer (make-output-stream x opts) opts))
+ :make-input-stream (fn [x opts]
+ (throw (ArgumentException.
+ (str "Cannot open <" (pr-str x) "> as an input Stream."))))
+ :make-output-stream (fn [x opts]
+ (throw (ArgumentException.
+ (str "Cannot open <" (pr-str x) "> as an output Stream."))))})
+
+(extend Stream
+ IOFactory
+ (assoc default-streams-impl
+ :make-text-reader (fn [^Stream x opts] (StreamReader. x (encoding opts)))
+ :make-text-writer (fn [^Stream x opts] (StreamWriter. x (encoding opts)))
+ :make-binary-reader (fn [^Stream x opts] (BinaryReader. x (encoding opts)))
+ :make-binary-writer (fn [^Stream x opts] (BinaryWriter. x (encoding opts)))
+ :make-input-stream (fn [^Stream x opts] (if (.CanRead x) x (throw (ArgumentException. "Cannot convert non-reading stream to input stream"))))
+ :make-output-stream (fn [^Stream x opts] (if (.CanWrite x) x (throw (ArgumentException. "Cannot convert non-reading stream to input stream"))))))
+
+(extend BinaryReader
+ IOFactory
+ (assoc default-streams-impl
+ :make-binary-reader (fn [x opts] x)
+ :make-input-stream (fn [^BinaryReader x opts] (.BaseStream x))
+ :make-output-stream (fn [^BinaryReader x opts] (make-output-stream (.BaseStream x) opts))))
+
+(extend BinaryWriter
+ IOFactory
+ (assoc default-streams-impl
+ :make-binary-writer (fn [x opts] x)
+ :make-input-stream (fn [^BinaryWriter x opts] (make-input-stream (.BaseStream x) opts))
+ :make-output-stream (fn [^BinaryWriter x opts] (.BaseStream x))))
+
+(extend StreamReader
+ IOFactory
+ (assoc default-streams-impl
+ :make-text-reader (fn [x opts] x)
+ :make-input-stream (fn [^StreamReader x opts] (.BaseStream x))
+ :make-output-stream (fn [^StreamReader x opts] (make-output-stream (.BaseStream x) opts))))
+
+(extend StreamWriter
+ IOFactory
+ (assoc default-streams-impl
+ :make-text-writer (fn [x opts] x)
+ :make-input-stream (fn [^StreamWriter x opts] (make-input-stream (.BaseStream x) opts))
+ :make-output-stream (fn [^StreamWriter x opts] (.BaseStream x))))
+
+(extend StringReader
+ IOFactory
+ (assoc default-streams-impl
+ :make-text-reader (fn [x opts] x)))
+
+(extend StringWriter
+ IOFactory
+ (assoc default-streams-impl
+ :make-text-writer (fn [x opts] x)))
+
+(extend FileInfo
+ IOFactory
+ (assoc default-streams-impl
+ :make-input-stream (fn [^FileInfo x opts]
+ (make-input-stream
+ (FileStream. (.FullName x)
+ (file-mode :read opts)
+ (file-access :read opts)
+ (file-share opts)
+ (buffer-size opts)
+ (file-options opts))
+ opts))
+ :make-output-stream (fn [^FileInfo x opts]
+ (make-output-stream
+ (FileStream. (.FullName x)
+ (file-mode :write opts)
+ (file-access :write opts)
+ (file-share opts)
+ (buffer-size opts)
+ (file-options opts))
+ opts))))
+
+(extend String
+ IOFactory
+ (assoc default-streams-impl
+ :make-input-stream (fn [^String x opts]
+ (try
+ (make-input-stream (Uri. x) opts)
+ (catch UriFormatException err
+ (make-input-stream (FileInfo. x) opts))))
+ :make-output-stream (fn [^String x opts]
+ (try
+ (make-output-stream (Uri. x) opts)
+ (catch UriFormatException err
+ (make-output-stream (FileInfo. x) opts))))))
+(extend Socket
+ IOFactory
+ (assoc default-streams-impl
+ :make-input-stream (fn [^Socket x opts] (NetworkStream. x (file-access :read opts)))
+ :make-output-stream (fn [^Socket x opts] (NetworkStream. x (file-access :write opts)))))
+
+
+(extend Uri
+ IOFactory
+ (assoc default-streams-impl
+ :make-input-stream (fn [^Uri x opts]
+ (if (.IsFile x)
+ (make-input-stream (FileInfo. (.LocalPath x)) opts)
+ (.OpenRead (System.Net.WebClient.) x)))
+ :make-output-stream (fn [^Uri x opts]
+ (if (.IsFile x)
+ (make-output-stream (FileInfo. (.LocalPath x)) opts)
+ (.OpenWrite (System.Net.WebClient.) x)))))
+
+
+(extend |System.Byte[]|
+ IOFactory
+ (assoc default-streams-impl
+ :make-input-stream (fn [^|System.Byte[]| x opts] (MemoryStream. x))))
+
+(extend Object
+ IOFactory
+ default-streams-impl)
+
+(extend nil
+ IOFactory
+ (assoc default-streams-impl
+ :make-text-reader (fn [x opts]
+ (throw (ArgumentException.
+ (str "Cannot open <" (pr-str x) "> as a Reader."))))
+ :make-text-writer (fn [x opts]
+ (throw (ArgumentException.
+ (str "Cannot open <" (pr-str x) "> as a Writer."))))))
+
+
+(defmulti
+ ^{:doc "Internal helper for copy"
+ :private true
+ :arglists '([input output opts])}
+ do-copy
+ (fn [input output opts] [(type input) (type output)]))
+
+(defmethod do-copy [Stream Stream] [^Stream input ^Stream output opts]
+ (let [ len (buffer-size opts)
+ ^bytes buffer (make-array Byte len)]
+ (loop []
+ (let [size (.Read input buffer 0 len)]
+ (when (pos? size)
+ (do (.Write output buffer 0 size)
+ (recur)))))))
+
+(defmethod do-copy [Stream TextWriter] [^Stream input ^TextWriter output opts]
+ (let [ len (buffer-size opts)
+ ^bytes buffer (make-array Byte len)
+ ^Decoder decoder (.GetDecoder (encoding opts)) ]
+ (loop []
+ (let [size (.Read input buffer 0 len)]
+ (when (pos? size)
+ (let [ cnt (.GetCharCount decoder buffer 0 size)
+ chbuf (make-array Char cnt)]
+ (do (.GetChars decoder buffer 0 size chbuf 0)
+ (.Write output chbuf 0 cnt)
+ (recur))))))))
+
+(defmethod do-copy [Stream FileInfo] [^Stream input ^FileInfo output opts]
+ (with-open [out (make-output-stream output opts)]
+ (do-copy input out opts)))
+
+(defmethod do-copy [TextReader Stream] [^TextReader input ^Stream output opts]
+ (let [ len (buffer-size opts)
+ ^chars buffer (make-array Char len)
+ ^Encoder encoder (.GetEncoder (encoding opts))]
+ (loop []
+ (let [size (.Read input buffer 0 len)]
+ (when (pos? size)
+ (let [cnt (.GetByteCount encoder buffer 0 size false)
+ bytes (make-array Byte cnt)]
+ (do (.GetBytes encoder buffer 0 size bytes 0 false)
+ (.Write output bytes 0 cnt)
+ (recur))))))))
+
+(defmethod do-copy [TextReader TextWriter] [^TextReader input ^TextWriter output opts]
+ (let [ len (buffer-size opts)
+ ^chars buffer (make-array Char len)]
+ (loop []
+ (let [size (.Read input buffer 0 len)]
+ (when (pos? size)
+ (do (.Write output buffer 0 size)
+ (recur)))))))
+
+(defmethod do-copy [TextReader FileInfo] [^TextReader input ^FileInfo output opts]
+ (with-open [out (make-output-stream output opts)]
+ (do-copy input out opts)))
+
+(defmethod do-copy [FileInfo Stream] [^FileInfo input ^Stream output opts]
+ (with-open [in (make-input-stream input opts)]
+ (do-copy in output opts)))
+
+(defmethod do-copy [FileInfo TextWriter] [^FileInfo input ^TextWriter output opts]
+ (with-open [in (make-input-stream input opts)]
+ (do-copy in output opts)))
+
+(defmethod do-copy [FileInfo FileInfo] [^FileInfo input ^FileInfo output opts]
+ (with-open [in (make-input-stream input opts)
+ out (make-output-stream output opts)]
+ (do-copy in out opts)))
+
+(defmethod do-copy [String Stream] [^String input ^Stream output opts]
+ (do-copy (StringReader. input) output opts))
+
+(defmethod do-copy [String TextWriter] [^String input ^TextWriter output opts]
+ (do-copy (StringReader. input) output opts))
+
+(defmethod do-copy [String FileInfo] [^String input ^FileInfo output opts]
+ (do-copy (StringReader. input) output opts))
+
+(defmethod do-copy [|System.Byte[]| Stream] [^bytes input ^Stream output opts]
+ (do-copy (MemoryStream. input) output opts))
+
+(defmethod do-copy [|System.Byte[]| TextWriter] [^bytes input ^TextWriter output opts]
+ (do-copy (MemoryStream. input) output opts))
+
+(defmethod do-copy [|System.Byte[]| FileInfo] [^bytes input ^FileInfo output opts]
+ (do-copy (MemoryStream. input) output opts))
+
+(defn copy
+ "Copies input to output. Returns nil or throws IOException.
+ Input may be an InputStream, Reader, File, byte[], or String.
+ Output may be an OutputStream, Writer, or File.
+
+ Options are key/value pairs and may be one of
+
+ :buffer-size buffer size to use, default is 1024.
+ :encoding encoding to use if converting between
+ byte and char streams.
+
+ Does not close any streams except those it opens itself
+ (on a File)."
+ {:added "1.2"}
+ [input output & opts]
+ (do-copy input output (when opts (apply hash-map opts))))
diff --git a/Clojure/Clojure.Source/clojure/core.clj b/Clojure/Clojure.Source/clojure/core.clj
index 5eecd09d8..6bb4bac63 100644
--- a/Clojure/Clojure.Source/clojure/core.clj
+++ b/Clojure/Clojure.Source/clojure/core.clj
@@ -1,1851 +1,1851 @@
-; Copyright (c) Rich Hickey. All rights reserved.
-; The use and distribution terms for this software are covered by the
-; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
-; which can be found in the file epl-v10.html at the root of this distribution.
-; By using this software in any fashion, you are agreeing to be bound by
-; the terms of this license.
-; You must not remove this notice, or any other, from this software.
-
-(ns ^{:doc "The core Clojure language."
- :author "Rich Hickey"}
- clojure.core)
-
-(def unquote)
-(def unquote-splicing)
-
-(def
- ^{:arglists '([& items])
- :doc "Creates a new list containing the items."
- :added "1.0"}
- list (. clojure.lang.PersistentList creator))
-
-(def
- ^{:arglists '([x seq])
- :doc "Returns a new seq where x is the first element and seq is
- the rest."
- :added "1.0"
- :static true}
-
- cons (fn* ^:static cons [x seq] (. clojure.lang.RT (cons x seq))))
-
- ;during bootstrap we don't have destructuring let, loop or fn, will redefine later
-(def
- ^{:macro true :redef true
- :added "1.0"}
- let (fn* let [&form &env & decl] (cons 'let* decl)))
-
-(def
- ^{:macro true :redef true
- :added "1.0"}
- loop (fn* loop [&form &env & decl] (cons 'loop* decl)))
-
- (def
- ^{:macro true :redef true
- :added "1.0"}
- fn (fn* fn [&form &env & decl]
- (.withMeta ^clojure.lang.IObj (cons 'fn* decl)
- (.meta ^clojure.lang.IMeta &form))))
-
-(def
- ^{:arglists '([coll])
- :doc "Returns the first item in the collection. Calls seq on its
- argument. If coll is nil, returns nil."
- :added "1.0"
- :static true}
- first (fn ^:static first [coll] (. clojure.lang.RT (first coll))))
-
-(def
- ^{:arglists '([coll])
- :tag clojure.lang.ISeq
- :doc "Returns a seq of the items after the first. Calls seq on its
- argument. If there are no more items, returns nil."
- :added "1.0"
- :static true}
- next (fn ^:static next [x] (. clojure.lang.RT (next x))))
-
-(def
- ^{:arglists '([coll])
- :tag clojure.lang.ISeq
- :doc "Returns a possibly empty seq of the items after the first. Calls seq on its
- argument."
- :added "1.0"
- :static true}
- rest (fn ^:static rest [x] (. clojure.lang.RT (more x))))
-
-(def
- ^{:arglists '([] [coll] [coll x] [coll x & xs])
- :doc "conj[oin]. Returns a new collection with the xs
- 'added'. (conj nil item) returns (item).
- (conj coll) returns coll. (conj) returns [].
- The 'addition' may happen at different 'places' depending
- on the concrete type."
- :added "1.0"
- :static true}
- conj (fn ^:static conj
- ([] [])
- ([coll] coll)
- ([coll x] (clojure.lang.RT/conj coll x))
- ([coll x & xs]
- (if xs
- (recur (clojure.lang.RT/conj coll x) (first xs) (next xs))
- (clojure.lang.RT/conj coll x)))))
-
-(def
- ^{:doc "Same as (first (next x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- second (fn ^:static second [x] (first (next x))))
-
-(def
- ^{:doc "Same as (first (first x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- ffirst (fn ^:static ffirst [x] (first (first x))))
-
-(def
- ^{:doc "Same as (next(first x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- nfirst (fn ^:static nfirst [x] (next (first x))))
-
-(def
- ^{:doc "Same as (first (next x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- fnext (fn ^:static fnext [x] (first (next x))))
-
-(def
- ^{:doc "Same as (next (next x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- nnext (fn ^:static nnext [x] (next (next x))))
-
-(def
- ^{:arglists '(^clojure.lang.ISeq [coll])
- :doc "Returns a seq on the collection. If the collection is
- empty, returns nil. (seq nil) returns nil. seq also works on
- Strings, native Java arrays (of reference types) and any objects
- that implement Iterable. Note that seqs cache values, thus seq
- should not be used on any Iterable whose iterator repeatedly
- returns the same mutable object."
- :tag clojure.lang.ISeq
- :added "1.0"
- :static true}
- seq (fn ^:static seq [coll] (. clojure.lang.RT (seq coll))))
-
-(def
- ^{:arglists '([^Type c x]) ;;; Class
- :doc "Evaluates x and tests if it is an instance of the class
- c. Returns true or false"
- :added "1.0"}
- instance? (fn instance? [^Type c x] (. c (IsInstanceOfType x)))) ;;; Class isInstanceOfTYpe
-
-(def
- ^{:arglists '([x])
- :doc "Return true if x implements ISeq"
- :added "1.0"
- :static true}
- seq? (fn ^:static seq? [x] (instance? clojure.lang.ISeq x)))
-
-(def
- ^{:arglists '([x])
- :doc "Return true if x is a Character"
- :added "1.0"
- :static true}
- char? (fn ^:static char? [x] (instance? Char x))) ;;; Character
-
-(def
- ^{:arglists '([x])
- :doc "Return true if x is a String"
- :added "1.0"
- :static true}
- string? (fn ^:static string? [x] (instance? String x)))
-
-(def
- ^{:arglists '([x])
- :doc "Return true if x implements IPersistentMap"
- :added "1.0"
- :static true}
- map? (fn ^:static map? [x] (instance? clojure.lang.IPersistentMap x)))
-
-(def
- ^{:arglists '([x])
- :doc "Return true if x implements IPersistentVector "
- :added "1.0"
- :static true}
- vector? (fn ^:static vector? [x] (instance? clojure.lang.IPersistentVector x)))
-
-(def
- ^{:arglists '([map key val] [map key val & kvs])
- :doc "assoc[iate]. When applied to a map, returns a new map of the
- same (hashed/sorted) type, that contains the mapping of key(s) to
- val(s). When applied to a vector, returns a new vector that
- contains val at index. Note - index must be <= (count vector)."
- :added "1.0"
- :static true}
- assoc
- (fn ^:static assoc
- ([map key val] (clojure.lang.RT/assoc map key val))
- ([map key val & kvs]
- (let [ret (clojure.lang.RT/assoc map key val)]
- (if kvs
- (if (next kvs)
- (recur ret (first kvs) (second kvs) (nnext kvs))
- (throw (ArgumentException. ;;; IllegalArgumentException
- "assoc expects even number of arguments after map/vector, found odd number")))
- ret)))))
-
-;;;;;;;;;;;;;;;;; metadata ;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(def
- ^{:arglists '([obj])
- :doc "Returns the metadata of obj, returns nil if there is no metadata."
- :added "1.0"
- :static true}
- meta (fn ^:static meta [x]
- (if (instance? clojure.lang.IMeta x)
- (. ^clojure.lang.IMeta x (meta)))))
-
-(def
- ^{:arglists '([^clojure.lang.IObj obj m])
- :doc "Returns an object of the same type and value as obj, with
- map m as its metadata."
- :added "1.0"
- :static true}
- with-meta (fn ^:static with-meta [^clojure.lang.IObj x m]
- (. x (withMeta m))))
-
-(def ^{:private true :dynamic true}
- assert-valid-fdecl (fn [fdecl]))
-
-(def
- ^{:private true}
- sigs
- (fn [fdecl]
- (assert-valid-fdecl fdecl)
- (let [asig
- (fn [fdecl]
- (let [arglist (first fdecl)
- ;elide implicit macro args
- arglist (if (clojure.lang.Util/equals '&form (first arglist))
- (clojure.lang.RT/subvec arglist 2 (clojure.lang.RT/count arglist))
- arglist)
- body (next fdecl)]
- (if (map? (first body))
- (if (next body)
- (with-meta arglist (conj (if (meta arglist) (meta arglist) {}) (first body)))
- arglist)
- arglist)))
- resolve-tag (fn [argvec]
- (let [m (meta argvec)
- ^clojure.lang.Symbol tag (:tag m)]
- (if (instance? clojure.lang.Symbol tag)
- (if (clojure.lang.Util/equiv (.IndexOf (.Name tag) ".") -1) ;;; .indexOf .getName
- (if (clojure.lang.Util/equals nil (clojure.lang.CljCompiler.Ast.HostExpr/maybeSpecialTag tag)) ;;; clojure.lang.Compiler$HostExpr
- (let [c (clojure.lang.CljCompiler.Ast.HostExpr/MaybeType tag false)] ;;; clojure.lang.Compiler$HostExpr maybeClass
- (if c
- (with-meta argvec (assoc m :tag (clojure.lang.Symbol/intern (.Name c)))) ;;; .getName
- argvec))
- argvec)
- argvec)
- argvec)))]
- (if (seq? (first fdecl))
- (loop [ret [] fdecls fdecl]
- (if fdecls
- (recur (conj ret (resolve-tag (asig (first fdecls)))) (next fdecls))
- (seq ret)))
- (list (resolve-tag (asig fdecl)))))))
-
-
-(def
- ^{:arglists '([coll])
- :doc "Return the last item in coll, in linear time"
- :added "1.0"
- :static true}
- last (fn ^:static last [s]
- (if (next s)
- (recur (next s))
- (first s))))
-
-(def
- ^{:arglists '([coll])
- :doc "Return a seq of all but the last item in coll, in linear time"
- :added "1.0"
- :static true}
- butlast (fn ^:static butlast [s]
- (loop [ret [] s s]
- (if (next s)
- (recur (conj ret (first s)) (next s))
- (seq ret)))))
-
-(def
-
- ^{:doc "Same as (def name (fn [params* ] exprs*)) or (def
- name (fn ([params* ] exprs*)+)) with any doc-string or attrs added
- to the var metadata. prepost-map defines a map with optional keys
- :pre and :post that contain collections of pre or post conditions."
- :arglists '([name doc-string? attr-map? [params*] prepost-map? body]
- [name doc-string? attr-map? ([params*] prepost-map? body)+ attr-map?]) :dynamic true ;;; ADDED :dynamic true -- eventually replace with :redef
- :added "1.0"}
- defn (fn defn [&form &env name & fdecl]
- ;; Note: Cannot delegate this check to def because of the call to (with-meta name ..)
- (if (instance? clojure.lang.Symbol name)
- nil
- (throw (ArgumentException. "First argument to defn must be a symbol"))) ;;; IllegalArgumentException
- (let [m (if (string? (first fdecl))
- {:doc (first fdecl)}
- {})
- fdecl (if (string? (first fdecl))
- (next fdecl)
- fdecl)
- m (if (map? (first fdecl))
- (conj m (first fdecl))
- m)
- fdecl (if (map? (first fdecl))
- (next fdecl)
- fdecl)
- fdecl (if (vector? (first fdecl))
- (list fdecl)
- fdecl)
- m (if (map? (last fdecl))
- (conj m (last fdecl))
- m)
- fdecl (if (map? (last fdecl))
- (butlast fdecl)
- fdecl)
- m (conj {:arglists (list 'quote (sigs fdecl))} m)
- m (let [inline (:inline m)
- ifn (first inline)
- iname (second inline)]
- ;; same as: (if (and (= 'fn ifn) (not (symbol? iname))) ...)
- (if (if (clojure.lang.Util/equiv 'fn ifn)
- (if (instance? clojure.lang.Symbol iname) false true))
- ;; inserts the same fn name to the inline fn if it does not have one
- (assoc m :inline (cons ifn (cons (clojure.lang.Symbol/intern (String/Concat (.Name ^clojure.lang.Symbol name) "__inliner")) ;;; .concat .getName
- (next inline))))
- m))
- m (conj (if (meta name) (meta name) {}) m)]
- (list 'def (with-meta name m)
- ;;todo - restore propagation of fn name
- ;;must figure out how to convey primitive hints to self calls first
- ;;(cons `fn fdecl)
- (with-meta (cons `fn fdecl) {:rettag (:tag m)})))))
-
-(. (var defn) (setMacro))
-
-(defn to-array
- "Returns an array of Objects containing the contents of coll, which
- can be any Collection. Maps to java.util.Collection.toArray()."
- {:tag "System.Object[]" ;;;{:tag "[Ljava.lang.Object;"}
- :added "1.0"
- :static true}
- [coll] (. clojure.lang.RT (toArray coll)))
-;;; Not the same as the Java version, but good enough?
-(defn cast
- "Throws a ClassCastException if x is not a c, else returns x."
- {:added "1.0"
- :static true}
- [^Type c x] ;;; changed Class to Type
- (if (clojure.lang.Util/identical x nil) nil (if (. c (IsInstanceOfType x)) x (throw (InvalidCastException. (.ToString (.GetType x))))))) ;;; original (. c (cast x)))
-
-(defn vector
- "Creates a new vector containing the args."
- {:added "1.0"
- :static true}
- ([] [])
- ([a] [a])
- ([a b] [a b])
- ([a b c] [a b c])
- ([a b c d] [a b c d])
- ([a b c d e] [a b c d e])
- ([a b c d e f] [a b c d e f])
- ([a b c d e f & args]
- (. clojure.lang.LazilyPersistentVector (create (cons a (cons b (cons c (cons d (cons e (cons f args))))))))))
-
-(defn vec
- "Creates a new vector containing the contents of coll. Java arrays
- will be aliased and should not be modified."
- {:added "1.0"
- :static true}
- ([coll]
- (if (vector? coll)
- (if (instance? clojure.lang.IObj coll)
- (with-meta coll nil)
- (clojure.lang.LazilyPersistentVector/create coll))
- (clojure.lang.LazilyPersistentVector/create coll))))
-
-(defn hash-map
- "keyval => key val
- Returns a new hash map with supplied mappings. If any keys are
- equal, they are handled as if by repeated uses of assoc."
- {:added "1.0"
- :static true}
- ([] {})
- ([& keyvals]
- (. clojure.lang.PersistentHashMap (create keyvals))))
-
-(defn hash-set
- "Returns a new hash set with supplied keys. Any equal keys are
- handled as if by repeated uses of conj."
- {:added "1.0"
- :static true}
- ([] #{})
- ([& keys]
- (clojure.lang.PersistentHashSet/create keys)))
-
-(defn sorted-map
- "keyval => key val
- Returns a new sorted map with supplied mappings. If any keys are
- equal, they are handled as if by repeated uses of assoc."
- {:added "1.0"
- :static true}
- ([] clojure.lang.PersistentTreeMap/EMPTY) ;;; I HAD TO ADD THIS EXTRA CASE TO AVOID AMBIGUOUS CALL TO CREATE WITH NULL
- ([& keyvals] (. clojure.lang.PersistentTreeMap (create keyvals))))
-
-(defn sorted-map-by
- "keyval => key val
- Returns a new sorted map with supplied mappings, using the supplied
- comparator. If any keys are equal, they are handled as if by
- repeated uses of assoc."
- {:added "1.0"
- :static true}
- ([comparator & keyvals]
- (clojure.lang.PersistentTreeMap/create comparator keyvals)))
-
-(defn sorted-set
- "Returns a new sorted set with supplied keys. Any equal keys are
- handled as if by repeated uses of conj."
- {:added "1.0"
- :static true}
- ([] clojure.lang.PersistentTreeSet/EMPTY) ;;; I HAD TO ADD THIS EXTRA CASE TO AVOID AMBIGUOUS CALL TO CREATE WITH NULL
- ([& keys] (clojure.lang.PersistentTreeSet/create keys)))
-
-(defn sorted-set-by
- "Returns a new sorted set with supplied keys, using the supplied
- comparator. Any equal keys are handled as if by repeated uses of
- conj."
- {:added "1.1"
- :static true}
- ([comparator & keys]
- (clojure.lang.PersistentTreeSet/create comparator keys)))
-
-
-;;;;;;;;;;;;;;;;;;;;
-(defn nil?
- "Returns true if x is nil, false otherwise."
- {:tag Boolean
- :added "1.0"
- :static true
- :inline (fn [x] (list 'clojure.lang.Util/identical x nil))}
- [x] (clojure.lang.Util/identical x nil))
-
-(def
-
- ^{:doc "Like defn, but the resulting function name is declared as a
- macro and will be used as a macro by the compiler when it is
- called."
- :arglists '([name doc-string? attr-map? [params*] body]
- [name doc-string? attr-map? ([params*] body)+ attr-map?])
- :added "1.0"}
- defmacro (fn [&form &env
- name & args]
- (let [prefix (loop [p (list name) args args]
- (let [f (first args)]
- (if (string? f)
- (recur (cons f p) (next args))
- (if (map? f)
- (recur (cons f p) (next args))
- p))))
- fdecl (loop [fd args]
- (if (string? (first fd))
- (recur (next fd))
- (if (map? (first fd))
- (recur (next fd))
- fd)))
- fdecl (if (vector? (first fdecl))
- (list fdecl)
- fdecl)
- add-implicit-args (fn [fd]
- (let [args (first fd)]
- (cons (vec (cons '&form (cons '&env args))) (next fd))))
- add-args (fn [acc ds]
- (if (nil? ds)
- acc
- (let [d (first ds)]
- (if (map? d)
- (conj acc d)
- (recur (conj acc (add-implicit-args d)) (next ds))))))
- fdecl (seq (add-args [] fdecl))
- decl (loop [p prefix d fdecl]
- (if p
- (recur (next p) (cons (first p) d))
- d))]
- (list 'do
- (cons `defn decl)
- (list '. (list 'var name) '(setMacro))
- (list 'var name)))))
-
-
-(. (var defmacro) (setMacro))
-
-(defmacro when
- "Evaluates test. If logical true, evaluates body in an implicit do."
- {:added "1.0"}
- [test & body]
- (list 'if test (cons 'do body)))
-
-(defmacro when-not
- "Evaluates test. If logical false, evaluates body in an implicit do."
- {:added "1.0"}
- [test & body]
- (list 'if test nil (cons 'do body)))
-
-(defn false?
- "Returns true if x is the value false, false otherwise."
- {:tag Boolean
- :added "1.0"
- :static true}
- [x] (clojure.lang.Util/identical x false))
-
-(defn true?
- "Returns true if x is the value true, false otherwise."
- {:tag Boolean
- :added "1.0"
- :static true}
- [x] (clojure.lang.Util/identical x true))
-
-(defn boolean?
- "Return true if x is a Boolean"
- {:added "1.9"}
- [x] (instance? Boolean x))
-
- (defn not
- "Returns true if x is logical false, false otherwise."
- {:tag Boolean
- :added "1.0"
- :static true}
- [x] (if x false true))
-
-(defn some?
- "Returns true if x is not nil, false otherwise."
- {:tag Boolean
- :added "1.6"
- :static true}
- [x] (not (nil? x)))
-
-(defn any?
- "Returns true given any argument."
- {:tag Boolean
- :added "1.9"}
- [x] true)
-
-(defn str
- "With no args, returns the empty string. With one arg x, returns
- x.toString(). (str nil) returns the empty string. With more than
- one arg, returns the concatenation of the str values of the args."
- {:tag String
- :added "1.0"
- :static true}
- (^String [] "")
- (^String [^Object x]
- (if (nil? x) "" (clojure.lang.RT/CultureToString x))) ;;;(if (nil? x) "" (. x (toString)))) ;; java: toString
- (^String [x & ys]
- ((fn [^StringBuilder sb more]
- (if more
- (recur (. sb (Append (str (first more)))) (next more)) ;; java: append
- (str sb)))
- (new StringBuilder (str x)) ys)))
-
-
-(defn symbol?
- "Return true if x is a Symbol"
- {:added "1.0"
- :static true}
- [x] (instance? clojure.lang.Symbol x))
-
-(defn keyword?
- "Return true if x is a Keyword"
- {:added "1.0"
- :static true}
- [x] (instance? clojure.lang.Keyword x))
-
-(defmacro cond
- "Takes a set of test/expr pairs. It evaluates each test one at a
- time. If a test returns logical true, cond evaluates and returns
- the value of the corresponding expr and doesn't evaluate any of the
- other tests or exprs. (cond) returns nil."
- {:added "1.0"}
- [& clauses]
- (when clauses
- (list 'if (first clauses)
+; Copyright (c) Rich Hickey. All rights reserved.
+; The use and distribution terms for this software are covered by the
+; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+; which can be found in the file epl-v10.html at the root of this distribution.
+; By using this software in any fashion, you are agreeing to be bound by
+; the terms of this license.
+; You must not remove this notice, or any other, from this software.
+
+(ns ^{:doc "The core Clojure language."
+ :author "Rich Hickey"}
+ clojure.core)
+
+(def unquote)
+(def unquote-splicing)
+
+(def
+ ^{:arglists '([& items])
+ :doc "Creates a new list containing the items."
+ :added "1.0"}
+ list (. clojure.lang.PersistentList creator))
+
+(def
+ ^{:arglists '([x seq])
+ :doc "Returns a new seq where x is the first element and seq is
+ the rest."
+ :added "1.0"
+ :static true}
+
+ cons (fn* ^:static cons [x seq] (. clojure.lang.RT (cons x seq))))
+
+ ;during bootstrap we don't have destructuring let, loop or fn, will redefine later
+(def
+ ^{:macro true :redef true
+ :added "1.0"}
+ let (fn* let [&form &env & decl] (cons 'let* decl)))
+
+(def
+ ^{:macro true :redef true
+ :added "1.0"}
+ loop (fn* loop [&form &env & decl] (cons 'loop* decl)))
+
+ (def
+ ^{:macro true :redef true
+ :added "1.0"}
+ fn (fn* fn [&form &env & decl]
+ (.withMeta ^clojure.lang.IObj (cons 'fn* decl)
+ (.meta ^clojure.lang.IMeta &form))))
+
+(def
+ ^{:arglists '([coll])
+ :doc "Returns the first item in the collection. Calls seq on its
+ argument. If coll is nil, returns nil."
+ :added "1.0"
+ :static true}
+ first (fn ^:static first [coll] (. clojure.lang.RT (first coll))))
+
+(def
+ ^{:arglists '([coll])
+ :tag clojure.lang.ISeq
+ :doc "Returns a seq of the items after the first. Calls seq on its
+ argument. If there are no more items, returns nil."
+ :added "1.0"
+ :static true}
+ next (fn ^:static next [x] (. clojure.lang.RT (next x))))
+
+(def
+ ^{:arglists '([coll])
+ :tag clojure.lang.ISeq
+ :doc "Returns a possibly empty seq of the items after the first. Calls seq on its
+ argument."
+ :added "1.0"
+ :static true}
+ rest (fn ^:static rest [x] (. clojure.lang.RT (more x))))
+
+(def
+ ^{:arglists '([] [coll] [coll x] [coll x & xs])
+ :doc "conj[oin]. Returns a new collection with the xs
+ 'added'. (conj nil item) returns (item).
+ (conj coll) returns coll. (conj) returns [].
+ The 'addition' may happen at different 'places' depending
+ on the concrete type."
+ :added "1.0"
+ :static true}
+ conj (fn ^:static conj
+ ([] [])
+ ([coll] coll)
+ ([coll x] (clojure.lang.RT/conj coll x))
+ ([coll x & xs]
+ (if xs
+ (recur (clojure.lang.RT/conj coll x) (first xs) (next xs))
+ (clojure.lang.RT/conj coll x)))))
+
+(def
+ ^{:doc "Same as (first (next x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ second (fn ^:static second [x] (first (next x))))
+
+(def
+ ^{:doc "Same as (first (first x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ ffirst (fn ^:static ffirst [x] (first (first x))))
+
+(def
+ ^{:doc "Same as (next(first x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ nfirst (fn ^:static nfirst [x] (next (first x))))
+
+(def
+ ^{:doc "Same as (first (next x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ fnext (fn ^:static fnext [x] (first (next x))))
+
+(def
+ ^{:doc "Same as (next (next x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ nnext (fn ^:static nnext [x] (next (next x))))
+
+(def
+ ^{:arglists '(^clojure.lang.ISeq [coll])
+ :doc "Returns a seq on the collection. If the collection is
+ empty, returns nil. (seq nil) returns nil. seq also works on
+ Strings, native Java arrays (of reference types) and any objects
+ that implement Iterable. Note that seqs cache values, thus seq
+ should not be used on any Iterable whose iterator repeatedly
+ returns the same mutable object."
+ :tag clojure.lang.ISeq
+ :added "1.0"
+ :static true}
+ seq (fn ^:static seq [coll] (. clojure.lang.RT (seq coll))))
+
+(def
+ ^{:arglists '([^Type c x]) ;;; Class
+ :doc "Evaluates x and tests if it is an instance of the class
+ c. Returns true or false"
+ :added "1.0"}
+ instance? (fn instance? [^Type c x] (. c (IsInstanceOfType x)))) ;;; Class isInstanceOfTYpe
+
+(def
+ ^{:arglists '([x])
+ :doc "Return true if x implements ISeq"
+ :added "1.0"
+ :static true}
+ seq? (fn ^:static seq? [x] (instance? clojure.lang.ISeq x)))
+
+(def
+ ^{:arglists '([x])
+ :doc "Return true if x is a Character"
+ :added "1.0"
+ :static true}
+ char? (fn ^:static char? [x] (instance? Char x))) ;;; Character
+
+(def
+ ^{:arglists '([x])
+ :doc "Return true if x is a String"
+ :added "1.0"
+ :static true}
+ string? (fn ^:static string? [x] (instance? String x)))
+
+(def
+ ^{:arglists '([x])
+ :doc "Return true if x implements IPersistentMap"
+ :added "1.0"
+ :static true}
+ map? (fn ^:static map? [x] (instance? clojure.lang.IPersistentMap x)))
+
+(def
+ ^{:arglists '([x])
+ :doc "Return true if x implements IPersistentVector "
+ :added "1.0"
+ :static true}
+ vector? (fn ^:static vector? [x] (instance? clojure.lang.IPersistentVector x)))
+
+(def
+ ^{:arglists '([map key val] [map key val & kvs])
+ :doc "assoc[iate]. When applied to a map, returns a new map of the
+ same (hashed/sorted) type, that contains the mapping of key(s) to
+ val(s). When applied to a vector, returns a new vector that
+ contains val at index. Note - index must be <= (count vector)."
+ :added "1.0"
+ :static true}
+ assoc
+ (fn ^:static assoc
+ ([map key val] (clojure.lang.RT/assoc map key val))
+ ([map key val & kvs]
+ (let [ret (clojure.lang.RT/assoc map key val)]
+ (if kvs
+ (if (next kvs)
+ (recur ret (first kvs) (second kvs) (nnext kvs))
+ (throw (ArgumentException. ;;; IllegalArgumentException
+ "assoc expects even number of arguments after map/vector, found odd number")))
+ ret)))))
+
+;;;;;;;;;;;;;;;;; metadata ;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(def
+ ^{:arglists '([obj])
+ :doc "Returns the metadata of obj, returns nil if there is no metadata."
+ :added "1.0"
+ :static true}
+ meta (fn ^:static meta [x]
+ (if (instance? clojure.lang.IMeta x)
+ (. ^clojure.lang.IMeta x (meta)))))
+
+(def
+ ^{:arglists '([^clojure.lang.IObj obj m])
+ :doc "Returns an object of the same type and value as obj, with
+ map m as its metadata."
+ :added "1.0"
+ :static true}
+ with-meta (fn ^:static with-meta [^clojure.lang.IObj x m]
+ (. x (withMeta m))))
+
+(def ^{:private true :dynamic true}
+ assert-valid-fdecl (fn [fdecl]))
+
+(def
+ ^{:private true}
+ sigs
+ (fn [fdecl]
+ (assert-valid-fdecl fdecl)
+ (let [asig
+ (fn [fdecl]
+ (let [arglist (first fdecl)
+ ;elide implicit macro args
+ arglist (if (clojure.lang.Util/equals '&form (first arglist))
+ (clojure.lang.RT/subvec arglist 2 (clojure.lang.RT/count arglist))
+ arglist)
+ body (next fdecl)]
+ (if (map? (first body))
+ (if (next body)
+ (with-meta arglist (conj (if (meta arglist) (meta arglist) {}) (first body)))
+ arglist)
+ arglist)))
+ resolve-tag (fn [argvec]
+ (let [m (meta argvec)
+ ^clojure.lang.Symbol tag (:tag m)]
+ (if (instance? clojure.lang.Symbol tag)
+ (if (clojure.lang.Util/equiv (.IndexOf (.Name tag) ".") -1) ;;; .indexOf .getName
+ (if (clojure.lang.Util/equals nil (clojure.lang.CljCompiler.Ast.HostExpr/maybeSpecialTag tag)) ;;; clojure.lang.Compiler$HostExpr
+ (let [c (clojure.lang.CljCompiler.Ast.HostExpr/MaybeType tag false)] ;;; clojure.lang.Compiler$HostExpr maybeClass
+ (if c
+ (with-meta argvec (assoc m :tag (clojure.lang.Symbol/intern (.Name c)))) ;;; .getName
+ argvec))
+ argvec)
+ argvec)
+ argvec)))]
+ (if (seq? (first fdecl))
+ (loop [ret [] fdecls fdecl]
+ (if fdecls
+ (recur (conj ret (resolve-tag (asig (first fdecls)))) (next fdecls))
+ (seq ret)))
+ (list (resolve-tag (asig fdecl)))))))
+
+
+(def
+ ^{:arglists '([coll])
+ :doc "Return the last item in coll, in linear time"
+ :added "1.0"
+ :static true}
+ last (fn ^:static last [s]
+ (if (next s)
+ (recur (next s))
+ (first s))))
+
+(def
+ ^{:arglists '([coll])
+ :doc "Return a seq of all but the last item in coll, in linear time"
+ :added "1.0"
+ :static true}
+ butlast (fn ^:static butlast [s]
+ (loop [ret [] s s]
+ (if (next s)
+ (recur (conj ret (first s)) (next s))
+ (seq ret)))))
+
+(def
+
+ ^{:doc "Same as (def name (fn [params* ] exprs*)) or (def
+ name (fn ([params* ] exprs*)+)) with any doc-string or attrs added
+ to the var metadata. prepost-map defines a map with optional keys
+ :pre and :post that contain collections of pre or post conditions."
+ :arglists '([name doc-string? attr-map? [params*] prepost-map? body]
+ [name doc-string? attr-map? ([params*] prepost-map? body)+ attr-map?]) :dynamic true ;;; ADDED :dynamic true -- eventually replace with :redef
+ :added "1.0"}
+ defn (fn defn [&form &env name & fdecl]
+ ;; Note: Cannot delegate this check to def because of the call to (with-meta name ..)
+ (if (instance? clojure.lang.Symbol name)
+ nil
+ (throw (ArgumentException. "First argument to defn must be a symbol"))) ;;; IllegalArgumentException
+ (let [m (if (string? (first fdecl))
+ {:doc (first fdecl)}
+ {})
+ fdecl (if (string? (first fdecl))
+ (next fdecl)
+ fdecl)
+ m (if (map? (first fdecl))
+ (conj m (first fdecl))
+ m)
+ fdecl (if (map? (first fdecl))
+ (next fdecl)
+ fdecl)
+ fdecl (if (vector? (first fdecl))
+ (list fdecl)
+ fdecl)
+ m (if (map? (last fdecl))
+ (conj m (last fdecl))
+ m)
+ fdecl (if (map? (last fdecl))
+ (butlast fdecl)
+ fdecl)
+ m (conj {:arglists (list 'quote (sigs fdecl))} m)
+ m (let [inline (:inline m)
+ ifn (first inline)
+ iname (second inline)]
+ ;; same as: (if (and (= 'fn ifn) (not (symbol? iname))) ...)
+ (if (if (clojure.lang.Util/equiv 'fn ifn)
+ (if (instance? clojure.lang.Symbol iname) false true))
+ ;; inserts the same fn name to the inline fn if it does not have one
+ (assoc m :inline (cons ifn (cons (clojure.lang.Symbol/intern (String/Concat (.Name ^clojure.lang.Symbol name) "__inliner")) ;;; .concat .getName
+ (next inline))))
+ m))
+ m (conj (if (meta name) (meta name) {}) m)]
+ (list 'def (with-meta name m)
+ ;;todo - restore propagation of fn name
+ ;;must figure out how to convey primitive hints to self calls first
+ ;;(cons `fn fdecl)
+ (with-meta (cons `fn fdecl) {:rettag (:tag m)})))))
+
+(. (var defn) (setMacro))
+
+(defn to-array
+ "Returns an array of Objects containing the contents of coll, which
+ can be any Collection. Maps to java.util.Collection.toArray()."
+ {:tag "System.Object[]" ;;;{:tag "[Ljava.lang.Object;"}
+ :added "1.0"
+ :static true}
+ [coll] (. clojure.lang.RT (toArray coll)))
+;;; Not the same as the Java version, but good enough?
+(defn cast
+ "Throws a ClassCastException if x is not a c, else returns x."
+ {:added "1.0"
+ :static true}
+ [^Type c x] ;;; changed Class to Type
+ (if (clojure.lang.Util/identical x nil) nil (if (. c (IsInstanceOfType x)) x (throw (InvalidCastException. (.ToString (.GetType x))))))) ;;; original (. c (cast x)))
+
+(defn vector
+ "Creates a new vector containing the args."
+ {:added "1.0"
+ :static true}
+ ([] [])
+ ([a] [a])
+ ([a b] [a b])
+ ([a b c] [a b c])
+ ([a b c d] [a b c d])
+ ([a b c d e] [a b c d e])
+ ([a b c d e f] [a b c d e f])
+ ([a b c d e f & args]
+ (. clojure.lang.LazilyPersistentVector (create (cons a (cons b (cons c (cons d (cons e (cons f args))))))))))
+
+(defn vec
+ "Creates a new vector containing the contents of coll. Java arrays
+ will be aliased and should not be modified."
+ {:added "1.0"
+ :static true}
+ ([coll]
+ (if (vector? coll)
+ (if (instance? clojure.lang.IObj coll)
+ (with-meta coll nil)
+ (clojure.lang.LazilyPersistentVector/create coll))
+ (clojure.lang.LazilyPersistentVector/create coll))))
+
+(defn hash-map
+ "keyval => key val
+ Returns a new hash map with supplied mappings. If any keys are
+ equal, they are handled as if by repeated uses of assoc."
+ {:added "1.0"
+ :static true}
+ ([] {})
+ ([& keyvals]
+ (. clojure.lang.PersistentHashMap (create keyvals))))
+
+(defn hash-set
+ "Returns a new hash set with supplied keys. Any equal keys are
+ handled as if by repeated uses of conj."
+ {:added "1.0"
+ :static true}
+ ([] #{})
+ ([& keys]
+ (clojure.lang.PersistentHashSet/create keys)))
+
+(defn sorted-map
+ "keyval => key val
+ Returns a new sorted map with supplied mappings. If any keys are
+ equal, they are handled as if by repeated uses of assoc."
+ {:added "1.0"
+ :static true}
+ ([] clojure.lang.PersistentTreeMap/EMPTY) ;;; I HAD TO ADD THIS EXTRA CASE TO AVOID AMBIGUOUS CALL TO CREATE WITH NULL
+ ([& keyvals] (. clojure.lang.PersistentTreeMap (create keyvals))))
+
+(defn sorted-map-by
+ "keyval => key val
+ Returns a new sorted map with supplied mappings, using the supplied
+ comparator. If any keys are equal, they are handled as if by
+ repeated uses of assoc."
+ {:added "1.0"
+ :static true}
+ ([comparator & keyvals]
+ (clojure.lang.PersistentTreeMap/create comparator keyvals)))
+
+(defn sorted-set
+ "Returns a new sorted set with supplied keys. Any equal keys are
+ handled as if by repeated uses of conj."
+ {:added "1.0"
+ :static true}
+ ([] clojure.lang.PersistentTreeSet/EMPTY) ;;; I HAD TO ADD THIS EXTRA CASE TO AVOID AMBIGUOUS CALL TO CREATE WITH NULL
+ ([& keys] (clojure.lang.PersistentTreeSet/create keys)))
+
+(defn sorted-set-by
+ "Returns a new sorted set with supplied keys, using the supplied
+ comparator. Any equal keys are handled as if by repeated uses of
+ conj."
+ {:added "1.1"
+ :static true}
+ ([comparator & keys]
+ (clojure.lang.PersistentTreeSet/create comparator keys)))
+
+
+;;;;;;;;;;;;;;;;;;;;
+(defn nil?
+ "Returns true if x is nil, false otherwise."
+ {:tag Boolean
+ :added "1.0"
+ :static true
+ :inline (fn [x] (list 'clojure.lang.Util/identical x nil))}
+ [x] (clojure.lang.Util/identical x nil))
+
+(def
+
+ ^{:doc "Like defn, but the resulting function name is declared as a
+ macro and will be used as a macro by the compiler when it is
+ called."
+ :arglists '([name doc-string? attr-map? [params*] body]
+ [name doc-string? attr-map? ([params*] body)+ attr-map?])
+ :added "1.0"}
+ defmacro (fn [&form &env
+ name & args]
+ (let [prefix (loop [p (list name) args args]
+ (let [f (first args)]
+ (if (string? f)
+ (recur (cons f p) (next args))
+ (if (map? f)
+ (recur (cons f p) (next args))
+ p))))
+ fdecl (loop [fd args]
+ (if (string? (first fd))
+ (recur (next fd))
+ (if (map? (first fd))
+ (recur (next fd))
+ fd)))
+ fdecl (if (vector? (first fdecl))
+ (list fdecl)
+ fdecl)
+ add-implicit-args (fn [fd]
+ (let [args (first fd)]
+ (cons (vec (cons '&form (cons '&env args))) (next fd))))
+ add-args (fn [acc ds]
+ (if (nil? ds)
+ acc
+ (let [d (first ds)]
+ (if (map? d)
+ (conj acc d)
+ (recur (conj acc (add-implicit-args d)) (next ds))))))
+ fdecl (seq (add-args [] fdecl))
+ decl (loop [p prefix d fdecl]
+ (if p
+ (recur (next p) (cons (first p) d))
+ d))]
+ (list 'do
+ (cons `defn decl)
+ (list '. (list 'var name) '(setMacro))
+ (list 'var name)))))
+
+
+(. (var defmacro) (setMacro))
+
+(defmacro when
+ "Evaluates test. If logical true, evaluates body in an implicit do."
+ {:added "1.0"}
+ [test & body]
+ (list 'if test (cons 'do body)))
+
+(defmacro when-not
+ "Evaluates test. If logical false, evaluates body in an implicit do."
+ {:added "1.0"}
+ [test & body]
+ (list 'if test nil (cons 'do body)))
+
+(defn false?
+ "Returns true if x is the value false, false otherwise."
+ {:tag Boolean
+ :added "1.0"
+ :static true}
+ [x] (clojure.lang.Util/identical x false))
+
+(defn true?
+ "Returns true if x is the value true, false otherwise."
+ {:tag Boolean
+ :added "1.0"
+ :static true}
+ [x] (clojure.lang.Util/identical x true))
+
+(defn boolean?
+ "Return true if x is a Boolean"
+ {:added "1.9"}
+ [x] (instance? Boolean x))
+
+ (defn not
+ "Returns true if x is logical false, false otherwise."
+ {:tag Boolean
+ :added "1.0"
+ :static true}
+ [x] (if x false true))
+
+(defn some?
+ "Returns true if x is not nil, false otherwise."
+ {:tag Boolean
+ :added "1.6"
+ :static true}
+ [x] (not (nil? x)))
+
+(defn any?
+ "Returns true given any argument."
+ {:tag Boolean
+ :added "1.9"}
+ [x] true)
+
+(defn str
+ "With no args, returns the empty string. With one arg x, returns
+ x.toString(). (str nil) returns the empty string. With more than
+ one arg, returns the concatenation of the str values of the args."
+ {:tag String
+ :added "1.0"
+ :static true}
+ (^String [] "")
+ (^String [^Object x]
+ (if (nil? x) "" (clojure.lang.RT/CultureToString x))) ;;;(if (nil? x) "" (. x (toString)))) ;; java: toString
+ (^String [x & ys]
+ ((fn [^StringBuilder sb more]
+ (if more
+ (recur (. sb (Append (str (first more)))) (next more)) ;; java: append
+ (str sb)))
+ (new StringBuilder (str x)) ys)))
+
+
+(defn symbol?
+ "Return true if x is a Symbol"
+ {:added "1.0"
+ :static true}
+ [x] (instance? clojure.lang.Symbol x))
+
+(defn keyword?
+ "Return true if x is a Keyword"
+ {:added "1.0"
+ :static true}
+ [x] (instance? clojure.lang.Keyword x))
+
+(defmacro cond
+ "Takes a set of test/expr pairs. It evaluates each test one at a
+ time. If a test returns logical true, cond evaluates and returns
+ the value of the corresponding expr and doesn't evaluate any of the
+ other tests or exprs. (cond) returns nil."
+ {:added "1.0"}
+ [& clauses]
+ (when clauses
+ (list 'if (first clauses)
(if (next clauses)
(second clauses)
(throw (ArgumentException. ;;;IllegalArgumentException.
"cond requires an even number of forms")))
- (cons 'clojure.core/cond (next (next clauses))))))
-
-(defn symbol
- "Returns a Symbol with the given namespace and name. Arity-1 works
- on strings, keywords, and vars."
- {:tag clojure.lang.Symbol
- :added "1.0"
- :static true}
- ([name]
- (cond
- (symbol? name) name
- (instance? String name) (clojure.lang.Symbol/intern name)
- (instance? clojure.lang.Var name) (.ToSymbol ^clojure.lang.Var name) ;;; .toSymbol
- (instance? clojure.lang.Keyword name) (.Symbol ^clojure.lang.Keyword name) ;;; .sym
- :else (throw (ArgumentException. "no conversion to symbol")))) ;;; IllegalArgumentException.
- ([ns name] (clojure.lang.Symbol/intern ns name)))
-
-(defn gensym
- "Returns a new symbol with a unique name. If a prefix string is
- supplied, the name is prefix# where # is some unique number. If
- prefix is not supplied, the prefix is 'G__'."
- {:added "1.0"
- :static true}
- ([] (gensym "G__"))
- ([prefix-string] (. clojure.lang.Symbol (intern (str prefix-string (str (. clojure.lang.RT (nextID))))))))
-
-
-(defn keyword
- "Returns a Keyword with the given namespace and name. Do not use :
- in the keyword strings, it will be added automatically."
- {:tag clojure.lang.Keyword
- :added "1.0"
- :static true}
- ([name] (cond (keyword? name) name
- (symbol? name) (clojure.lang.Keyword/intern ^clojure.lang.Symbol name)
- (string? name) (clojure.lang.Keyword/intern ^String name)))
- ([ns name] (clojure.lang.Keyword/intern ns name)))
-
-(defn find-keyword
- "Returns a Keyword with the given namespace and name if one already
- exists. This function will not intern a new keyword. If the keyword
- has not already been interned, it will return nil. Do not use :
- in the keyword strings, it will be added automatically."
- {:tag clojure.lang.Keyword
- :added "1.3"
- :static true}
- ([name] (cond (keyword? name) name
- (symbol? name) (clojure.lang.Keyword/find ^clojure.lang.Symbol name)
- (string? name) (clojure.lang.Keyword/find ^String name)))
- ([ns name] (clojure.lang.Keyword/find ns name)))
-
-
-(defn spread
- {:private true
- :static true}
- [arglist]
- (cond
- (nil? arglist) nil
- (nil? (next arglist)) (seq (first arglist))
- :else (cons (first arglist) (spread (next arglist)))))
-
-(defn list*
- "Creates a new seq containing the items prepended to the rest, the
- last of which will be treated as a sequence."
- {:added "1.0"
- :static true}
- ([args] (seq args))
- ([a args] (cons a args))
- ([a b args] (cons a (cons b args)))
- ([a b c args] (cons a (cons b (cons c args))))
- ([a b c d & more]
- (cons a (cons b (cons c (cons d (spread more)))))))
-
-(defn apply
- "Applies fn f to the argument list formed by prepending intervening arguments to args."
- {:added "1.0"
- :static true}
- ([^clojure.lang.IFn f args]
- (. f (applyTo (seq args))))
- ([^clojure.lang.IFn f x args]
- (. f (applyTo (list* x args))))
- ([^clojure.lang.IFn f x y args]
- (. f (applyTo (list* x y args))))
- ([^clojure.lang.IFn f x y z args]
- (. f (applyTo (list* x y z args))))
- ([^clojure.lang.IFn f a b c d & args]
+ (cons 'clojure.core/cond (next (next clauses))))))
+
+(defn symbol
+ "Returns a Symbol with the given namespace and name. Arity-1 works
+ on strings, keywords, and vars."
+ {:tag clojure.lang.Symbol
+ :added "1.0"
+ :static true}
+ ([name]
+ (cond
+ (symbol? name) name
+ (instance? String name) (clojure.lang.Symbol/intern name)
+ (instance? clojure.lang.Var name) (.ToSymbol ^clojure.lang.Var name) ;;; .toSymbol
+ (instance? clojure.lang.Keyword name) (.Symbol ^clojure.lang.Keyword name) ;;; .sym
+ :else (throw (ArgumentException. "no conversion to symbol")))) ;;; IllegalArgumentException.
+ ([ns name] (clojure.lang.Symbol/intern ns name)))
+
+(defn gensym
+ "Returns a new symbol with a unique name. If a prefix string is
+ supplied, the name is prefix# where # is some unique number. If
+ prefix is not supplied, the prefix is 'G__'."
+ {:added "1.0"
+ :static true}
+ ([] (gensym "G__"))
+ ([prefix-string] (. clojure.lang.Symbol (intern (str prefix-string (str (. clojure.lang.RT (nextID))))))))
+
+
+(defn keyword
+ "Returns a Keyword with the given namespace and name. Do not use :
+ in the keyword strings, it will be added automatically."
+ {:tag clojure.lang.Keyword
+ :added "1.0"
+ :static true}
+ ([name] (cond (keyword? name) name
+ (symbol? name) (clojure.lang.Keyword/intern ^clojure.lang.Symbol name)
+ (string? name) (clojure.lang.Keyword/intern ^String name)))
+ ([ns name] (clojure.lang.Keyword/intern ns name)))
+
+(defn find-keyword
+ "Returns a Keyword with the given namespace and name if one already
+ exists. This function will not intern a new keyword. If the keyword
+ has not already been interned, it will return nil. Do not use :
+ in the keyword strings, it will be added automatically."
+ {:tag clojure.lang.Keyword
+ :added "1.3"
+ :static true}
+ ([name] (cond (keyword? name) name
+ (symbol? name) (clojure.lang.Keyword/find ^clojure.lang.Symbol name)
+ (string? name) (clojure.lang.Keyword/find ^String name)))
+ ([ns name] (clojure.lang.Keyword/find ns name)))
+
+
+(defn spread
+ {:private true
+ :static true}
+ [arglist]
+ (cond
+ (nil? arglist) nil
+ (nil? (next arglist)) (seq (first arglist))
+ :else (cons (first arglist) (spread (next arglist)))))
+
+(defn list*
+ "Creates a new seq containing the items prepended to the rest, the
+ last of which will be treated as a sequence."
+ {:added "1.0"
+ :static true}
+ ([args] (seq args))
+ ([a args] (cons a args))
+ ([a b args] (cons a (cons b args)))
+ ([a b c args] (cons a (cons b (cons c args))))
+ ([a b c d & more]
+ (cons a (cons b (cons c (cons d (spread more)))))))
+
+(defn apply
+ "Applies fn f to the argument list formed by prepending intervening arguments to args."
+ {:added "1.0"
+ :static true}
+ ([^clojure.lang.IFn f args]
+ (. f (applyTo (seq args))))
+ ([^clojure.lang.IFn f x args]
+ (. f (applyTo (list* x args))))
+ ([^clojure.lang.IFn f x y args]
+ (. f (applyTo (list* x y args))))
+ ([^clojure.lang.IFn f x y z args]
+ (. f (applyTo (list* x y z args))))
+ ([^clojure.lang.IFn f a b c d & args]
(. f (applyTo (cons a (cons b (cons c (cons d (spread args)))))))))
-
-(defn vary-meta
- "Returns an object of the same type and value as obj, with
- (apply f (meta obj) args) as its metadata."
- {:added "1.0"
- :static true}
- [obj f & args]
- (with-meta obj (apply f (meta obj) args)))
-
-(defmacro lazy-seq
- "Takes a body of expressions that returns an ISeq or nil, and yields
- a Seqable object that will invoke the body only the first time seq
- is called, and will cache the result and return it on all subsequent
- seq calls. Se all - realized?"
- {:added "1.0"}
- [& body]
- (list 'new 'clojure.lang.LazySeq (list* '^{:once true} fn* [] body)))
-
-(defn ^:static ^clojure.lang.ChunkBuffer chunk-buffer ^clojure.lang.ChunkBuffer [capacity]
- (clojure.lang.ChunkBuffer. capacity))
-
-(defn ^:static chunk-append [^clojure.lang.ChunkBuffer b x]
- (.add b x))
-
-(defn ^:static ^clojure.lang.IChunk chunk [^clojure.lang.ChunkBuffer b]
- (.chunk b))
-
-(defn ^:static ^clojure.lang.IChunk chunk-first ^clojure.lang.IChunk [^clojure.lang.IChunkedSeq s]
- (.chunkedFirst s))
-
-(defn ^:static ^clojure.lang.ISeq chunk-rest ^clojure.lang.ISeq [^clojure.lang.IChunkedSeq s]
- (.chunkedMore s))
-
-(defn ^:static ^clojure.lang.ISeq chunk-next ^clojure.lang.ISeq [^clojure.lang.IChunkedSeq s]
- (.chunkedNext s))
-
-(defn ^:static chunk-cons [chunk rest]
- (if (clojure.lang.Numbers/isZero (clojure.lang.RT/count chunk))
- rest
- (clojure.lang.ChunkedCons. chunk rest)))
-
-(defn ^:static chunked-seq? [s]
- (instance? clojure.lang.IChunkedSeq s))
-
-(defn concat
- "Returns a lazy seq representing the concatenation of the elements in the supplied colls."
- {:added "1.0"
- :static true}
- ([] (lazy-seq nil))
- ([x] (lazy-seq x))
- ([x y]
- (lazy-seq
- (let [s (seq x)]
- (if s
- (if (chunked-seq? s)
- (chunk-cons (chunk-first s) (concat (chunk-rest s) y))
- (cons (first s) (concat (rest s) y)))
- y))))
- ([x y & zs]
- (let [cat (fn cat [xys zs]
- (lazy-seq
- (let [xys (seq xys)]
- (if xys
- (if (chunked-seq? xys)
- (chunk-cons (chunk-first xys)
- (cat (chunk-rest xys) zs))
- (cons (first xys) (cat (rest xys) zs)))
- (when zs
- (cat (first zs) (next zs)))))))]
- (cat (concat x y) zs))))
-
-;;;;;;;;;;;;;;;;at this point all the support for syntax-quote exists;;;;;;;;;;;;;;;;;;;;;;
-(defmacro delay
- "Takes a body of expressions and yields a Delay object than will
- invoke the body only the first time it is forced (with force or deref/@), and
- will cache the result and return it on all subsequent force
- calls. See also - realized?"
- {:added "1.0"}
- [& body]
- (list 'new 'clojure.lang.Delay (list* `^{:once true} fn* [] body)))
-
-(defn delay?
- "returns true if x is a Delay created with delay"
- {:added "1.0"
- :static true}
- [x] (instance? clojure.lang.Delay x))
-
-(defn force
- "If x is a Delay, returns the (possibly cached) value of its expression, else returns x"
- {:added "1.0"
- :static true}
- [x] (. clojure.lang.Delay (force x)))
-
+
+(defn vary-meta
+ "Returns an object of the same type and value as obj, with
+ (apply f (meta obj) args) as its metadata."
+ {:added "1.0"
+ :static true}
+ [obj f & args]
+ (with-meta obj (apply f (meta obj) args)))
+
+(defmacro lazy-seq
+ "Takes a body of expressions that returns an ISeq or nil, and yields
+ a Seqable object that will invoke the body only the first time seq
+ is called, and will cache the result and return it on all subsequent
+ seq calls. Se all - realized?"
+ {:added "1.0"}
+ [& body]
+ (list 'new 'clojure.lang.LazySeq (list* '^{:once true} fn* [] body)))
+
+(defn ^:static ^clojure.lang.ChunkBuffer chunk-buffer ^clojure.lang.ChunkBuffer [capacity]
+ (clojure.lang.ChunkBuffer. capacity))
+
+(defn ^:static chunk-append [^clojure.lang.ChunkBuffer b x]
+ (.add b x))
+
+(defn ^:static ^clojure.lang.IChunk chunk [^clojure.lang.ChunkBuffer b]
+ (.chunk b))
+
+(defn ^:static ^clojure.lang.IChunk chunk-first ^clojure.lang.IChunk [^clojure.lang.IChunkedSeq s]
+ (.chunkedFirst s))
+
+(defn ^:static ^clojure.lang.ISeq chunk-rest ^clojure.lang.ISeq [^clojure.lang.IChunkedSeq s]
+ (.chunkedMore s))
+
+(defn ^:static ^clojure.lang.ISeq chunk-next ^clojure.lang.ISeq [^clojure.lang.IChunkedSeq s]
+ (.chunkedNext s))
+
+(defn ^:static chunk-cons [chunk rest]
+ (if (clojure.lang.Numbers/isZero (clojure.lang.RT/count chunk))
+ rest
+ (clojure.lang.ChunkedCons. chunk rest)))
+
+(defn ^:static chunked-seq? [s]
+ (instance? clojure.lang.IChunkedSeq s))
+
+(defn concat
+ "Returns a lazy seq representing the concatenation of the elements in the supplied colls."
+ {:added "1.0"
+ :static true}
+ ([] (lazy-seq nil))
+ ([x] (lazy-seq x))
+ ([x y]
+ (lazy-seq
+ (let [s (seq x)]
+ (if s
+ (if (chunked-seq? s)
+ (chunk-cons (chunk-first s) (concat (chunk-rest s) y))
+ (cons (first s) (concat (rest s) y)))
+ y))))
+ ([x y & zs]
+ (let [cat (fn cat [xys zs]
+ (lazy-seq
+ (let [xys (seq xys)]
+ (if xys
+ (if (chunked-seq? xys)
+ (chunk-cons (chunk-first xys)
+ (cat (chunk-rest xys) zs))
+ (cons (first xys) (cat (rest xys) zs)))
+ (when zs
+ (cat (first zs) (next zs)))))))]
+ (cat (concat x y) zs))))
+
+;;;;;;;;;;;;;;;;at this point all the support for syntax-quote exists;;;;;;;;;;;;;;;;;;;;;;
+(defmacro delay
+ "Takes a body of expressions and yields a Delay object than will
+ invoke the body only the first time it is forced (with force or deref/@), and
+ will cache the result and return it on all subsequent force
+ calls. See also - realized?"
+ {:added "1.0"}
+ [& body]
+ (list 'new 'clojure.lang.Delay (list* `^{:once true} fn* [] body)))
+
+(defn delay?
+ "returns true if x is a Delay created with delay"
+ {:added "1.0"
+ :static true}
+ [x] (instance? clojure.lang.Delay x))
+
+(defn force
+ "If x is a Delay, returns the (possibly cached) value of its expression, else returns x"
+ {:added "1.0"
+ :static true}
+ [x] (. clojure.lang.Delay (force x)))
+
(defmacro if-not
- "Evaluates test. If logical false, evaluates and returns then expr,
+ "Evaluates test. If logical false, evaluates and returns then expr,
otherwise else expr, if supplied, else nil."
- {:added "1.0"}
+ {:added "1.0"}
([test then] `(if-not ~test ~then nil))
([test then else]
- `(if (not ~test) ~then ~else)))
-
-(defn identical?
- "Tests if 2 arguments are the same object"
- {:inline (fn [x y] `(. clojure.lang.Util identical ~x ~y))
- :inline-arities #{2}
- :added "1.0"}
- ([x y] (clojure.lang.Util/identical x y)))
-
-; equiv-based
-(defn =
- "Equality. Returns true if x equals y, false if not. Same as
- Java x.equals(y) except it also works for nil, and compares
- numbers and collections in a type-independent manner. Clojure's immutable data
- structures define equals() (and thus =) as a value, not an identity,
- comparison."
- {:inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y))
- :inline-arities #{2}
- :added "1.0"}
- ([x] true)
- ([x y] (clojure.lang.Util/equiv x y))
- ([x y & more]
- (if (clojure.lang.Util/equiv x y)
- (if (next more)
- (recur y (first more) (next more))
- (clojure.lang.Util/equiv y (first more)))
- false)))
-
-;equals-based
-#_(defn =
- "Equality. Returns true if x equals y, false if not. Same as Java
- x.equals(y) except it also works for nil. Boxed numbers must have
- same type. Clojure's immutable data structures define equals() (and
- thus =) as a vlue, not an identity, comparison."
- {:inline (fn [x y] `(. clojure.lang.Util equals ~x ~y))
- :inline-arities #{2}
- :added "1.0"}
- ([x] true)
- ([x y] (clojure.lang.Util/equals x y))
- ([x y & more]
- (if (= x y)
- (if (next more)
- (recur y (first more) (next more))
- (= y (first more)))
- false)))
-
-(defn not=
- "Same as (not (= obj1 obj2))"
- {:tag Boolean
- :added "1.0"
- :static true}
- ([x] false)
- ([x y] (not (= x y)))
- ([x y & more]
- (not (apply = x y more))))
-
-
-
-(defn compare
- "Comparator. Returns a negative number, zero, or a positive number
- when x is logically 'less than', 'equal to', or 'greater than'
- y. Same as Java x.compareTo(y) except it also works for nil, and
- compares numbers and collections in a type-independent manner. x
- must implement Comparable"
- {
- :inline (fn [x y] `(. clojure.lang.Util compare ~x ~y))
- :added "1.0"}
- [x y] (. clojure.lang.Util (compare x y)))
-
-(defmacro and
- "Evaluates exprs one at a time, from left to right. If a form
- returns logical false (nil or false), and returns that value and
- doesn't evaluate any of the other expressions, otherwise it returns
- the value of the last expr. (and) returns true."
- {:added "1.0"}
- ([] true)
- ([x] x)
- ([x & next]
- `(let [and# ~x]
- (if and# (and ~@next) and#))))
-
-(defmacro or
- "Evaluates exprs one at a time, from left to right. If a form
- returns a logical true value, or returns that value and doesn't
- evaluate any of the other expressions, otherwise it returns the
- value of the last expression. (or) returns nil."
- {:added "1.0"}
- ([] nil)
- ([x] x)
- ([x & next]
- `(let [or# ~x]
- (if or# or# (or ~@next)))))
-
-;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;;
-(defn zero?
- "Returns true if num is zero, else false"
- {
- :inline (fn [num] `(. clojure.lang.Numbers (isZero ~num)))
- :added "1.0"}
- [num] (. clojure.lang.Numbers (isZero num)))
-
-(defn count
- "Returns the number of items in the collection. (count nil) returns
- 0. Also works on strings, arrays, and Java Collections and Maps"
- {
- :inline (fn [x] `(. clojure.lang.RT (count ~x)))
- :added "1.0"}
- [coll] (. clojure.lang.RT (count coll)))
-
-(defn int ;;; Need to make this handle args out of range
- "Coerce to int"
- {
- :inline (fn [x] `(. clojure.lang.RT (~(if *unchecked-math* 'uncheckedIntCast 'intCast) ~x)))
- :added "1.0"}
- [x] (. clojure.lang.RT (intCast x)))
-
-(defn nth
- "Returns the value at the index. get returns nil if index out of
- bounds, nth throws an exception unless not-found is supplied. nth
- also works for strings, Java arrays, regex Matchers and Lists, and,
- in O(n) time, for sequences."
- {:inline (fn [c i & nf] `(. clojure.lang.RT (nth ~c ~i ~@nf)))
- :inline-arities #{2 3}
- :added "1.0"}
- ([coll index] (. clojure.lang.RT (nth coll index)))
- ([coll index not-found] (. clojure.lang.RT (nth coll index not-found))))
-
-(defn <
- "Returns non-nil if nums are in monotonically increasing order,
- otherwise false."
- {:inline (fn [x y] `(. clojure.lang.Numbers (lt ~x ~y)))
- :inline-arities #{2}
- :added "1.0"}
- ([x] true)
- ([x y] (. clojure.lang.Numbers (lt x y)))
- ([x y & more]
- (if (< x y)
- (if (next more)
- (recur y (first more) (next more))
- (< y (first more)))
- false)))
-
-(defn inc'
- "Returns a number one greater than num. Supports arbitrary precision.
- See also: inc"
- {:inline (fn [x] `(. clojure.lang.Numbers (incP ~x)))
- :added "1.0"}
- [x] (. clojure.lang.Numbers (incP x)))
-
-(defn inc
- "Returns a number one greater than num. Does not auto-promote
- longs, will throw on overflow. See also: inc'"
- {:inline (fn [x] `(. clojure.lang.Numbers (~(if *unchecked-math* 'unchecked_inc 'inc) ~x)))
- :added "1.2"}
- [x] (. clojure.lang.Numbers (inc x)))
-
-;; reduce is defined again later after InternalReduce loads
-(defn ^:private ^:static
- reduce1
- ([f coll]
- (let [s (seq coll)]
- (if s
- (reduce1 f (first s) (next s))
- (f))))
- ([f val coll]
- (let [s (seq coll)]
- (if s
- (if (chunked-seq? s)
- (recur f
- (.reduce (chunk-first s) f val)
- (chunk-next s))
- (recur f (f val (first s)) (next s)))
- val))))
-
-(defn reverse
- "Returns a seq of the items in coll in reverse order. Not lazy."
- {:added "1.0"
- :static true}
- [coll]
- (reduce1 conj () coll))
-
-;;math stuff
-(defn ^:private nary-inline
- ([op] (nary-inline op op))
- ([op unchecked-op]
- (fn
- ([x] (let [op (if *unchecked-math* unchecked-op op)]
- `(. clojure.lang.Numbers (~op ~x))))
- ([x y] (let [op (if *unchecked-math* unchecked-op op)]
- `(. clojure.lang.Numbers (~op ~x ~y))))
- ([x y & more]
- (let [op (if *unchecked-math* unchecked-op op)]
- (reduce1
- (fn [a b] `(. clojure.lang.Numbers (~op ~a ~b)))
- `(. clojure.lang.Numbers (~op ~x ~y)) more))))))
-
-(defn ^:private >1? [n] (clojure.lang.Numbers/gt n 1))
-(defn ^:private >0? [n] (clojure.lang.Numbers/gt n 0))
-
-(defn +'
- "Returns the sum of nums. (+') returns 0. Supports arbitrary precision.
- See also: +"
- {:inline (nary-inline 'addP)
- :inline-arities >1?
- :added "1.0"}
- ([] 0)
- ([x] (. clojure.lang.RT (NumberCast x))) ;; (cast Number x))
- ([x y] (. clojure.lang.Numbers (addP x y)))
- ([x y & more]
- (reduce1 +' (+' x y) more)))
-
-(defn +
- "Returns the sum of nums. (+) returns 0. Does not auto-promote
- longs, will throw on overflow. See also: +'"
- {:inline (nary-inline 'add 'unchecked_add)
- :inline-arities >1?
- :added "1.2"}
- ([] 0)
- ([x] (. clojure.lang.RT (NumberCast x))) ;;; (cast Number x))
- ([x y] (. clojure.lang.Numbers (add x y)))
- ([x y & more]
- (reduce1 + (+ x y) more)))
-
-(defn *'
- "Returns the product of nums. (*') returns 1. Supports arbitrary precision.
- See also: *"
- {:inline (nary-inline 'multiplyP)
- :inline-arities >1?
- :added "1.0"}
- ([] 1)
- ([x] (. clojure.lang.RT (NumberCast x))) ;; (cast Number x))
- ([x y] (. clojure.lang.Numbers (multiplyP x y)))
- ([x y & more]
- (reduce1 *' (*' x y) more)))
-
-(defn *
- "Returns the product of nums. (*) returns 1. Does not auto-promote
- longs, will throw on overflow. See also: *'"
- {:inline (nary-inline 'multiply 'unchecked_multiply)
- :inline-arities >1?
- :added "1.2"}
- ([] 1)
- ([x] (. clojure.lang.RT (NumberCast x))) ;;; (cast Number x))
- ([x y] (. clojure.lang.Numbers (multiply x y)))
- ([x y & more]
- (reduce1 * (* x y) more)))
-
-(defn /
- "If no denominators are supplied, returns 1/numerator,
- else returns numerator divided by all of the denominators."
- {:inline (nary-inline 'divide)
- :inline-arities >1?
- :added "1.0"}
- ([x] (/ 1 x))
- ([x y] (. clojure.lang.Numbers (divide x y)))
- ([x y & more]
- (reduce1 / (/ x y) more)))
-
-(defn -'
- "If no ys are supplied, returns the negation of x, else subtracts
- the ys from x and returns the result. Supports arbitrary precision.
- See also: -"
- {:inline (nary-inline 'minusP)
- :inline-arities >0?
- :added "1.0"}
- ([x] (. clojure.lang.Numbers (minusP x)))
- ([x y] (. clojure.lang.Numbers (minusP x y)))
- ([x y & more]
- (reduce1 -' (-' x y) more)))
-
-(defn -
- "If no ys are supplied, returns the negation of x, else subtracts
- the ys from x and returns the result. Does not auto-promote
- longs, will throw on overflow. See also: -'"
- {:inline (nary-inline 'minus 'unchecked_minus)
- :inline-arities >0?
- :added "1.2"}
- ([x] (. clojure.lang.Numbers (minus x)))
- ([x y] (. clojure.lang.Numbers (minus x y)))
- ([x y & more]
- (reduce1 - (- x y) more)))
-
-(defn <=
- "Returns non-nil if nums are in monotonically non-decreasing order,
- otherwise false."
- {:inline (fn [x y] `(. clojure.lang.Numbers (lte ~x ~y)))
- :inline-arities #{2}
- :added "1.0"}
- ([x] true)
- ([x y] (. clojure.lang.Numbers (lte x y)))
- ([x y & more]
- (if (<= x y)
- (if (next more)
- (recur y (first more) (next more))
- (<= y (first more)))
- false)))
-
-(defn >
- "Returns non-nil if nums are in monotonically decreasing order,
- otherwise false."
- {:inline (fn [x y] `(. clojure.lang.Numbers (gt ~x ~y)))
- :inline-arities #{2}
- :added "1.0"}
- ([x] true)
- ([x y] (. clojure.lang.Numbers (gt x y)))
- ([x y & more]
- (if (> x y)
- (if (next more)
- (recur y (first more) (next more))
- (> y (first more)))
- false)))
-
-(defn >=
- "Returns non-nil if nums are in monotonically non-increasing order,
- otherwise false."
- {:inline (fn [x y] `(. clojure.lang.Numbers (gte ~x ~y)))
- :inline-arities #{2}
- :added "1.0"}
- ([x] true)
- ([x y] (. clojure.lang.Numbers (gte x y)))
- ([x y & more]
- (if (>= x y)
- (if (next more)
- (recur y (first more) (next more))
- (>= y (first more)))
- false)))
-
-(defn ==
- "Returns non-nil if nums all have the equivalent
- value (type-independent), otherwise false"
- {:inline (fn [x y] `(. clojure.lang.Numbers (equiv ~x ~y)))
- :inline-arities #{2}
- :added "1.0"}
- ([x] true)
- ([x y] (. clojure.lang.Numbers (equiv x y)))
- ([x y & more]
- (if (== x y)
- (if (next more)
- (recur y (first more) (next more))
- (== y (first more)))
- false)))
-
-(defn max
- "Returns the greatest of the nums."
- {:added "1.0"
- :inline-arities >1?
- :inline (nary-inline 'max)}
- ([x] x)
- ([x y] (. clojure.lang.Numbers (max x y)))
- ([x y & more]
- (reduce1 max (max x y) more)))
-
-(defn min
- "Returns the least of the nums."
- {:added "1.0"
- :inline-arities >1?
- :inline (nary-inline 'min)}
- ([x] x)
- ([x y] (. clojure.lang.Numbers (min x y)))
- ([x y & more]
- (reduce1 min (min x y) more)))
-
-(defn abs
- {:doc "Returns the absolute value of a.
- If a is Long/MIN_VALUE => Long/MIN_VALUE
- If a is a double and zero => +0.0
- If a is a double and ##Inf or ##-Inf => ##Inf
- If a is a double and ##NaN => ##NaN"
- :inline-arities #{1}
- :inline (fn [a] `(clojure.lang.Numbers/abs ~a))
- :added "1.11"}
- [a]
- (clojure.lang.Numbers/abs a))
-
-(defn dec'
- "Returns a number one less than num. Supports arbitrary precision.
- See also: dec"
- {:inline (fn [x] `(. clojure.lang.Numbers (decP ~x)))
- :added "1.0"}
- [x] (. clojure.lang.Numbers (decP x)))
-
-(defn dec
- "Returns a number one less than num. Does not auto-promote
- longs, will throw on overflow. See also: dec'"
- {:inline (fn [x] `(. clojure.lang.Numbers (~(if *unchecked-math* 'unchecked_dec 'dec) ~x)))
- :added "1.2"}
- [x] (. clojure.lang.Numbers (dec x)))
-
-(defn unchecked-inc-int
- "Returns a number one greater than x, an int.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_int_inc ~x)))
- :added "1.0"}
- [x] (. clojure.lang.Numbers (unchecked_int_inc x)))
-
-(defn unchecked-inc
- "Returns a number one greater than x, a long.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_inc ~x)))
- :added "1.0"}
- [x] (. clojure.lang.Numbers (unchecked_inc x)))
-
-(defn unchecked-dec-int
- "Returns a number one less than x, an int.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_int_dec ~x)))
- :added "1.0"}
- [x] (. clojure.lang.Numbers (unchecked_int_dec x)))
-
-(defn unchecked-dec
- "Returns a number one less than x, a long.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_dec ~x)))
- :added "1.0"}
- [x] (. clojure.lang.Numbers (unchecked_dec x)))
-
-(defn unchecked-negate-int
- "Returns the negation of x, an int.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_int_negate ~x)))
- :added "1.0"}
- [x] (. clojure.lang.Numbers (unchecked_int_negate x)))
-
-(defn unchecked-negate
- "Returns the negation of x, a long.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_minus ~x)))
- :added "1.0"}
- [x] (. clojure.lang.Numbers (unchecked_minus x)))
-
-(defn unchecked-add-int
- "Returns the sum of x and y, both int.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_add ~x ~y)))
- :added "1.0"}
- [x y] (. clojure.lang.Numbers (unchecked_int_add x y)))
-
-(defn unchecked-add
- "Returns the sum of x and y, both long.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_add ~x ~y)))
- :added "1.0"}
- [x y] (. clojure.lang.Numbers (unchecked_add x y)))
-
-(defn unchecked-subtract-int
- "Returns the difference of x and y, both int.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_subtract ~x ~y)))
- :added "1.0"}
- [x y] (. clojure.lang.Numbers (unchecked_int_subtract x y)))
-
-(defn unchecked-subtract
- "Returns the difference of x and y, both long.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_minus ~x ~y)))
- :added "1.0"}
- [x y] (. clojure.lang.Numbers (unchecked_minus x y)))
-
-(defn unchecked-multiply-int
- "Returns the product of x and y, both int.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_multiply ~x ~y)))
- :added "1.0"}
- [x y] (. clojure.lang.Numbers (unchecked_int_multiply x y)))
-
-(defn unchecked-multiply
- "Returns the product of x and y, both long.
- Note - uses a primitive operator subject to overflow."
- {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_multiply ~x ~y)))
- :added "1.0"}
- [x y] (. clojure.lang.Numbers (unchecked_multiply x y)))
-
-(defn unchecked-divide-int
- "Returns the division of x by y, both int.
- Note - uses a primitive operator subject to truncation."
- {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_divide ~x ~y)))
- :added "1.0"}
- [x y] (. clojure.lang.Numbers (unchecked_int_divide x y)))
-
-(defn unchecked-remainder-int
- "Returns the remainder of division of x by y, both int.
- Note - uses a primitive operator subject to truncation."
- {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_remainder ~x ~y)))
- :added "1.0"}
- [x y] (. clojure.lang.Numbers (unchecked_int_remainder x y)))
-
-(defn pos?
- "Returns true if num is greater than zero, else false"
- {:tag Boolean
- :inline (fn [num] `(. clojure.lang.Numbers (isPos ~num)))
- :added "1.0"}
- [num] (. clojure.lang.Numbers (isPos num)))
-
-(defn neg?
- "Returns true if num is less than zero, else false"
- {
- :inline (fn [num] `(. clojure.lang.Numbers (isNeg ~num)))
- :added "1.0"}
- [num] (. clojure.lang.Numbers (isNeg num)))
-
-(defn quot
- "quot[ient] of dividing numerator by denominator."
- {:added "1.0"
- :static true
- :inline (fn [x y] `(. clojure.lang.Numbers (quotient ~x ~y)))}
- [num div]
- (. clojure.lang.Numbers (quotient num div)))
-
-(defn rem
- "remainder of dividing numerator by denominator."
- {:added "1.0"
- :static true
- :inline (fn [x y] `(. clojure.lang.Numbers (remainder ~x ~y)))}
- [num div]
- (. clojure.lang.Numbers (remainder num div)))
-
-(defn rationalize
- "returns the rational value of num"
- {:added "1.0"
- :static true}
- [num]
- (. clojure.lang.Numbers (rationalize num)))
-
-;;Bit ops
-
-(defn bit-not
- "Bitwise complement"
- {:inline (fn [x] `(. clojure.lang.Numbers (not ~x)))
- :added "1.0"}
- [x] (. clojure.lang.Numbers not x))
-
-
-(defn bit-and
- "Bitwise and"
- {:inline (nary-inline 'and)
- :inline-arities >1?
- :added "1.0"}
- ([x y] (. clojure.lang.Numbers and x y))
- ([x y & more]
- (reduce1 bit-and (bit-and x y) more)))
-
-(defn bit-or
- "Bitwise or"
- {:inline (nary-inline 'or)
- :inline-arities >1?
- :added "1.0"}
- ([x y] (. clojure.lang.Numbers or x y))
- ([x y & more]
- (reduce1 bit-or (bit-or x y) more)))
-
-(defn bit-xor
- "Bitwise exclusive or"
- {:inline (nary-inline 'xor)
- :inline-arities >1?
- :added "1.0"}
- ([x y] (. clojure.lang.Numbers xor x y))
- ([x y & more]
- (reduce1 bit-xor (bit-xor x y) more)))
-
-(defn bit-and-not
- "Bitwise and with complement"
- {:inline (nary-inline 'andNot)
- :inline-arities >1?
- :added "1.0"
- :static true}
- ([x y] (. clojure.lang.Numbers andNot x y))
- ([x y & more]
- (reduce1 bit-and-not (bit-and-not x y) more)))
-
-
-(defn bit-clear
- "Clear bit at index n"
- {:added "1.0"
- :static true}
- [x n] (. clojure.lang.Numbers clearBit x n))
-
-(defn bit-set
- "Set bit at index n"
- {:added "1.0"
- :static true}
- [x n] (. clojure.lang.Numbers setBit x n))
-
-(defn bit-flip
- "Flip bit at index n"
- {:added "1.0
- :static true"}
- [x n] (. clojure.lang.Numbers flipBit x n))
-
-(defn bit-test
- "Test bit at index n"
- {:added "1.0"
- :static true}
- [x n] (. clojure.lang.Numbers testBit x n))
-
-
-(defn bit-shift-left
- "Bitwise shift left"
- {:inline (fn [x n] `(. clojure.lang.Numbers (shiftLeft ~x ~n)))
- :added "1.0"}
- [x n] (. clojure.lang.Numbers shiftLeft x n))
-
-(defn bit-shift-right
- "Bitwise shift right"
- {:inline (fn [x n] `(. clojure.lang.Numbers (shiftRight ~x ~n)))
- :added "1.0"}
- [x n] (. clojure.lang.Numbers shiftRight x n))
-
-(defn unsigned-bit-shift-right
- "Bitwise shift right, without sign-extension."
- {:inline (fn [x n] `(. clojure.lang.Numbers (unsignedShiftRight ~x ~n)))
- :added "1.6"}
- [x n] (. clojure.lang.Numbers unsignedShiftRight x n))
+ `(if (not ~test) ~then ~else)))
+
+(defn identical?
+ "Tests if 2 arguments are the same object"
+ {:inline (fn [x y] `(. clojure.lang.Util identical ~x ~y))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x y] (clojure.lang.Util/identical x y)))
+
+; equiv-based
+(defn =
+ "Equality. Returns true if x equals y, false if not. Same as
+ Java x.equals(y) except it also works for nil, and compares
+ numbers and collections in a type-independent manner. Clojure's immutable data
+ structures define equals() (and thus =) as a value, not an identity,
+ comparison."
+ {:inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x] true)
+ ([x y] (clojure.lang.Util/equiv x y))
+ ([x y & more]
+ (if (clojure.lang.Util/equiv x y)
+ (if (next more)
+ (recur y (first more) (next more))
+ (clojure.lang.Util/equiv y (first more)))
+ false)))
+
+;equals-based
+#_(defn =
+ "Equality. Returns true if x equals y, false if not. Same as Java
+ x.equals(y) except it also works for nil. Boxed numbers must have
+ same type. Clojure's immutable data structures define equals() (and
+ thus =) as a vlue, not an identity, comparison."
+ {:inline (fn [x y] `(. clojure.lang.Util equals ~x ~y))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x] true)
+ ([x y] (clojure.lang.Util/equals x y))
+ ([x y & more]
+ (if (= x y)
+ (if (next more)
+ (recur y (first more) (next more))
+ (= y (first more)))
+ false)))
+
+(defn not=
+ "Same as (not (= obj1 obj2))"
+ {:tag Boolean
+ :added "1.0"
+ :static true}
+ ([x] false)
+ ([x y] (not (= x y)))
+ ([x y & more]
+ (not (apply = x y more))))
+
+
+
+(defn compare
+ "Comparator. Returns a negative number, zero, or a positive number
+ when x is logically 'less than', 'equal to', or 'greater than'
+ y. Same as Java x.compareTo(y) except it also works for nil, and
+ compares numbers and collections in a type-independent manner. x
+ must implement Comparable"
+ {
+ :inline (fn [x y] `(. clojure.lang.Util compare ~x ~y))
+ :added "1.0"}
+ [x y] (. clojure.lang.Util (compare x y)))
+
+(defmacro and
+ "Evaluates exprs one at a time, from left to right. If a form
+ returns logical false (nil or false), and returns that value and
+ doesn't evaluate any of the other expressions, otherwise it returns
+ the value of the last expr. (and) returns true."
+ {:added "1.0"}
+ ([] true)
+ ([x] x)
+ ([x & next]
+ `(let [and# ~x]
+ (if and# (and ~@next) and#))))
+
+(defmacro or
+ "Evaluates exprs one at a time, from left to right. If a form
+ returns a logical true value, or returns that value and doesn't
+ evaluate any of the other expressions, otherwise it returns the
+ value of the last expression. (or) returns nil."
+ {:added "1.0"}
+ ([] nil)
+ ([x] x)
+ ([x & next]
+ `(let [or# ~x]
+ (if or# or# (or ~@next)))))
+
+;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;;
+(defn zero?
+ "Returns true if num is zero, else false"
+ {
+ :inline (fn [num] `(. clojure.lang.Numbers (isZero ~num)))
+ :added "1.0"}
+ [num] (. clojure.lang.Numbers (isZero num)))
+
+(defn count
+ "Returns the number of items in the collection. (count nil) returns
+ 0. Also works on strings, arrays, and Java Collections and Maps"
+ {
+ :inline (fn [x] `(. clojure.lang.RT (count ~x)))
+ :added "1.0"}
+ [coll] (. clojure.lang.RT (count coll)))
+
+(defn int ;;; Need to make this handle args out of range
+ "Coerce to int"
+ {
+ :inline (fn [x] `(. clojure.lang.RT (~(if *unchecked-math* 'uncheckedIntCast 'intCast) ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.RT (intCast x)))
+
+(defn nth
+ "Returns the value at the index. get returns nil if index out of
+ bounds, nth throws an exception unless not-found is supplied. nth
+ also works for strings, Java arrays, regex Matchers and Lists, and,
+ in O(n) time, for sequences."
+ {:inline (fn [c i & nf] `(. clojure.lang.RT (nth ~c ~i ~@nf)))
+ :inline-arities #{2 3}
+ :added "1.0"}
+ ([coll index] (. clojure.lang.RT (nth coll index)))
+ ([coll index not-found] (. clojure.lang.RT (nth coll index not-found))))
+
+(defn <
+ "Returns non-nil if nums are in monotonically increasing order,
+ otherwise false."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (lt ~x ~y)))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x] true)
+ ([x y] (. clojure.lang.Numbers (lt x y)))
+ ([x y & more]
+ (if (< x y)
+ (if (next more)
+ (recur y (first more) (next more))
+ (< y (first more)))
+ false)))
+
+(defn inc'
+ "Returns a number one greater than num. Supports arbitrary precision.
+ See also: inc"
+ {:inline (fn [x] `(. clojure.lang.Numbers (incP ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.Numbers (incP x)))
+
+(defn inc
+ "Returns a number one greater than num. Does not auto-promote
+ longs, will throw on overflow. See also: inc'"
+ {:inline (fn [x] `(. clojure.lang.Numbers (~(if *unchecked-math* 'unchecked_inc 'inc) ~x)))
+ :added "1.2"}
+ [x] (. clojure.lang.Numbers (inc x)))
+
+;; reduce is defined again later after InternalReduce loads
+(defn ^:private ^:static
+ reduce1
+ ([f coll]
+ (let [s (seq coll)]
+ (if s
+ (reduce1 f (first s) (next s))
+ (f))))
+ ([f val coll]
+ (let [s (seq coll)]
+ (if s
+ (if (chunked-seq? s)
+ (recur f
+ (.reduce (chunk-first s) f val)
+ (chunk-next s))
+ (recur f (f val (first s)) (next s)))
+ val))))
+
+(defn reverse
+ "Returns a seq of the items in coll in reverse order. Not lazy."
+ {:added "1.0"
+ :static true}
+ [coll]
+ (reduce1 conj () coll))
+
+;;math stuff
+(defn ^:private nary-inline
+ ([op] (nary-inline op op))
+ ([op unchecked-op]
+ (fn
+ ([x] (let [op (if *unchecked-math* unchecked-op op)]
+ `(. clojure.lang.Numbers (~op ~x))))
+ ([x y] (let [op (if *unchecked-math* unchecked-op op)]
+ `(. clojure.lang.Numbers (~op ~x ~y))))
+ ([x y & more]
+ (let [op (if *unchecked-math* unchecked-op op)]
+ (reduce1
+ (fn [a b] `(. clojure.lang.Numbers (~op ~a ~b)))
+ `(. clojure.lang.Numbers (~op ~x ~y)) more))))))
+
+(defn ^:private >1? [n] (clojure.lang.Numbers/gt n 1))
+(defn ^:private >0? [n] (clojure.lang.Numbers/gt n 0))
+
+(defn +'
+ "Returns the sum of nums. (+') returns 0. Supports arbitrary precision.
+ See also: +"
+ {:inline (nary-inline 'addP)
+ :inline-arities >1?
+ :added "1.0"}
+ ([] 0)
+ ([x] (. clojure.lang.RT (NumberCast x))) ;; (cast Number x))
+ ([x y] (. clojure.lang.Numbers (addP x y)))
+ ([x y & more]
+ (reduce1 +' (+' x y) more)))
+
+(defn +
+ "Returns the sum of nums. (+) returns 0. Does not auto-promote
+ longs, will throw on overflow. See also: +'"
+ {:inline (nary-inline 'add 'unchecked_add)
+ :inline-arities >1?
+ :added "1.2"}
+ ([] 0)
+ ([x] (. clojure.lang.RT (NumberCast x))) ;;; (cast Number x))
+ ([x y] (. clojure.lang.Numbers (add x y)))
+ ([x y & more]
+ (reduce1 + (+ x y) more)))
+
+(defn *'
+ "Returns the product of nums. (*') returns 1. Supports arbitrary precision.
+ See also: *"
+ {:inline (nary-inline 'multiplyP)
+ :inline-arities >1?
+ :added "1.0"}
+ ([] 1)
+ ([x] (. clojure.lang.RT (NumberCast x))) ;; (cast Number x))
+ ([x y] (. clojure.lang.Numbers (multiplyP x y)))
+ ([x y & more]
+ (reduce1 *' (*' x y) more)))
+
+(defn *
+ "Returns the product of nums. (*) returns 1. Does not auto-promote
+ longs, will throw on overflow. See also: *'"
+ {:inline (nary-inline 'multiply 'unchecked_multiply)
+ :inline-arities >1?
+ :added "1.2"}
+ ([] 1)
+ ([x] (. clojure.lang.RT (NumberCast x))) ;;; (cast Number x))
+ ([x y] (. clojure.lang.Numbers (multiply x y)))
+ ([x y & more]
+ (reduce1 * (* x y) more)))
+
+(defn /
+ "If no denominators are supplied, returns 1/numerator,
+ else returns numerator divided by all of the denominators."
+ {:inline (nary-inline 'divide)
+ :inline-arities >1?
+ :added "1.0"}
+ ([x] (/ 1 x))
+ ([x y] (. clojure.lang.Numbers (divide x y)))
+ ([x y & more]
+ (reduce1 / (/ x y) more)))
+
+(defn -'
+ "If no ys are supplied, returns the negation of x, else subtracts
+ the ys from x and returns the result. Supports arbitrary precision.
+ See also: -"
+ {:inline (nary-inline 'minusP)
+ :inline-arities >0?
+ :added "1.0"}
+ ([x] (. clojure.lang.Numbers (minusP x)))
+ ([x y] (. clojure.lang.Numbers (minusP x y)))
+ ([x y & more]
+ (reduce1 -' (-' x y) more)))
+
+(defn -
+ "If no ys are supplied, returns the negation of x, else subtracts
+ the ys from x and returns the result. Does not auto-promote
+ longs, will throw on overflow. See also: -'"
+ {:inline (nary-inline 'minus 'unchecked_minus)
+ :inline-arities >0?
+ :added "1.2"}
+ ([x] (. clojure.lang.Numbers (minus x)))
+ ([x y] (. clojure.lang.Numbers (minus x y)))
+ ([x y & more]
+ (reduce1 - (- x y) more)))
+
+(defn <=
+ "Returns non-nil if nums are in monotonically non-decreasing order,
+ otherwise false."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (lte ~x ~y)))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x] true)
+ ([x y] (. clojure.lang.Numbers (lte x y)))
+ ([x y & more]
+ (if (<= x y)
+ (if (next more)
+ (recur y (first more) (next more))
+ (<= y (first more)))
+ false)))
+
+(defn >
+ "Returns non-nil if nums are in monotonically decreasing order,
+ otherwise false."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (gt ~x ~y)))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x] true)
+ ([x y] (. clojure.lang.Numbers (gt x y)))
+ ([x y & more]
+ (if (> x y)
+ (if (next more)
+ (recur y (first more) (next more))
+ (> y (first more)))
+ false)))
+
+(defn >=
+ "Returns non-nil if nums are in monotonically non-increasing order,
+ otherwise false."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (gte ~x ~y)))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x] true)
+ ([x y] (. clojure.lang.Numbers (gte x y)))
+ ([x y & more]
+ (if (>= x y)
+ (if (next more)
+ (recur y (first more) (next more))
+ (>= y (first more)))
+ false)))
+
+(defn ==
+ "Returns non-nil if nums all have the equivalent
+ value (type-independent), otherwise false"
+ {:inline (fn [x y] `(. clojure.lang.Numbers (equiv ~x ~y)))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x] true)
+ ([x y] (. clojure.lang.Numbers (equiv x y)))
+ ([x y & more]
+ (if (== x y)
+ (if (next more)
+ (recur y (first more) (next more))
+ (== y (first more)))
+ false)))
+
+(defn max
+ "Returns the greatest of the nums."
+ {:added "1.0"
+ :inline-arities >1?
+ :inline (nary-inline 'max)}
+ ([x] x)
+ ([x y] (. clojure.lang.Numbers (max x y)))
+ ([x y & more]
+ (reduce1 max (max x y) more)))
+
+(defn min
+ "Returns the least of the nums."
+ {:added "1.0"
+ :inline-arities >1?
+ :inline (nary-inline 'min)}
+ ([x] x)
+ ([x y] (. clojure.lang.Numbers (min x y)))
+ ([x y & more]
+ (reduce1 min (min x y) more)))
+
+(defn abs
+ {:doc "Returns the absolute value of a.
+ If a is Long/MIN_VALUE => Long/MIN_VALUE
+ If a is a double and zero => +0.0
+ If a is a double and ##Inf or ##-Inf => ##Inf
+ If a is a double and ##NaN => ##NaN"
+ :inline-arities #{1}
+ :inline (fn [a] `(clojure.lang.Numbers/abs ~a))
+ :added "1.11"}
+ [a]
+ (clojure.lang.Numbers/abs a))
+
+(defn dec'
+ "Returns a number one less than num. Supports arbitrary precision.
+ See also: dec"
+ {:inline (fn [x] `(. clojure.lang.Numbers (decP ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.Numbers (decP x)))
+
+(defn dec
+ "Returns a number one less than num. Does not auto-promote
+ longs, will throw on overflow. See also: dec'"
+ {:inline (fn [x] `(. clojure.lang.Numbers (~(if *unchecked-math* 'unchecked_dec 'dec) ~x)))
+ :added "1.2"}
+ [x] (. clojure.lang.Numbers (dec x)))
+
+(defn unchecked-inc-int
+ "Returns a number one greater than x, an int.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_int_inc ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.Numbers (unchecked_int_inc x)))
+
+(defn unchecked-inc
+ "Returns a number one greater than x, a long.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_inc ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.Numbers (unchecked_inc x)))
+
+(defn unchecked-dec-int
+ "Returns a number one less than x, an int.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_int_dec ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.Numbers (unchecked_int_dec x)))
+
+(defn unchecked-dec
+ "Returns a number one less than x, a long.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_dec ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.Numbers (unchecked_dec x)))
+
+(defn unchecked-negate-int
+ "Returns the negation of x, an int.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_int_negate ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.Numbers (unchecked_int_negate x)))
+
+(defn unchecked-negate
+ "Returns the negation of x, a long.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_minus ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.Numbers (unchecked_minus x)))
+
+(defn unchecked-add-int
+ "Returns the sum of x and y, both int.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_add ~x ~y)))
+ :added "1.0"}
+ [x y] (. clojure.lang.Numbers (unchecked_int_add x y)))
+
+(defn unchecked-add
+ "Returns the sum of x and y, both long.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_add ~x ~y)))
+ :added "1.0"}
+ [x y] (. clojure.lang.Numbers (unchecked_add x y)))
+
+(defn unchecked-subtract-int
+ "Returns the difference of x and y, both int.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_subtract ~x ~y)))
+ :added "1.0"}
+ [x y] (. clojure.lang.Numbers (unchecked_int_subtract x y)))
+
+(defn unchecked-subtract
+ "Returns the difference of x and y, both long.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_minus ~x ~y)))
+ :added "1.0"}
+ [x y] (. clojure.lang.Numbers (unchecked_minus x y)))
+
+(defn unchecked-multiply-int
+ "Returns the product of x and y, both int.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_multiply ~x ~y)))
+ :added "1.0"}
+ [x y] (. clojure.lang.Numbers (unchecked_int_multiply x y)))
+
+(defn unchecked-multiply
+ "Returns the product of x and y, both long.
+ Note - uses a primitive operator subject to overflow."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_multiply ~x ~y)))
+ :added "1.0"}
+ [x y] (. clojure.lang.Numbers (unchecked_multiply x y)))
+
+(defn unchecked-divide-int
+ "Returns the division of x by y, both int.
+ Note - uses a primitive operator subject to truncation."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_divide ~x ~y)))
+ :added "1.0"}
+ [x y] (. clojure.lang.Numbers (unchecked_int_divide x y)))
+
+(defn unchecked-remainder-int
+ "Returns the remainder of division of x by y, both int.
+ Note - uses a primitive operator subject to truncation."
+ {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_int_remainder ~x ~y)))
+ :added "1.0"}
+ [x y] (. clojure.lang.Numbers (unchecked_int_remainder x y)))
+
+(defn pos?
+ "Returns true if num is greater than zero, else false"
+ {:tag Boolean
+ :inline (fn [num] `(. clojure.lang.Numbers (isPos ~num)))
+ :added "1.0"}
+ [num] (. clojure.lang.Numbers (isPos num)))
+
+(defn neg?
+ "Returns true if num is less than zero, else false"
+ {
+ :inline (fn [num] `(. clojure.lang.Numbers (isNeg ~num)))
+ :added "1.0"}
+ [num] (. clojure.lang.Numbers (isNeg num)))
+
+(defn quot
+ "quot[ient] of dividing numerator by denominator."
+ {:added "1.0"
+ :static true
+ :inline (fn [x y] `(. clojure.lang.Numbers (quotient ~x ~y)))}
+ [num div]
+ (. clojure.lang.Numbers (quotient num div)))
+
+(defn rem
+ "remainder of dividing numerator by denominator."
+ {:added "1.0"
+ :static true
+ :inline (fn [x y] `(. clojure.lang.Numbers (remainder ~x ~y)))}
+ [num div]
+ (. clojure.lang.Numbers (remainder num div)))
+
+(defn rationalize
+ "returns the rational value of num"
+ {:added "1.0"
+ :static true}
+ [num]
+ (. clojure.lang.Numbers (rationalize num)))
+
+;;Bit ops
+
+(defn bit-not
+ "Bitwise complement"
+ {:inline (fn [x] `(. clojure.lang.Numbers (not ~x)))
+ :added "1.0"}
+ [x] (. clojure.lang.Numbers not x))
+
+
+(defn bit-and
+ "Bitwise and"
+ {:inline (nary-inline 'and)
+ :inline-arities >1?
+ :added "1.0"}
+ ([x y] (. clojure.lang.Numbers and x y))
+ ([x y & more]
+ (reduce1 bit-and (bit-and x y) more)))
+
+(defn bit-or
+ "Bitwise or"
+ {:inline (nary-inline 'or)
+ :inline-arities >1?
+ :added "1.0"}
+ ([x y] (. clojure.lang.Numbers or x y))
+ ([x y & more]
+ (reduce1 bit-or (bit-or x y) more)))
+
+(defn bit-xor
+ "Bitwise exclusive or"
+ {:inline (nary-inline 'xor)
+ :inline-arities >1?
+ :added "1.0"}
+ ([x y] (. clojure.lang.Numbers xor x y))
+ ([x y & more]
+ (reduce1 bit-xor (bit-xor x y) more)))
+
+(defn bit-and-not
+ "Bitwise and with complement"
+ {:inline (nary-inline 'andNot)
+ :inline-arities >1?
+ :added "1.0"
+ :static true}
+ ([x y] (. clojure.lang.Numbers andNot x y))
+ ([x y & more]
+ (reduce1 bit-and-not (bit-and-not x y) more)))
+
+
+(defn bit-clear
+ "Clear bit at index n"
+ {:added "1.0"
+ :static true}
+ [x n] (. clojure.lang.Numbers clearBit x n))
+
+(defn bit-set
+ "Set bit at index n"
+ {:added "1.0"
+ :static true}
+ [x n] (. clojure.lang.Numbers setBit x n))
+
+(defn bit-flip
+ "Flip bit at index n"
+ {:added "1.0
+ :static true"}
+ [x n] (. clojure.lang.Numbers flipBit x n))
+
+(defn bit-test
+ "Test bit at index n"
+ {:added "1.0"
+ :static true}
+ [x n] (. clojure.lang.Numbers testBit x n))
+
+
+(defn bit-shift-left
+ "Bitwise shift left"
+ {:inline (fn [x n] `(. clojure.lang.Numbers (shiftLeft ~x ~n)))
+ :added "1.0"}
+ [x n] (. clojure.lang.Numbers shiftLeft x n))
+
+(defn bit-shift-right
+ "Bitwise shift right"
+ {:inline (fn [x n] `(. clojure.lang.Numbers (shiftRight ~x ~n)))
+ :added "1.0"}
+ [x n] (. clojure.lang.Numbers shiftRight x n))
+
+(defn unsigned-bit-shift-right
+ "Bitwise shift right, without sign-extension."
+ {:inline (fn [x n] `(. clojure.lang.Numbers (unsignedShiftRight ~x ~n)))
+ :added "1.6"}
+ [x n] (. clojure.lang.Numbers unsignedShiftRight x n))
(defn integer?
"Returns true if n is an integer"
- {:added "1.0"
- :static true}
+ {:added "1.0"
+ :static true}
[n]
(or (instance? Int32 n) (instance? UInt32 n) ;;; Integer -> Int32, added UInt32
(instance? Int64 n) (instance? UInt64 n) ;;; Long -> Int64, added UInt64
(instance? clojure.lang.BigInt n)
(instance? BigInteger n)
(instance? Int16 n) (instance? UInt16 n) ;;; Short -> Int16, added UInt16
- (instance? Byte n) (instance? SByte n))) ;;; Added SByte test
-
-(defn even?
- "Returns true if n is even, throws an exception if n is not an integer"
- {:added "1.0"
- :static true}
- [n] (if (integer? n)
- (zero? (bit-and (clojure.lang.RT/uncheckedLongCast n) 1))
- (throw (ArgumentException. (str "Argument must be an integer: " n))))) ;;; IllegalArgumentException.
-
-(defn odd?
- "Returns true if n is odd, throws an exception if n is not an integer"
- {:added "1.0"
- :static true}
- [n] (not (even? n)))
-
-(defn int?
- "Return true if x is a fixed precision integer" ;;; DM: TODO: determine how or whether to handle unsigned types
- {:added "1.9"}
- [x] (or (instance? Int64 x) ;;; Long
- (instance? Int32 x) ;;; Integer
- (instance? Int16 x) ;;; Short
- (instance? Byte x)))
-
-(defn pos-int?
- "Return true if x is a positive fixed precision integer"
- {:added "1.9"}
- [x] (and (int? x)
- (pos? x)))
-
-(defn neg-int?
- "Return true if x is a negative fixed precision integer"
- {:added "1.9"}
- [x] (and (int? x)
- (neg? x)))
-
-(defn nat-int?
- "Return true if x is a non-negative fixed precision integer"
- {:added "1.9"}
- [x] (and (int? x)
- (not (neg? x))))
-
-(defn double?
- "Return true if x is a Double"
- {:added "1.9"}
- [x] (instance? Double x))
-
-;;
-
-(defn complement
- "Takes a fn f and returns a fn that takes the same arguments as f,
- has the same effects, if any, and returns the opposite truth value."
- {:added "1.0"
- :static true}
- [f]
- (fn
- ([] (not (f)))
- ([x] (not (f x)))
- ([x y] (not (f x y)))
- ([x y & zs] (not (apply f x y zs)))))
-
-(defn constantly
- "Returns a function that takes any number of arguments and returns x."
- {:added "1.0"
- :static true}
- [x] (fn [& args] x))
-
-(defn identity
- "Returns its argument."
- {:added "1.0"
- :static true}
- [x] x)
-
-;;Collection stuff
-
-;;list stuff
-(defn peek
- "For a list or queue, same as first, for a vector, same as, but much
- more efficient than, last. If the collection is empty, returns nil."
- {:added "1.0"
- :static true}
- [coll] (. clojure.lang.RT (peek coll)))
-
-(defn pop
- "For a list or queue, returns a new list/queue without the first
- item, for a vector, returns a new vector without the last item. If
- the collection is empty, throws an exception. Note - not the same
- as next/butlast."
- {:added "1.0"
- :static true}
- [coll] (. clojure.lang.RT (pop coll)))
-
-;;map stuff
-
-(defn map-entry? ;;; hoping this is correct. The equiv of Map$Entry is a struct, so not a base for anything.
- "Return true if x is a map entry" ;;; Given the way it is used, adding KeyValuePair