Microsoft MVP성태의 닷넷 이야기
개발 환경 구성: 227. 닷넷 용 ClojureCLR 개발환경 설정 [링크 복사], [링크+제목 복사],
조회: 21213
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

닷넷 용 ClojureCLR 개발환경 설정

Clojure의 파일 확장자가 "CLJ"인데요. "C#", "LISP", "Java"의 약자를 딴 것이라고 합니다. 그래서인지 Clojure는 닷넷용으로도 포팅되어 있습니다. (단지, 자바의 릴리스에 비해 시기가 늦어질 뿐!)

clojure-clr (A port of Clojure to the CLR, part of the Clojure project)
; https://github.com/clojure/clojure-clr

release
; https://github.com/clojure/clojure-clr/releases

실제로 자바는 이미 1.6.0 버전이 stable 단계로 릴리즈되었지만 ClojureCLR은 1.6.0이 베타 1 단계에 접어들었습니다. (이것이 2월 23일의 이야기니까... 꽤나 느리게 진행되고 있다는 것을 짐작케 합니다.)

그래도 저는 언어 공부가 목적이므로 그냥 베타 단계이지만 1.6.0 버전을 설치해 보았습니다.

다운로드 받은 "clojure-clr-clojure-1.6.0-beta1.zip" 파일의 압축을 해제하면 "./Clojure" 폴더 밑에 ClojureCLR.sln 솔루션 파일이 있는데요. Visual Studio에서 로드하고 빌드하면 ./bin/3.5/Debug 폴더에 Clojure.Main.exe 및 기타 다양한 어셈블리들이 함께 출력됩니다.

어쨌든 실행하면 잘 됩니다.

c:\...\clojure-clr-clojure-1.6.0-beta1\bin\3.5\Debug>Clojure.Main.exe
Clojure 1.6.0-beta1
user=>

Visual Studio의 훌륭한 디버깅 환경을 생각하면, 만약 clojure 언어 자체의 컴파일러나 내부 구조에 관심이 있다면 clojureclr로 공부하시는 것도 좋은 선택이겠습니다.




그 외 "Clojure 언어의 윈도우 개발환경 설정"에서 다뤘던 것들을 동일하게 설명해 보면!

외부 clj 소스 코드를 로드하기 위한 load-file 명령어도 Clojure.Main.exe 파일이 있는 폴더를 기준으로 지정하면 됩니다.

; temp.clj 소스 코드 내용
; (defn hello [name] (str "Hello, " name))
; (hello "stu")
 
user=> (load-file "..\\sample\\temp.clj")
"Hello, stu"
user=>

Clojure.Main.exe가 실행되면서 처리하고 싶은 명령어가 있는 경우 -i 옵션을 이용해 지정하는 방법도 동일합니다.

c:\...\clojure-clr-clojure-1.6.0-beta1\bin\3.5\Debug>Clojure.Main.exe -i ..\sample\temp.clj -r
Clojure 1.6.0-beta1
user=> (hello "stu")
"Hello, stu"
user=>

아쉬운 점이 있다면 clojure.contrib의 닷넷 버전으로 컴파일된 DLL이 없다는 것입니다. (Java의 jar와 유사한) DLL로 패키징된 파일이 없어도 직접 소스 코드를 가져와서 사용하는 것도 가능하므로 clojure.contrib의 소스 코드에서 직접 가져오기를 시도해봤는데요. 일단 clojure-contrib 라이브러리를 다운로드 받고,

clojure-contrib
; http://code.google.com/p/clojure-contrib/downloads/list

압축을 푼 후 .\clojure-contrib-1.1.0\contrib\src\clojure 폴더 하위에 있는 contrib 폴더를 Clojure.Main.exe가 위치한 폴더의 하위에 있는 "clojure" 폴더 내에 복사하면 됩니다. 그리고 나서 str-utils를 사용해 보려고 했는데... 아쉽게도 오류가 발생하는 군요. ^^

user=> (use 'clojure.contrib.str-utils)
Bad type
CompilerException System.NullReferenceException: Object reference not set to aninstance of an object.
   at clojure.lang.Util.NameForType(Type t) in c:\...\clojure-clr-clojure-1.6.0-beta1\Clojure\Clojure\Lib\Util.cs:line 769
   at clojure.lang.Namespace.importClass(Type t) in c:\...\clojure-clr-clojure-1.6.0-beta1\Clojure\Clojure\Lib\Namespace.cs:line 339
   at clojure/contrib/str_utils$eval__35$loading__17106__auto____40__43.invoke() in eval:line 15
   at clojure/contrib/str_utils$eval__35__46.invoke() in eval:line 15
   at clojure.lang.Compiler.eval(Object form) in c:\...\clojure-clr-clojure-1.6.0-beta1\Clojure\Clojure\CljCompiler\Compiler.cs:line 999
   at clojure.lang.Compiler.eval(Object form) in c:\...\clojure-clr-clojure-1.6.0-beta1\Clojure\Clojure\CljCompiler\Compiler.cs:line 991
   at clojure.lang.Compiler.load(TextReader rdr, String sourcePath, String sourceName, String relativePath) in c:\...\clojure-clr-clojure-1.6.0-beta1\Clojure\Clojure\CljCompiler\Compiler.cs:line 1681, compiling: (c:\...\clojure-clr-clojure-1.6.0-beta1\bin\3.5\Debug\clojure\contrib\str_utils.clj:1:0)

그럴 수밖에 없는 것이, clojure 언어 자체는 Java에 독립적이지만 이를 이용해 만드는 라이브러리에는 Java의 기능을 쓰는 경우가 있어서 CLR 닷넷 환경에서는 사용이 불가능한 것입니다. 예를 들어, clojure.contrib.str-utils의 경우 소스 코드가 다음과 같이 java.util.regex에 의존하고 있는 것이지요.

; str_utils.clj 
(ns 
  #^{:author "Stuart Sierra",
     :doc "String utilities for Clojure"}
  clojure.contrib.str-utils
  (:import (java.util.regex Pattern)))

...[생략]...

그나마 위안을 삼는다면, clojure.contrib의 함수들 중에는 Java 종속적이지 않아서 부분적인 소스 코드 자체는 가져다 쓰는 것이 가능합니다. 가령, clojure.contrib.str-utils.clj에 포함된 str-join 함수는 소스 코드를 복사해서 ClojureCLR REPL에서 직접 실행할 수 있습니다.

user=> (defn str-join  
    "Returns a string of all elements in 'sequence', separated by  'separator'.  Like Perl's 'join'."  
    [separator sequence]  
    (apply str (interpose separator sequence))
)
#'user/str-join

user=> (str-join "0" "test")
"t0e0s0t"

말할 필요도 없이, 시중에 공개된 clojure 책을 clojureClr에서 실습할 때는 닷넷이란 점을 감안하고 실습하시면 됩니다. 예를 들어, 예외 타입도 Java가 아닌 닷넷의 것으로 대체되고,

user=> (/ 1 0)
ArithmeticException Divide by zero  clojure.lang.Numbers.divide (c:\...\clojure-clr-clojure-1.6.0-beta1\Clojure\Clojure\Lib\Numbers.cs:208)

따라서 Java 종속적인 코드에 대해서는 지원되는 메서드 유형도 다릅니다.

; Java의 printStackTrace는 .NET Exception 타입에 없기 때문에 오류가 나고,
; user=> (.printStackTrace *e)
; MissingMethodException Cannot find instance field/property/member name printStackTrace  .CallSite.Target (:0)

; 대신 .StackTrace 속성으로 접근하면 됩니다.
user=> (.StackTrace *e)
"   at clojure.lang.Numbers.divide(Object x, Object y) in c:\\...\\clojure-clr-clojure-1.6.0-beta1\\Clojure\\Clojure\\Lib\\Numbers.cs:line 208\r\n   
    at clojure.lang.Numbers.divide(Int64 x, Int64 y) in c:\\...\\clojure-clr-clojure-1.6.0-beta1\\Clojure\\Clojure\\Lib\\Numbers.cs:line 2938\r\n   
    at user$eval__84__89.invoke() in eval:line 9\r\n   
    at clojure.lang.Compiler.eval(Object form) in c:\\...\\clojure-clr-clojure-1.6.0-beta1\\Clojure\\Clojure\\CljCompiler\\Compiler.cs:line 999\r\n   
    at clojure/core$eval__15007.invoke(Object ) in core.clj:line 2923\r\n   
    at clojure/main$repl$read_eval_print__21542$fn__21555__21559.invoke() in main.clj:line 258\r\n   
    at clojure/main$repl$read_eval_print__21542__21562.invoke() in main.clj:line 258"

이 정도면, clojureClr에서도 clojure 언어를 배우기 위한 기초적인 개발 환경은 끝난 것 같군요. ^^ 그 외에 Visual Studio 내에서 확장 패키지 형식으로 vsClojure가 있는데,

lisp_learn_1.png

설치하고 나면 다음과 같이 구색은 갖춰져 있지만,

lisp_learn_2.png

어쨌든 clojure 언어 자체가 아직은 기존의 Visual C#으로 작업하던 성격의 응용 프로그램을 대체하기에는 그래서... 공부 용도로는 그냥 clojureClr 명령행으로도 충분합니다. ^^

마지막으로 clojure 라이브 코딩 영상하나 소개합니다. ^^

Live Coding by parksungmin 
; http://www.youtube.com/watch?v=yiHw_oeYj_A




참고로, Visual Studio에서 ClojureClr 솔루션을 빌드하려고 하면 다음과 같은 오류가 발생할 수 있습니다.

Package restore is disabled by default. To give consent, open the Visual Studio Options dialog, click on Package Manager node and check 'Allow NuGet to download missing packages during build.' You can also give consent by setting the environment variable 'EnableNuGetPackageRestore' to 'true'.


시키는 대로 하시면 됩니다. 근데 이상하군요. 이것을 해결하기 위해서는 2가지 옵션이 있는데, 하나는 "Tools" / "Options..." 메뉴 선택하고 "NuGet Package Manager" 범주에 가서 "Allow NuGet to download missing packages" 관련 옵션을 체크하는 것이라고 합니다. 하지만 실제로 그 옵션은 설정되어 있는데도 불구하고 동일한 오류가 발생합니다.

대신 환경 변수에 가서 "EnableNuGetPackageRestore"을 "true" 값으로 등록해 두고 Visual Studio를 다시 실행하면 정상적으로 빌드가 됩니다.

(그리고, Visual Studio 2010의 경우 기본적으로 Nuget이 없기 때문에 "Tools" / "Extension Manager..." 메뉴를 선택해 "NuGet Package Manager"를 다운로드 받아 설치해야 합니다.)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/27/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  113  114  115  116  117  118  [119]  120  ...
NoWriterDateCnt.TitleFile(s)
10949정성태4/28/201619875.NET Framework: 575. SharedDomain과 JIT 컴파일파일 다운로드1
10948정성태4/28/201623819.NET Framework: 574. .NET - 눈으로 확인하는 SharedDomain의 동작 방식 [3]파일 다운로드1
10947정성태4/27/201621682.NET Framework: 573. .NET CLR4 보안 모델 - 4. CLR4 보안 모델에서의 조건부 APTCA 역할파일 다운로드1
10946정성태4/26/201624510VS.NET IDE: 106. Visual Studio 2015 확장 - INI 파일을 위한 사용자 정의 포맷 기능 (Syntax Highlighting)파일 다운로드1
10945정성태4/26/201618266오류 유형: 327. VSIX 프로젝트 빌드 시 The "VsTemplatePaths" task could not be loaded from the assembly 오류 발생
10944정성태4/22/201619514디버깅 기술: 80. windbg - 풀 덤프 파일로부터 텍스트 파일의 내용을 찾는 방법
10943정성태4/22/201624367디버깅 기술: 79. windbg - 풀 덤프 파일로부터 .NET DLL을 추출/저장하는 방법 [1]
10942정성태4/19/201619671디버깅 기술: 78. windbg 사례 - .NET 예외가 발생한 시점의 오류 분석 [1]
10941정성태4/19/201619578오류 유형: 326. Error MSB8020 - The build tools for v120_xp (Platform Toolset = 'v120_xp') cannot be found.
10940정성태4/18/201622844Windows: 116. 프로세스 풀 덤프 시간을 줄여 주는 Process Reflection [3]
10939정성태4/18/201623878.NET Framework: 572. .NET APM 비동기 호출의 Begin...과 End... 조합 [3]파일 다운로드1
10938정성태4/13/201623443오류 유형: 325. 파일 삭제 시 오류 - Error 0x80070091: The directory is not empty.
10937정성태4/13/201631666Windows: 115. UEFI 모드로 윈도우 10 설치 가능한 USB 디스크 만드는 방법
10936정성태4/8/201642352Windows: 114. 삼성 센스 크로노스 7 노트북의 운영체제를 USB 디스크로 새로 설치하는 방법 [3]
10935정성태4/7/201626651웹: 32. Edge에서 Google Docs 문서 편집 시 한영 전환키가 동작 안하는 문제
10934정성태4/5/201625379디버깅 기술: 77. windbg의 콜스택 함수 인자를 쉽게 확인하는 방법 [1]
10933정성태4/5/201630986.NET Framework: 571. C# - 스레드 선호도(Thread Affinity) 지정하는 방법 [8]파일 다운로드1
10932정성태4/4/201623282VC++: 96. C/C++ 식 평가 - printf("%d %d %d\n", a, a++, a);
10931정성태3/31/201623557개발 환경 구성: 283. Hyper-V 내에 구성한 Active Directory 환경의 시간 구성 방법 [3]
10930정성태3/30/201621509.NET Framework: 570. .NET 4.5부터 추가된 CLR Profiler의 실행 시 Rejit 기능
10929정성태3/29/201631618.NET Framework: 569. ServicePointManager.DefaultConnectionLimit의 역할파일 다운로드1
10928정성태3/28/201637334.NET Framework: 568. ODP.NET의 완전한 닷넷 버전 Oracle ODP.NET, Managed Driver [2]파일 다운로드1
10927정성태3/25/201626543.NET Framework: 567. System.Net.ServicePointManager의 DefaultConnectionLimit 속성 설명
10926정성태3/24/201626083.NET Framework: 566. openssl의 PKCS#1 PEM 개인키 파일을 .NET RSACryptoServiceProvider에서 사용하는 방법 [10]파일 다운로드1
10925정성태3/24/201620386.NET Framework: 565. C# - Rabin-Miller 소수 생성 방법을 이용하여 RSACryptoServiceProvider의 개인키를 직접 채워보자 - 두 번째 이야기파일 다운로드1
10924정성태3/22/201621037오류 유형: 324. Visual Studio에서 Azure 클라우드 서비스 생성 시 Failed to initialize the PowerShell host 에러 발생
... 106  107  108  109  110  111  112  113  114  115  116  117  118  [119]  120  ...