Programming/lisp2013. 1. 14. 23:04
lisp는 이름 그대로 LISt Processing으로
LIST를 기반으로 작업하게 된다.

자료구조에서 배우던 linked list를 이용해서 자료를 저장하게 되는데
C언어에서 항상 문자열은 0x00 혹은 \0으로 끝맺듯
list 도 마지막은 NIL로 표기를 하게 된다.

아래는 NIL로 끝나지 않는 리스트와 NIL로 끝나는 리스트를 만든것으로
. 은 NIL로 끝나지 않는 리스트를 의미하게 된다. 
[1]> '(1 . 2)
(1 . 2)
[2]> (cons 1 2)
(1 . 2)
[3]> '(1 2)
(1 2)
[4]> (cons 1 (cons 2 NIL))
(1 2)
 

last는 안되고 아무튼 rest는 남은걸 나타내는 것이기 때문에 가능한 것 같은데
(1 2)에 대한 rest 두번은 NIL이 나오고
(1 . 2) 에 대한 rest 두번은 존재하지 않기 때문에 에러가 발생하게 된다.
[6]> (rest (rest '(1 2)))
NIL
[6]> (rest (rest '(1 . 2)))

*** - REST: 2 is not a list
The following restarts are available:
ABORT          :R1      Abort debug loop
ABORT          :R2      Abort main loop
[7]> (rest '(1 . 2))
2


그나저나.. 책에 의하면 아래와 같이 뜬다고 하는데
> (defparameter foo '(1 2 3))
FOO
> (setf (cdddr foo) foo)
#1=(1 2 3 . #1#) 

내가 사용하는 clisp 2.49에서는 뻗어버린다 -_-
  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         8           8      ooooo   8oooo
    `-__|__-'        8         8           8           8  8
        |            8     o   8           8     o     8  8
  ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8

Welcome to GNU CLISP 2.49 (2010-07-07) <http://clisp.cons.org/>

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2010

Type :h and hit Enter for context help.
 
[12]> (defparameter foo '(1 2 3))
FOO
[13]> (setf (cdddr foo) foo)
^C
*** - Ctrl-C: User break
The following restarts are available:

*** - handle_fault error2 ! address = 0x68457000 not in [0x65de5658,0x68457000) !
SIGSEGV cannot be cured. Fault address = 0x68457000.
GC count: 47
Space collected by GC: 0 355764032
Run time: 40 918556
Real time: 164 950564
GC time: 23 933489
Permanently allocated: 94080 bytes.
Currently in use: 1194294496 bytes.
Free space: 12 bytes. 


'Programming > lisp' 카테고리의 다른 글

xlisp  (0) 2013.01.16
lisp 연관리스트  (0) 2013.01.14
lisp #  (0) 2013.01.11
만들면서 배우는 리스프 프로그래밍  (2) 2013.01.09
lisp 전역변수 / 지역변수  (0) 2013.01.09
Posted by 구차니
Programming/lisp2013. 1. 11. 17:15
#으로 시작하는 매크로인데
공부하면서 접하게 되는건 function 을 대체하는 #' 정도?

2012/12/05 - [Programming/lisp] - lisp - #' 와 '

 In addition, the first character may not be '#' (non-terminating macro character), nor may the symbol have identical syntax with a numeric literal.  Uppercase and lowercase characters are not distinguished within symbol names because, by default, lowercase characters are mapped to uppercase on input.

Standard Non-Terminating Macro Characters
-----------------------------------------
#
[링크 : http://psg.com/~dlamkins/sl/chapter03-11.html]

#
 
This is a dispatching macro character. It reads an optional digit string and then one more character, and uses that character to select a function to run as a macro-character function.
The # character also happens to be a non-terminating macro character. This is completely independent of the fact that it is a dispatching macro character; it is a coincidence that the only standard dispatching macro character in Common Lisp is also the only standard non-terminating macro character.

See the next section for predefined # macro-character constructions.

[링크 : http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node190.html] 

Table 22-4: Standard # Macro Character Syntax
 
#!  undefined *                #<backspace>  signals error 
#"  undefined                  #<tab>        signals error 
##  reference to #= label      #<newline>    signals error 
#$  undefined                  #<linefeed>   signals error 
#%  undefined                  #<page>       signals error 
#&  undefined                  #<return>     signals error 
#'  function abbreviation      #<space>      signals error 
#(  simple vector              #+      read-time conditional 
#)  signals error              #-      read-time conditional 
#*  bit-vector                 #.      read-time evaluation 
#,  load-time evaluation       #/      undefined 
#0  used for infix arguments   #A, #a  array 
#1  used for infix arguments   #B, #b  binary rational 
#2  used for infix arguments   #C, #c  complex number 
#3  used for infix arguments   #D, #d  undefined 
#4  used for infix arguments   #E, #e  undefined 
#5  used for infix arguments   #F, #f  undefined 
#6  used for infix arguments   #G, #g  undefined 
#7  used for infix arguments   #H, #h  undefined 
#8  used for infix arguments   #I, #i  undefined 
#9  used for infix arguments   #J, #j  undefined 
#:  uninterned symbol          #K, #k  undefined 
#;  undefined                  #L, #l  undefined 
#<  signals error              #M, #m  undefined 
#=  label following object     #N, #n  undefined 
#>  undefined                  #O, #o  octal rational 
#?  undefined *                #P, #p  pathname 
#@  undefined                  #Q, #q  undefined 
#[  undefined *                #R, #r  radix-n rational 
#\  character object           #S, #s  structure 
#]  undefined *                #T, #t  undefined 
#^  undefined                  #U, #u  undefined 
#_  undefined                  #V, #v  undefined 
#`  undefined                  #W, #w  undefined 
#{  undefined *                #X, #x  hexadecimal rational 
#|  balanced comment           #Y, #y  undefined 
#}  undefined *                #Z, #z  undefined    
#~  undefined                  #<rubout> undefined
 

'Programming > lisp' 카테고리의 다른 글

lisp 연관리스트  (0) 2013.01.14
lisp의 con cell 과 NIL  (0) 2013.01.14
만들면서 배우는 리스프 프로그래밍  (2) 2013.01.09
lisp 전역변수 / 지역변수  (0) 2013.01.09
lisp car / cdr  (0) 2013.01.03
Posted by 구차니
Programming/lisp2013. 1. 9. 22:37
아직 전부를 다읽은건 아니지만
대충 훑어 본바로서는 입문용으로 쓰기에는 약간 난이도가 있지만
리스프를 약간이라도 이해한 사람이라면 단시간에 높은 레벨에 까지 이를수 있을듯한 책이다.

2011년 11월 27일 초판이고, 3.5만원이라 조금 비싸지만
가지고 있을만한 가치가 있는 책이다.
(일단은 구립도서관에서 빌려왔지만 ^^;)

그나저나 누가 이걸 신청할걸까.. 구립도서관에서 자체적으로 구매한걸까?

+ 웹 서버 라던가 생명게임이라던가 조금 난이도 있는 내용들을 다루지만
다르게 말하면 이 책 한권에 웬만한 난이도는 이해할수 있는 내용이 담겨 있다는 것!


[링크 : http://www.yes24.com/24/goods/5968810]

'Programming > lisp' 카테고리의 다른 글

lisp의 con cell 과 NIL  (0) 2013.01.14
lisp #  (0) 2013.01.11
lisp 전역변수 / 지역변수  (0) 2013.01.09
lisp car / cdr  (0) 2013.01.03
lisp 반복문  (0) 2012.12.31
Posted by 구차니
Programming/lisp2013. 1. 9. 21:43
define a parameter
(defparameter <sym> <val> [<comment>])

fsubr.

<sym> the symbol (will be marked special)
<val> the value
<comment>  optional comment string (ignored)
returns the value

define a variable
(defvar <sym> [<val> [<comment>]])

fsubr.  Variable only initialized if not previously defined.

<sym> the symbol (will be marked special)
<val> the initial value, or NIL if absent.
<comment>  optional comment string (ignored)
returns the current value

set the global value of a symbol
(set <sym> <expr>)

You can also use (setf (symbol-value <sym>) <expr>)

<sym> the symbol being set
<expr> the new value
returns the new value

set the value of a symbol
(setq [<sym> <expr>]...)

fsubr. You can also use (setf <sym> <expr>)

<sym> the symbol being set (quoted)
<expr> the new value
returns the last new value or NIL if no arguments



전역변수
(defparameter *var_name* value) 마지막에 정의된것으로 변경가능
(defvar *var_namevalue) 처음 정의된것으로 고정

> (defparameter *a* 1)
*a*
> *a*
1
> (defparameter *a* 2)
*a*
> *a*

> (defvar*a* 1)
*a*
> *a*
1> (defvar *a* 2)
*a*
> *a*
1

지역변수
(let ((variable_declarations)) (body)

> (let ((*a* 5)) (princ *a*))
5
5
> *a*
 

'Programming > lisp' 카테고리의 다른 글

lisp #  (0) 2013.01.11
만들면서 배우는 리스프 프로그래밍  (2) 2013.01.09
lisp car / cdr  (0) 2013.01.03
lisp 반복문  (0) 2012.12.31
clisp  (0) 2012.12.29
Posted by 구차니
Programming/processing2013. 1. 8. 22:25
과동기에게 들었던 신기한(?) 언어
이두이노도 이녀석으로 IDE를 만들었던거 같아서 신기해 했는데
아무튼 컨셉은 비쥬얼라이즈 언어

[링크 : http://en.wikipedia.org/wiki/Processing_(programming_language)]
[링크 : http://processing.org/]

'Programming > processing' 카테고리의 다른 글

processing 실행  (0) 2014.01.12
processing (언어)  (0) 2012.05.04
Posted by 구차니
Programming/openMP2013. 1. 8. 09:08
OpenMP 처럼 패러럴 프로세싱관련 라이브러리로
Intel에서 제작하고 배포하는데 라이센스는 확인이 필요할듯

[링크 : http://goparallel.sourceforge.net/compiling-tbb-programs-and-examples-on-linux-ubuntu/
[링크 : http://software.intel.com/en-us/intel-tbb...] 30일 버전이나 구입인거 봐서는 free는 아닌듯
[링크 : http://threadingbuildingblocks.org/]

'Programming > openMP' 카테고리의 다른 글

openMP 지시어  (0) 2013.03.16
visual studio express 2008에서는 openMP 공식 지원안해!  (0) 2013.03.16
openMP 문서들  (0) 2012.06.18
openmp for문 나누기  (0) 2012.06.18
libgomp 공식 사이트 / 문서  (0) 2012.06.10
Posted by 구차니
클로져라는 녀석이 있는데 먼가 좋다는데 좋은진 모르겠고 -_-
암튼, 함수언어라고 해야하나
함수에 함수를 넣고
함수 변수에 특정 변수를 넣어 함수를 생성해 내는 그런 기능을 클로져라고 하는데


머하는데 써먹지?

[링크 : https://developer.mozilla.org/ko/docs/JavaScript/Guide/Closures]

'Programming > javascript & HTML' 카테고리의 다른 글

jquery  (0) 2015.09.08
div 태그  (0) 2015.09.08
javascript - DOM inspector in Firefox  (0) 2010.08.19
HTML의 style="filter:filter_name()"  (0) 2010.08.06
javascript - Traversing an HTML table with JavaScript and DOM Interfaces  (0) 2010.08.02
Posted by 구차니
Programming/C++ STL2013. 1. 6. 23:28
템플릿을 이용하는건 제너릭 프로그래밍과 동일하지만
컴파일러에 조금더 의존을 해서, 최적화를 한다는데 자세한건 읽어봐야 할 듯

간략하게 한글 위키 내용을 요약하면,
factorial 같은 무거운 함수를 템플릿으로 작성하고
이걸 템플릿 메타 프로그래밍을 적용하면
factorial(N)에 대해서 컴파일러가 미리 처리해서
해당 값을 바로 리턴할수 있도록 컴파일 시간에 값을 정해버린다는 것.

엄청난 퍼포먼스 향상이 있을것으로 생각이 되지만...
컴파일러에 지극히 의존적이라 호환성이 떨어진다고 하니...

[링크 : http://ko.wikipedia.org/wiki/템플릿_메타프로그래밍]
[링크 : http://en.wikipedia.org/wiki/Template_metaprogramming]

[링크 : http://en.wikipedia.org/wiki/Generic_programming]

'Programming > C++ STL' 카테고리의 다른 글

C++ 첫걸음 *-_-*  (0) 2013.02.09
unsigned char -> int 변환 주의사항  (0) 2013.02.04
c++ template  (0) 2012.05.12
리눅스에서 c++ 컴파일시 strcpy / strcat 오류  (0) 2011.10.13
new / new[] / delete / delete[]  (4) 2010.09.16
Posted by 구차니
Programming/C Win32 MFC2013. 1. 6. 23:11
c언어 강좌를 하다가 윈도우 서버 프로그래머 분이 오셔서 이야기를 듣는데
이건 꼭! 내것으로 만들어야 겠다 싶은게 있어서 기록 (오유 i2kas 님)



if(idx == 0)
이라는 문구가 있을경우
idx = 0 으로 쳐도 문법적인 에러는 발생하지 않고
찾기가 상당히 어려운 버그중에 하나인데


if(0 == idx) 로 순서만 바꾸면 문법적으로는 아무런 하자가 없으면서도
== 를 잘못입력하여 = 로 입력했을시 
if(0 = idx)로 lvalue가 constant로 에러가 발생함으로 유용하게 논리에러를 잡아내는데 사용될수 있다.


오홍!!!! 

'Programming > C Win32 MFC' 카테고리의 다른 글

win32api - joystick 예제  (0) 2013.06.15
Windows IME  (0) 2013.02.14
c 변수범위 헤더  (0) 2012.07.02
엔디안 / endian  (2) 2012.06.14
localtime의 return값을 조심하세요  (2) 2012.06.12
Posted by 구차니
Programming/lisp2013. 1. 3. 21:25
난해한(!) 명령어중에 하나로 car / cdr이라는 lisp 명령어가 있다.
car은 first에 대응되며 list의 가장 처음 내용만 보여주고
cdr은 rest에 대응되며 list의 처음것을 제외한 내용을 보여준다.

1> (car '(1 2 3))
1                
1> (cdr '(1 2 3))
(2 3)
1> (rest '(1 2 3))
(2 3) 

return the car of a list node
(car <expr>)

May be used as a place form.

<expr> the list node
returns the CAR of the list node


return the cdr of a list node
(cdr <expr>)

May be used as a place form.

<expr> the list node
returns the CDR of the list node

all cxxr combinations
(cxxr <expr>)
all cxxxr combinations
(cxxxr <expr>)
all cxxxxr combinations
(cxxxxr <expr>)

May be used as place forms when common2.lsp loaded.

a synonym for car
(first <expr>)
a synonym for cadr
(second <expr>)
a synonym for caddr
(third <expr>)
a synonym for cadddr
(fourth <expr>)
fifth list element
(fifth <expr>)
sixth list element
(sixth <expr>)
seventh list element
(seventh <expr>)
eighth list element
(eighth <expr>)
ninth list element
(ninth <expr>)
tenth list element
(tenth <expr>)
a synonym for cdr
(rest <expr>)

May be used as place forms when common2.lsp loaded.  fifth through tenth defined in common2.lsp. 

Etymology

Lisp was originally implemented on the IBM 704 computer, in the late 1950s. The 704 hardware had special support for splitting a 36-bit machine word into four parts, an "address part" and "decrement part" of 15 bits each and a "prefix part" and "tag part" of three bits each.

Precursors to Lisp included functions:

  • car (short for "Contents of the Address part of Register number"),
  • cdr ("Contents of the Decrement part of Register number"),
  • cpr ("Contents of the Prefix part of Register number"), and
  • ctr ("Contents of the Tag part of Register number"),

each of which took a machine address as an argument, loaded the corresponding word from memory, and extracted the appropriate bits.

http://en.wikipedia.org/wiki/CAR_and_CDR]

'Programming > lisp' 카테고리의 다른 글

만들면서 배우는 리스프 프로그래밍  (2) 2013.01.09
lisp 전역변수 / 지역변수  (0) 2013.01.09
lisp 반복문  (0) 2012.12.31
clisp  (0) 2012.12.29
lisp 기본함수  (0) 2012.12.29
Posted by 구차니