프로그래밍 605

명령행 인자 처리 예제 for Common Lisp

Common Lisp 언어 의 명령행 인자 처리 방법은 Common Lisp 의 구현체 마다 각각 그 방법이 다르다. 아래의 에제는 CLISP 에서 동작하는 명령행 처리 예제이다. CLISP 에서는 ext:*args* 라는 리스트(list)형 전역변수로 받는다. (length ext:*args*) 는 명령문에서 인자의 개수이다. parse-number 는 대부분의 Coomon Lisp 구현체에서 동작하는 (매우 짧은) 함수로서 스트링(string)을 부동소수점수(floating point number)로 변환하는 일을 한다. mapcar 와 apply 함수를 사용하여 (반복문 없이) 그 합을 구할 수 있게 하였다. GNU CLisp 에서는 명령행에서 실행시 명령행 인자들은 ext:*args* 라는 리스트..

구구단 출력 예제 for Common Lisp

Common Lisp 언어의 함수 정의 구문 양식은       (defun functionName(parameters)             block )이다.Common Lisp 언어의 반복문 양식은       (loop for varname from start to last by step do             block )이다. 여기서 by step 은 생략해도 되는데 이를 생력하면 반복될 때마다 varname 이 1씩 증가한다.소스 파일명: forTest.lisp------------------------------[소스 시작](defun printDan(dan)    (loop for i from 1 to 9 do        (format t "~D x ~D = ~D~%" dan i (* ..

Hello 예제 for Common Lisp

컨솔에 문자 출력하는 Common Lisp 구문은 (format f "문자열(스트링)~%") 이다. 여기서 ~%는 C 언어의 개행문자 "\n"에 해당한다. 이다. 여기서 개행문자 "\n"은 추가하지 않아도 된다. 소스 파일명: hello.lisp ------------------------------[소스 시작] (format t "Hello, world!~%") (quit) ------------------------------[소스 끝] ;; 윈도우 XP에 설치된 CLISP으로 실행하는 경우: 실행> clisp i i i i i i i ooooo o ooooooo ooooo ooooo I I I I I I I 8 8 8 8 8 o 8 8 I \ `+' / I 8 8 8 8 8 8 \ `-+-' / 8..

이진 파일을 읽어서 16진수로 보여주는 HexView 소스 with ErLang

ErLang 언어 소스: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Filename: testHexView_03.erl % % Compile: erlc testHexView_03.erl % Execute: erl -f [filename] -run testHexView_03 main -run init stop -noshell % % Date: 2013. 8. 24. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -module(testHexView_03). -export([main/0]). toHex(N) -> X1 = (N band 16#F0) bsr 4, X2 = N band 16#F, S1 = if X1 string:ch..

이진 파일을 읽어서 16진수로 보여주는 HexView 소스 with OCaml

OCaml 언어 소스: (* Filename: testHexView_02.ml Execute: ocaml testHexView_02.ml [filename] Or Compile: ocamlc -o testHexView_02 testHexView_02.ml Execute: ./testHexView_02 [filename] Or Compile: ocamlc -o testHexView_02.exe testHexView_02.ml Execute: testHexView_02 [filename] Date: 2013. 8. 20. *) open Printf;; let printUsage() = printf("Usgae: testHexView_02 [filename]\n");; let toHex n = let s = ..

이진 파일을 읽어서 16진수로 보여주는 HexView 소스 with Haskell

Haskell 언어 소스: {- Filename: testHexView_02.hs Purpose: Show hexadecimal values of the given file. Compile: ghc testHexView_02.hs Execute: testHexView_02 [filename] Date: 2013. 8. 20. -} module Main where import System.Directory import System.Exit import System.IO import System.Environment import Text.Printf import Data.Bits import Data.Char (ord) import Data.Char (chr) import Data.Array import D..

이진 파일을 읽어서 16진수로 보여주는 HexView 소스 with F#

F# 언어 소스: (* Filename: testHexView_02.fs * * Compile: fsc testHexView_02.fs * Execute: testHexView_02 [filename] * * Date: 2013. 8. 18. *) open System open System.IO let Value (c:char) = (int c) - (int 'A') + 1 let toHex n = let mutable s = "" let x1 = (n &&& 0xF0) >>> 4 let x2 = n &&& 0xF if x1 > 24 let x3 = (n &&& 0xF00000) >>> 20 let x4 = (n &&& 0xF0000) >>> 16 let x5 = (n &&& 0x..

프로그래밍/F# 2013.08.18

이진 파일을 읽어서 16진수로 보여주는 HexView 소스 with Octave

Octave 언어 소스: % Filename: testHexView_02.m % % Execute: octave -qf testHexView_02.m [filename] % % Date: 2013. 8. 18. function printUsage() printf("Usage: octave -qf testHexView_02.m [filename]\n"); endfunction function y = getFileSize(fd) n = ftell(fd); fseek(fd, 0, SEEK_END); x = ftell(fd); fseek(fd, n, SEEK_SET); y = x; endfunction function y = toHex(n) s = ""; x1 = bitshift(bitand(n, 0xF0), ..

이진 파일을 읽어서 16진수로 보여주는 HexView 소스 with Boo

Boo 언어 소스: # Filename: testHexView_02.boo # # Execute: booi testHexView_02.boo [filename] # # Or # # Compile: booc testHexView_02.boo # Execute: testHexView_02 [filename] # # Date: 2013. 8. 16. import System import System.IO def printUsage(): print "Usage: booi testHexView_02 [filename]" def isDirectory(path as string) as bool: fa = System.IO.File.GetAttributes(path) isDir = false if (fa & FileA..

프로그래밍/Boo 2013.08.16