clojure 和 Leiningen 环境安装

clojure环境安装

参考链接

windows 环境安装

说明:下面的操作都是在cmd命令窗口执行,也可通过PowerShell安装

1、执行以下命令:

PowerShell -Command "iwr -useb download.clojure.org/install/win-install-1.10.3.1087.ps1 | iex"

没有报错,但是显然是没有成功(使用PowerShell也有此问题),截图如下:
在这里插入图片描述
解决办法:
步骤1:访问上面命令中的链接,下载win-install-1.10.3.1087.ps1文件
步骤2:修改win-install-1.10.3.1087.ps1文件内容(注释掉6-8行):

#!/usr/bin/env pwsh
$ErrorActionPreference = 'Stop'
$Version = '1.10.3.1087'
$ClojureToolsUrl = "https://download.clojure.org/install/clojure-tools-$Version.zip"

#Write-Host 'Downloading Clojure tools' -ForegroundColor Gray
#[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls12'
#Invoke-WebRequest -Uri $ClojureToolsUrl -OutFile clojure-tools.zip

Write-Warning 'Clojure will install as a module in your PowerShell module path.'
Write-Host ''
Write-Host 'Possible install locations:'

$InstallLocations = $env:PSModulePath -split [IO.Path]::PathSeparator
for ($Index = 0; $Index -lt $InstallLocations.Length; $Index++) {
  Write-Host ('  {0}) {1}' -f ($Index + 1), $InstallLocations[$Index])
}
$Choice = Read-Host 'Enter number of preferred install location'
$DestinationPath = $InstallLocations[$Choice - 1]

Write-Host ''

$ExistingLocation = "$DestinationPath\ClojureTools"
if (Test-Path $ExistingLocation) {
  Write-Host 'Cleaning up existing install' -ForegroundColor Gray
  Remove-Item -Path $ExistingLocation -Recurse
}

Write-Host 'Installing PowerShell module'
Expand-Archive clojure-tools.zip -DestinationPath $DestinationPath

Write-Host 'Removing download'
Remove-Item clojure-tools.zip

Write-Host 'Clojure now installed. Use "clj -h" for help.' -ForegroundColor Green

步骤3:在文件同级目录下执行以下命令:

powershell.exe -noprofile -executionpolicy bypass -file .\win-install-1.10.3.1087.ps1

安装成功,截图如下:
在这里插入图片描述

2、验证是否成功 执行命令PowerShell clj -h

D:\software\tools\clojure>PowerShell clj -h
Version: 1.10.3.1087

You use the Clojure tools ('clj' or 'clojure') to run Clojure programs
on the JVM, e.g. to start a REPL or invoke a specific function with data.
The Clojure tools will configure the JVM process by defining a classpath
(of desired libraries), an execution environment (JVM options) and
specifying a main class and args.

Using a deps.edn file (or files), you tell Clojure where your source code
resides and what libraries you need. Clojure will then calculate the full
set of required libraries and a classpath, caching expensive parts of this
process for better performance.

The internal steps of the Clojure tools, as well as the Clojure functions
you intend to run, are parameterized by data structures, often maps. Shell
command lines are not optimized for passing nested data, so instead you
will put the data structures in your deps.edn file and refer to them on the
command line via 'aliases' - keywords that name data structures.

'clj' and 'clojure' differ in that 'clj' has extra support for use as a REPL
in a terminal, and should be preferred unless you don't want that support,
then use 'clojure'.

Usage:
  Start a REPL   clj     [clj-opt*] [-Aaliases] [init-opt*]
  Exec fn(s)     clojure [clj-opt*] -X[aliases] a/fn? [kpath v]* kv-map?
  Run tool       clojure [clj-opt*] -T[name|aliases] a/fn [kpath v] kv-map?
  Run main       clojure [clj-opt*] -M[aliases] [init-opt*] [main-opt] [arg*]
  Prepare        clojure [clj-opt*] -P [other exec opts]

exec-opts:
  -Aaliases      Use concatenated aliases to modify classpath
  -X[aliases]    Use concatenated aliases to modify classpath or supply exec fn/args
  -T[name|aliases]  Invoke tool by name or via aliases ala -X
  -M[aliases]    Use concatenated aliases to modify classpath or supply main opts
  -P             Prepare deps - download libs, cache classpath, but don't exec

clj-opts:
  -Jopt          Pass opt through in java_opts, ex: -J-Xmx512m
  -Sdeps EDN     Deps data to use as the final deps file
  -Spath         Compute classpath and echo to stdout only
  -Spom          Generate (or update) pom.xml with deps and paths
  -Stree         Print dependency tree
  -Scp CP        Do NOT compute or cache classpath, use this one instead
  -Srepro        Use only the local deps.edn (ignore other config files)
  -Sforce        Force recomputation of the classpath (don't use the cache)
  -Sverbose      Print important path info to console
  -Sdescribe     Print environment and command parsing info as data
  -Sthreads      Set specific number of download threads
  -Strace        Write a trace.edn file that traces deps expansion
  --             Stop parsing dep options and pass remaining arguments to clojure.main
  --version      Print the version to stdout and exit
  -version       Print the version to stderr and exit

init-opt:
  -i, --init path     Load a file or resource
  -e, --eval string   Eval exprs in string; print non-nil values
  --report target     Report uncaught exception to "file" (default), "stderr", or "none"

main-opt:
  -m, --main ns-name  Call the -main function from namespace w/args
  -r, --repl          Run a repl
  path                Run a script from a file or resource
  -                   Run a script from standard input
  -h, -?, --help      Print this help message and exit

Programs provided by :deps alias:
 -X:deps mvn-install       Install a maven jar to the local repository cache
 -X:deps git-resolve-tags  Resolve git coord tags to shas and update deps.edn
 -X:deps find-versions     Find available versions of a library
 -X:deps prep              Prepare all unprepped libs in the dep tree

For more info, see:
  https://clojure.org/guides/deps_and_cli
  https://clojure.org/reference/repl_and_main

D:\software\tools\clojure>

3、powershell -command clj 命令执行报错:

在这里插入图片描述
解决办法参考https://blog.csdn.net/sjw_night/article/details/111665665
步骤1:用管理员打开cmd窗口,执行以下命令:

PowerShell  set-executionpolicy remotesigned

然后执行 powershell -command clj 命令:
第一次执行此命令,命令行窗口会输出下载文件的日志。下图代码是第二次执行后的输出。

C:\Users\User>powershell -command clj
Clojure 1.10.3
user=>

运行测试

D:\software\tools\clojure>powershell -command clj
Clojure 1.10.3
user=> (+ 3 4)
7
user=>

leiningen 安装

参考链接

脚本lein.bat(不易下载,在此处保存)

@echo off

setLocal EnableExtensions EnableDelayedExpansion

set LEIN_VERSION=2.9.8

if "%LEIN_VERSION:~-9%" == "-SNAPSHOT" (
    set SNAPSHOT=YES
) else (
    set SNAPSHOT=NO
)

set ORIGINAL_PWD=%CD%
:: If ORIGINAL_PWD ends with a backslash (such as C:\),
:: we need to escape it with a second backslash.
if "%ORIGINAL_PWD:~-1%x" == "\x" set "ORIGINAL_PWD=%ORIGINAL_PWD%\"

call :FIND_DIR_CONTAINING_UPWARDS project.clj
if "%DIR_CONTAINING%" neq "" cd "%DIR_CONTAINING%"

:: LEIN_JAR and LEIN_HOME variables can be set manually.
:: Only set LEIN_JAR manually if you know what you are doing.
:: Having LEIN_JAR pointing to one version of Leiningen as well as
:: having a different version in PATH has been known to cause problems.

if "x%LEIN_HOME%" == "x" (
    set LEIN_HOME=!USERPROFILE!\.lein
)
SET RC=1

::if "x%LEIN_JAR%" == "x" set "LEIN_JAR=!LEIN_HOME!\self-installs\leiningen-!LEIN_VERSION!-standalone.jar"
if "x%LEIN_JAR%" == "x" set "LEIN_JAR=D:\workspace\IdeaProjects\clojurespace\lein\leiningen-2.9.8-standalone.jar"

if "%1" == "self-install" goto SELF_INSTALL
if "%1" == "upgrade"      goto UPGRADE
if "%1" == "downgrade"    goto UPGRADE

if not exist "%~dp0..\src\leiningen\version.clj" goto RUN_NO_CHECKOUT

    :: Running from source checkout.
    call :SET_LEIN_ROOT "%~dp0.."


	set "bootstrapfile=!LEIN_ROOT!\leiningen-core\.lein-bootstrap"
	rem in .lein-bootstrap there is only one line where each path is concatenated to each other via a semicolon, there's no semicolon at the end
	rem each path is NOT inside double quotes and may contain spaces (even semicolons but this is not supported here) in their names, 
	rem  but they won't/cannot contain double quotes " or colons :  in their names (at least on windows it's not allowed/won't work)
	
	rem tested when folders contain spaces and when LEIN_ROOT contains semicolon
	
	
	if not "x%DEBUG%" == "x" echo LEIN_ROOT=!LEIN_ROOT!
	
	rem if not "%LEIN_ROOT:;=%" == "%LEIN_ROOT%" (

	
	rem oddly enough /G:/ should've worked but doesn't where / they say it's console
	rem findstr is C:\Windows\System32\findstr.exe
	echo.!LEIN_ROOT! | findstr /C:";" >nul 2>&1 && (
		rem aka errorlevel is 0 aka the string ";" was found
		echo Your folder structure !LEIN_ROOT! contains at least one semicolon in its name
		echo This is not allowed and would break things with the generated bootstrap file
		echo Please correct this by renaming the folders to not contain semicolons in their name
		del !bootstrapfile! >nul 2>&1
		echo You'll also have to recreate the bootstrap file just to be sure it has semicolon-free names inside
		echo the bootstrap file ^(which was just deleted^) is: !bootstrapfile!
		echo  and the info on how to do that is:
		goto RUN_BOOTSTRAP
	)

	if not exist !bootstrapfile! goto NO_DEPENDENCIES

	findstr \^" "!bootstrapfile!" >nul 2>&1
	if errorlevel 1 goto PARSE_BOOTSTRAPFILE
		echo double quotes detected inside file: !bootstrapfile!
		echo this should not be happening
		goto RUN_BOOTSTRAP

:PARSE_BOOTSTRAPFILE
rem will proceed to set LEIN_LIBS and surround each path from bootstrap file in double quotes and separate it from others with a semicolon
rem the paths inside the bootstrap file do not already contain double quotes but may contain spaces
	rem note worthy: the following won't work due to a hard 1022bytes limit truncation in the variable that was set
	rem set /p LEIN_LIBS=<!bootstrapfile!
	rem so this will work instead:
	rem for /f "usebackq delims=" %%j in (!bootstrapfile!) do set LEIN_LIBS=%%j
	rem just  set LEIN_LIBS="%%j"  is uglier/hacky but would also work here instead of the below:
	for /f "usebackq delims=" %%j in ("!bootstrapfile!") do (
		set tmpline=%%j
		call :PROCESSPATH
	)

	rem remove trailing semicolon, if any
	if "!LEIN_LIBS:~-1!x" == ";x" SET LEIN_LIBS=!LEIN_LIBS:~0,-1!
	if not "x%DEBUG%" == "x" echo LEIN_LIBS=!LEIN_LIBS!

    if "x!LEIN_LIBS!" == "x" goto NO_DEPENDENCIES


	rem semicolons in pathes are not supported, spaces are supported by quoting CLASSPATH as a whole
	rem (no end semicolon required)
    set CLASSPATH=!LEIN_LIBS!;!LEIN_ROOT!\src;!LEIN_ROOT!\resources

    :: Apply context specific CLASSPATH entries
    if exist "%~dp0..\.lein-classpath" (
        for /f "tokens=* delims= " %%i in ("%~dp0..\.lein-classpath") do (
            set CONTEXT_CP=%%i
        )

        if NOT "x!CONTEXT_CP!"=="x" (
            set CLASSPATH=!CONTEXT_CP!;!CLASSPATH!
        )
    )
    goto SETUP_JAVA

:RUN_NO_CHECKOUT

    :: Not running from a checkout.
    if not exist "%LEIN_JAR%" goto NO_LEIN_JAR
    set CLASSPATH=%LEIN_JAR%
  
    if exist ".lein-classpath" (
        for /f "tokens=* delims= " %%i in (.lein-classpath) do (
            set CONTEXT_CP=%%i
        )

        if NOT "x!CONTEXT_CP!"=="x" (
            set CLASSPATH=!CONTEXT_CP!;!CLASSPATH!
        )
    )

:SETUP_JAVA

if not "x%DEBUG%" == "x" echo CLASSPATH=!CLASSPATH!
:: ##################################################

if "x!JAVA_CMD!" == "x" set JAVA_CMD=java
if "x!LEIN_JAVA_CMD!" == "x" set LEIN_JAVA_CMD=%JAVA_CMD%

rem remove quotes from around java commands
for /f "usebackq delims=" %%i in ('!JAVA_CMD!') do set JAVA_CMD=%%~i
for /f "usebackq delims=" %%i in ('!LEIN_JAVA_CMD!') do set LEIN_JAVA_CMD=%%~i

if "x%JVM_OPTS%" == "x" set JVM_OPTS=%JAVA_OPTS%
goto RUN

:DownloadFile
set LAST_HTTP_CLIENT=
rem parameters: TargetFileName Address
if "x%HTTP_CLIENT%" == "x" goto TRY_POWERSHELL
    %HTTP_CLIENT% %1 %2
    SET RC=%ERRORLEVEL%
    goto EXITRC

:TRY_POWERSHELL
call powershell -? >nul 2>&1
if NOT ERRORLEVEL 0 goto TRY_WGET
    set LAST_HTTP_CLIENT=powershell
    rem By default: Win7 = PS2, Win 8.0 = PS3 (maybe?), Win 8.1 = PS4, Win10 = PS5
    powershell -Command "& {param($a,$f) if (($PSVersionTable.PSVersion | Select-Object -ExpandProperty Major) -lt 4) { exit 111; } else { $client = New-Object System.Net.WebClient; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $client.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials; $client.DownloadFile($a, $f); }}" ""%2"" ""%1""
    SET RC=%ERRORLEVEL%
    goto EXITRC

:TRY_WGET
call wget --help >nul 2>&1
if NOT ERRORLEVEL 0 goto TRY_CURL
    set LAST_HTTP_CLIENT=wget
    call wget -O %1 %2
    SET RC=%ERRORLEVEL%
    goto EXITRC

:TRY_CURL
call curl --help >nul 2>&1
if NOT ERRORLEVEL 0 GOTO NO_HTTP_CLIENT
    rem We set CURL_PROXY to a space character below to pose as a no-op argument
    set LAST_HTTP_CLIENT=curl
    set CURL_PROXY= 
    if NOT "x%HTTPS_PROXY%" == "x" set CURL_PROXY="-x %HTTPS_PROXY%"
    call curl %CURL_PROXY% -f -L -o  %1 %2
    SET RC=%ERRORLEVEL%
    goto EXITRC

:NO_LEIN_JAR
echo.
echo %LEIN_JAR% can not be found.
echo You can try running "lein self-install"
echo or change LEIN_JAR environment variable
echo or edit lein.bat to set appropriate LEIN_JAR path.
echo.
goto EXITRC

:NO_DEPENDENCIES
echo.
echo Leiningen is missing its dependencies.
:RUN_BOOTSTRAP
echo Please run "lein bootstrap" in the leiningen-core/ directory
echo with a stable release of Leiningen. See CONTRIBUTING.md for details.
echo.
goto EXITRC

:SELF_INSTALL
if exist "%LEIN_JAR%" (
    echo %LEIN_JAR% already exists. Delete and retry.
    goto EXITRC
)

for %%f in ("%LEIN_JAR%") do set LEIN_INSTALL_DIR="%%~dpf"
if not exist %LEIN_INSTALL_DIR% mkdir %LEIN_INSTALL_DIR%

echo Downloading Leiningen now...

set LEIN_JAR_URL=https://github.com/technomancy/leiningen/releases/download/%LEIN_VERSION%/leiningen-%LEIN_VERSION%-standalone.jar
call :DownloadFile "%LEIN_JAR%.pending" "%LEIN_JAR_URL%"
SET RC=%ERRORLEVEL%
if not %RC% == 0 goto DOWNLOAD_FAILED
if not exist "%LEIN_JAR%.pending" goto DOWNLOAD_FAILED
move /y "%LEIN_JAR%.pending" "%LEIN_JAR%" >nul 2>&1
SET RC=%ERRORLEVEL%
goto EXITRC

:DOWNLOAD_FAILED
SET RC=3
if "%ERRORLEVEL%" == "111" (
    echo.
    echo You seem to be using an old version of PowerShell that
    echo can't download files via TLS 1.2.
    echo Please upgrade your PowerShell to at least version 4.0, e.g. via
    echo https://www.microsoft.com/en-us/download/details.aspx?id=50395
    echo.
    echo Alternatively you can manually download
    echo %LEIN_JAR_URL%
    echo and save it as
    echo %LEIN_JAR%
    echo.
    echo If you have "curl" or "wget" you can try setting the HTTP_CLIENT
    echo variable, but the TLS problem might still persist.
    echo.
    echo   a^) set HTTP_CLIENT=wget -O
    echo   b^) set HTTP_CLIENT=curl -f -L -o
    echo.
    echo NOTE: Make sure to *not* add double quotes when setting the value
    echo       of HTTP_CLIENT
    goto EXITRC
)
SET RC=3
del "%LEIN_JAR%.pending" >nul 2>&1
echo.
echo Failed to download %LEIN_JAR_URL%
echo.
echo It is possible that the download failed due to "powershell", 
echo "curl" or "wget"'s inability to retrieve GitHub's security certificate.
echo.

if "%LAST_HTTP_CLIENT%" == "powershell" (
  echo The PowerShell failed to download the latest Leiningen version.
  echo Try to use "curl" or "wget" to download Leiningen by setting up
  echo the HTTP_CLIENT environment variable with one of the following 
  echo values:
  echo.
  echo   a^) set HTTP_CLIENT=wget -O
  echo   b^) set HTTP_CLIENT=curl -f -L -o
  echo.
  echo NOTE: Make sure to *not* add double quotes when setting the value
  echo       of HTTP_CLIENT
)

if "%LAST_HTTP_CLIENT%" == "curl" (
  echo Curl failed to download the latest Leiningen version.
  echo Try to use "wget" to download Leiningen by setting up
  echo the HTTP_CLIENT environment variable with one of the following 
  echo values:
  echo.
  echo   a^) set HTTP_CLIENT=wget -O
  echo.
  echo NOTE: Make sure to *not* add double quotes when setting the value
  echo       of HTTP_CLIENT
  echo. 
  echo If neither curl nor wget can download Leiningen, please seek
  echo for help on Leiningen's GitHub project issues page.
)

if "%LAST_HTTP_CLIENT%" == "wget" (
  echo Curl failed to download the latest Leiningen version.
  echo Try to use "wget" to download Leiningen by setting up
  echo the HTTP_CLIENT environment variable with one of the following 
  echo values:
  echo.
  echo.   a^) set HTTP_CLIENT=curl -f -L -o
  echo.
  echo NOTE: make sure *not* to add double quotes to set the value of 
  echo       HTTP_CLIENT
  echo. 
  echo If neither curl nor wget can download Leiningen, please seek
  echo for help on Leiningen's GitHub project issues page.
)

if %SNAPSHOT% == YES echo See README.md for SNAPSHOT build instructions.
echo.
goto EOF


:UPGRADE
set LEIN_BAT=%~dp0%~nx0
set TARGET_VERSION=%2
if "x%2" == "x" set TARGET_VERSION=stable
echo The script at %LEIN_BAT% will be upgraded to the latest %TARGET_VERSION% version.
set /P ANSWER=Do you want to continue (Y/N)?
if /i {%ANSWER%}=={y}   goto YES_UPGRADE
if /i {%ANSWER%}=={yes} goto YES_UPGRADE
echo Aborted.
goto EXITRC


:YES_UPGRADE
echo Downloading latest Leiningen batch script...

set LEIN_BAT_URL=https://github.com/technomancy/leiningen/raw/%TARGET_VERSION%/bin/lein.bat
set TEMP_BAT=%~dp0temp-lein-%RANDOM%%RANDOM%.bat
call :DownloadFile "%LEIN_BAT%.pending" "%LEIN_BAT_URL%"
if ERRORLEVEL 0 goto EXEC_UPGRADE
    del "%LEIN_BAT%.pending" >nul 2>&1
    echo Failed to download %LEIN_BAT_URL%
    goto EXITRC
:EXEC_UPGRADE
move /y "%LEIN_BAT%.pending" "%TEMP_BAT%" >nul 2>&1
echo.
echo Upgrading...
set LEIN_JAR=
call "%TEMP_BAT%" self-install
(
   rem This is self-modifying batch code. Use brackets to pre-load the exit command.
   rem This way, script execution does not depend on whether the replacement script
   rem has that command at the *very same* file position as the calling batch file.
   move /y "%TEMP_BAT%" "%LEIN_BAT%" >nul 2>&1
   exit /B %ERRORLEVEL%
)

:NO_HTTP_CLIENT
echo.
echo ERROR: Neither PowerShell, Wget, or Curl could be found.
echo        Make sure at least one of these tools is installed
echo        and is in PATH. You can get them from URLs below:
echo.
echo PowerShell: "http://www.microsoft.com/powershell"

rem echo Wget:       "http://users.ugent.be/~bpuype/wget/"
rem Note: Stale URL. HTTP 404.
rem Alternative: wget64.exe compiled by J. Simoncic, rename to wget.exe
rem MD5 1750c130c5daca8b347d3f7e34824c9b
rem Check: https://www.virustotal.com/en/file/abf507f8240ed41aac74c9df6de558c88c2f11d7770f02.8.4-SNAPSHOT5f1cc544b9c08b/analysis/
echo Wget:       "https://eternallybored.org/misc/wget/"

echo Curl:       "http://curl.haxx.se/dlwiz/?type=bin&os=Win32&flav=-&ver=2000/XP"
echo.
goto EXITRC


:SET_LEIN_ROOT
set LEIN_ROOT=%~f1
goto EOF

:: Find directory containing filename supplied in first argument
:: looking in current directory, and looking up the parent
:: chain until we find it, or run out
:: returns result in %DIR_CONTAINING%
:: empty string if we don't find it
:FIND_DIR_CONTAINING_UPWARDS
set DIR_CONTAINING=%CD%
set LAST_DIR=

:LOOK_AGAIN
if "%DIR_CONTAINING%" == "%LAST_DIR%" (
    :: didn't find it
    set DIR_CONTAINING=
    goto EOF
)

if EXIST "%DIR_CONTAINING%\%1" (
    :: found it - use result in DIR_CONTAINING
    goto EOF
)

set LAST_DIR=%DIR_CONTAINING%
call :GET_PARENT_PATH "%DIR_CONTAINING%\.."
set DIR_CONTAINING=%PARENT_PATH%
goto LOOK_AGAIN

:GET_PARENT_PATH
set PARENT_PATH=%~f1
goto EOF


:RUN
:: We need to disable delayed expansion here because the %* variable
:: may contain bangs (as in test!). There may also be special
:: characters inside the TRAMPOLINE_FILE.
setLocal DisableDelayedExpansion

set "TRAMPOLINE_FILE=%TEMP%\lein-trampoline-%RANDOM%.bat"
del "%TRAMPOLINE_FILE%" >nul 2>&1

set ERRORLEVEL=
set RC=0
"%LEIN_JAVA_CMD%" -client %LEIN_JVM_OPTS% ^
 -Dfile.encoding=UTF-8 ^
 -Dclojure.compile.path="%DIR_CONTAINING%/target/classes" ^
 -Dleiningen.original.pwd="%ORIGINAL_PWD%" ^
 -cp "%CLASSPATH%" clojure.main -m leiningen.core.main %*
SET RC=%ERRORLEVEL%
if not %RC% == 0 goto EXITRC

if not exist "%TRAMPOLINE_FILE%" goto EOF
call "%TRAMPOLINE_FILE%"
del "%TRAMPOLINE_FILE%" >nul 2>&1
goto EOF


:PROCESSPATH
rem will surround each path with double quotes before appending it to LEIN_LIBS
	for /f "tokens=1* delims=;" %%a in ("%tmpline%") do (
		set LEIN_LIBS=!LEIN_LIBS!"%%a";
		set tmpline=%%b
	)
	if not "%tmpline%" == "" goto PROCESSPATH
	goto EOF

:EXITRC
exit /B %RC%

:EOF

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Clojure 和 Python 是两种不同的编程语言,它们具有不同的设计哲学和特点。以下是对 Clojure 和 Python 进行比较的一些方面: 1. 语法和风格: - Clojure 是一种 Lisp 方言,其语法简洁、统一且拥有强大的宏系统。它使用括号表示表达式,具有强调函数式编程和不可变性的风格。 - Python 的语法更接近自然语言,使用缩进来表示代码块,具有直观和易读的风格。它既支持面向对象编程,也支持函数式编程。 2. 类型系统: - Clojure 是一种动态类型语言,变量的类型可以在运行时改变。它采用了基于值的不可变数据结构,并通过特定的函数操作来实现数据转换和处理。 - Python 也是一种动态类型语言,但它还支持静态类型检查(通过类型注解)。它使用了更传统的可变数据结构,并提供了丰富的内置数据类型和操作。 3. 并发和并行处理: - Clojure 在语言层面上支持并发和并行处理。它提供了一些内置的机制(如原子操作、锁和通道)来处理共享状态和并发访问。 - Python 的并发和并行处理需要借助于第三方库(如 threading、multiprocessing 和 asyncio)来实现。它提供了多线程和多进程编程的支持,以及异步编程模型。 4. 生态系统和库支持: - Python 拥有非常庞大和活跃的生态系统,有丰富的第三方库和工具可供选择,用于各种领域的开发,如科学计算、Web 开发、数据分析等。 - Clojure 的生态系统相对较小,但也有一些优秀的库和工具可供使用。它可以与 Java 生态系统进行互操作,可以利用 Java 的库和工具来扩展功能。 总体来说,Clojure 和 Python 在语法、类型系统和并发处理方面存在差异。Python 是一种通用的、易于学习和使用的语言,适合于快速开发和脚本编写。Clojure 则更适合于函数式编程和并发处理,对于处理大规模数据和构建高性能应用程序具有优势。选择哪种语言取决于具体的需求和个人偏好。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值