'lisp'에 해당되는 글 7건

  1. 2013.01.17 lisp rem, mod
  2. 2013.01.03 lisp car / cdr
  3. 2012.12.05 lisp - #' 와 '
  4. 2012.11.19 lisp는 리스트지 prefix 표기법이 아니다
  5. 2012.01.24 lisp 문법
  6. 2012.01.24 slime / lispbox
  7. 2011.05.05 lisp
Programming/lisp2013. 1. 17. 19:26
reminder 나 modulo 나 둘다 나머지 연산인데
왜 굳이 두개의 이름으로 별도로 존재하나 했더니

양수에서는 차이가 없으나, 음수에서 차이가 발생한다.
2> (mod  5 2) 
1             
2> (mod  5 -2)
-1            
2> (rem  5 2) 
1             
2> (rem  5 -2)
1              


    Rem(x, 5):

                       5+         o         o
                        |       /         /
                        |     /         /
                        |   /         /
                        | /         /
    *---------*---------*---------*---------*
   -10      / -5      / 0         5        10
          /         /   |
        /         /     |
      /         /       |
    o         o       -5+

    Mod(x, 5):

              o        5o         o         o
            /         / |       /         /
          /         /   |     /         /
        /         /     |   /         /
      /         /       | /         /
    *---------*---------*---------*---------*
   -10        -5        0         5        10

    Rem(x, -5):

                       5+         o         o
                        |       /         /
                        |     /         /
                        |   /         /
                        | /         /
    *---------*---------*---------*---------*
   -10      / -5      / 0         5        10
          /         /   |
        /         /     |
      /         /       |
    o         o       -5+

    Mod(x, -5):

    *---------*---------*---------*---------*
   -10      / -5      / 0       / 5       /10
          /         /   |     /         /
        /         /     |   /         /
      /         /       | /         /
    o         o       -5o         o
 
[링크 : http://mathforum.org/library/drmath/view/54377.html

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

xlisp에서 incf 오류  (0) 2013.01.19
lisp backquote / 유사인용  (0) 2013.01.19
lisp i/o  (0) 2013.01.17
lisp file i/o  (0) 2013.01.17
lisp savefun / load  (0) 2013.01.16
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 구차니
Programming/lisp2012. 12. 5. 23:18
'는 quote(인용)인데
함수적 언어인 lisp에서 함수를 쓰지 않고 list나 atom을 만드는데 사용한다.
> (quote a)
A
> 'a
A
> '(a)
(A) 
> (quote (a))
(A) 

>'(+ 1 2)
(+ 1 2)

위의 예제와 같이 (quote val)과 'val은 동일하며 atom을 나타낼때 사용된다.
atom으로 쓰려면 'val
list로 쓰려면 '(val)
로 사용하면 된다. 물론 함수역시 list의 atom으로서 인식이 되어질수 있다.



#'는 lisp 문서를 보다가 찾게 된 녀석인데
#' 는 (function val)과 같은 의미이고
함수 포인터라고 하기도 모호하고 아무튼.. 아직은 이해가 잘 안되는 녀석..
APPLY is also a Lisp primitive function.
APPLY takes a function and a list of objects as input. It invokes the specified function with those objects as its inputs.  The first argument to APPLY should be quoted with #’ rather than an ordinary quote; #’ is the proper way to quote functions supplied as inputs to other functions.  This will be explained in more detail in Chapter 7.
(apply #'+ '(2 3)) ⇒ 5
(apply #’equal '(12 17)) ⇒ nil 

The #’ (or ‘‘sharp quote’’) notation is the correct way to quote a function in Common Lisp.  If you want to see what the function CONS looks like in your implementation, try the following example in your Lisp:
> (setf fn #’cons)
#<Compiled-function CONS {6041410}>
> fn
#<Compiled-function CONS {6041410}>
> (type-of fn)
COMPILED-FUNCTION
> (funcall fn ’c ’d)
(C . D) 

> #'+
#<SYSTEM-FUNCTION +> 

> (function +)
#<SYSTEM-FUNCTION +> 

---2012.12.11

#는 벡터라고 한다.
[링크 : http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node30.html]

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

lisp atom  (0) 2012.12.11
lisp tutorial  (0) 2012.12.06
클로져  (0) 2012.12.03
lisp는 리스트지 prefix 표기법이 아니다  (0) 2012.11.19
lisp 관련 책  (0) 2012.01.25
Posted by 구차니
Programming/lisp2012. 11. 19. 14:33
지하철에서 오가다가 lisp 문서를 보다보니
(+ 1 2 3)
6

이런 내용이 있어서 곰곰히 생각해보니
이 써글(!) lisp를 못 읽었던 이유가
전위 표기법으로 착각을 하고 있었던것 -_-


list를 기반으로 하기에 모든건 list이고 
+는 단지 처음에 오는 식별자 혹은 함수 이름으로서 '+' 라는 점
그렇기에 +와 - 를 합쳐서 쓰려면
괄호가 늘어 난다는 점 -_-

또한 값으로만 이루어진 리스트는
'(a b c) 식으로 함수 없이 값만으로 이루어진 것이라는 접두가 필요하다는 점
머.. 이게 이번에 깨달은 걸려나? 

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

lisp - #' 와 '  (0) 2012.12.05
클로져  (0) 2012.12.03
lisp 관련 책  (0) 2012.01.25
lisp 문법  (0) 2012.01.24
slime / lispbox  (0) 2012.01.24
Posted by 구차니
Programming/lisp2012. 1. 24. 18:07
연휴이고 하니 뜬금없이 LISP 공부중인데 전에도 이해 못했고 이번에도 이해 못하고 있는 lisp -_-
LISP는 LISt Process 의 약자로
이름대로 모든것으로 LIST 에 기반하여 표현하게 되며, 리스트는 () 로 둘러쌓여 표현된다.
이러한 이유로 lisp 소스를 보면 ()가 가득히 둘러쌓여 가독성이 떨어지는 형태가 된다.

또한 리스트에서 계산등은 모두 전위표기법을 사용하게 되며 기본 연산은 다음과 같이 표현된다.
CL-USER> (+ 1 2 ) ; 1 + 2
3
 
CL-USER> (- 1 2 ) ; 1 - 2
-1
 
CL-USER> (/ 1 2) ; 1 / 2
1/2
 
CL-USER> (* 1 2) ; 1 * 2
2
 
CL-USER> (mod 3 2) ; 3 % 2
1
 
CL-USER> (log 2) ; log(2)
0.6931472
 
CL-USER> (sqrt 2) ; sqrt(2)
1.4142135 

CL-USER> (< 1 2) ; 1 < 2
T 

그리고 기호를 가지는 변수(?)는 setq 명령어를 이용하여 선언한다. 
val을 입력하면 해석할 수 없는 변수이기 때문에 에러가 나지만 setq를 통해서 값을 정해주면
val만 입력해도 입력했던 값이 나오게 된다.
CL-USER> val
Invoking restart: Return to sldb level 2.
; Evaluation aborted on #<UNBOUND-VARIABLE #xC7B642E>.

CL-USER>
(setq val 100)
100

CL-USER> val
100 

CL-USER> (setq str "This is test string")
"This is test string"
 
CL-USER> str
"This is test string" 
 
아무튼 defvar 라는 키워드를 이용해서 변수를 선언 할수도 있는데 setq와는 다르게 리턴되는 값이 다르다
CL-USER> (defvar loop 10)
LOOP
 
CL-USER> loop
10 
 
함수는 defun (DEFine + FUNction 인 듯?)을 통해서 선언이 가능하다.
단순하게 3을 리턴하는 함수로 three 라는 것을 만드는 예제이다.
> (defun three () 3)            
THREE                           

> (three)                       
3                               

> (+ (three) 1)                 
4          

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> three()                       
error: unbound variable - THREE 
> three                         
error: unbound variable - THREE 
> (+ three 1)                   
error: unbound variable - THREE  
 
인자를 사용하는 함수로 인자는 아래와 같이 사용한다.
CL-USER> (defun add (x y) (+ x y))
ADD

CL-USER> (add 3 4)
7 
 
리스트는 아래와 같이 '을 먼저 찍고 해주면 된다. (아직 이해 부족.. OTL)
물론 리스트도 setq로 선언하여 사용이 가능하다.
> '(1 2 3)             
(1 2 3)                

> (1 2 3)              
error: bad function - 1 

'/어포스트로피/apostrophe
'foo는 (quote foo) 와 동일하고 s expression 에서 함수가 아닌 것으로 해석하도록 하는 명령어이다.
어떻게 보면 변수로 인식시킨다고 해야 하려나? replace 라고 된것을 보면 -_-

Creating sets (actually, creating variables) can be done with setf : this creates a set called learned with three members:

(setf learned '(VB C++ LISP))

The apostrophe is uses to designate that something in brackets isn't a function (or an S-expression). Basically, if LISP receives something like (VB C++ LISP) it assumes VB is the name of a function and C++ and LISP are its arguments. The apostrophe says that this isn't a function, it's a list, and can itself be an argument in a function.

[링크 : http://homepages.paradise.net.nz/milhous/lisp.htm]  

The form 'foo is simply a faster way to type the special form

(quote foo)

which is to say, "do not evaluate the name foo and replace it with its value; I really mean the name foo".

I think SISC is perfectly fine for exploring the exercises in TLS. 

[링크 : http://stackoverflow.com/questions/1539144/what-is-apostrophe-in-lisp-scheme]  





리스프에 내장된 함수라고 해야하나 keyword 라고 해야하나 아무튼 그거 목록
[링크 : http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/] << 목록
    [링크: http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/clm.html] << 최상위

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

lisp는 리스트지 prefix 표기법이 아니다  (0) 2012.11.19
lisp 관련 책  (0) 2012.01.25
slime / lispbox  (0) 2012.01.24
우분투에서 lisp 설치하기  (0) 2012.01.15
lisp  (0) 2011.05.05
Posted by 구차니
Programming/lisp2012. 1. 24. 10:04
slime 은 emacs와 lisp를 합쳐서 만든 통합 개발 환경이다.
Superior Lisp Interaction Mode for Emacs 라..
vi도 안친한데 emacs를 이용해서 어떻게 해야하나 하아..


[링크 :  http://common-lisp.net/project/slime/]


아무튼 간단하게 압축만 풀면 실행이 되는 slime for windows 프로그램이 있어서 투척
멋지게도 컬러풀하게 나오고 아래에서는 defun 이런거 입력하면 기본 유형이 나와준다.


[링크 :  http://common-lisp.net/project/lispbox/]   lispbox(slime for windows) 
[링크 :  http://www.cs.utexas.edu/~novak/gclwin.html] gnu lisp for windows


-----
우분투야 항상 그러하듯 slime 패키지를 설치하면 해결



일단 emacs를 실행하고 Alt-x 누른후 slime 이라고 입력한다.


그러면 clisp를 통해서 어쩌구 저쩌구 하고는 아래와 같이 프롬프트가 뜬다.


[링크 : http://akoumjian.blogspot.com/2007/10/clisp-in-emacs-using-slime-on-ubuntu.html]

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

lisp는 리스트지 prefix 표기법이 아니다  (0) 2012.11.19
lisp 관련 책  (0) 2012.01.25
lisp 문법  (0) 2012.01.24
우분투에서 lisp 설치하기  (0) 2012.01.15
lisp  (0) 2011.05.05
Posted by 구차니
Programming/lisp2011. 5. 5. 21:57
lisp는 LISt Processing 의 약자로 프로그래밍 언어이다.
일반적으로 AI 쪽에서 많이 쓰이며
괄호가 넘쳐나는 괴랄한 언어라서 이해가 쉽지는 않다 -_-


수업을 들었었어도 이해를 할수가 없는 언어 OTL 
다시 한번 시도를 해봐야지 ㅠ.ㅠ

[링크 : http://www.cs.cmu.edu/~dst/LispBook/index.html] Common Lisp (PDF)
[링크 : http://www.paulgraham.com/onlisp.html]
    [링크 : http://www.paulgraham.com/onlisptext.html] On LISP (PDF)
[링크 : http://gigamonkeys.com/book/] Practical COMMON LISP (HTML)

[링크 : http://lisp-korea.wikispaces.com/]
[링크 : http://onlisp.blogspot.com/2008/03/common-lisp.html

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

lisp는 리스트지 prefix 표기법이 아니다  (0) 2012.11.19
lisp 관련 책  (0) 2012.01.25
lisp 문법  (0) 2012.01.24
slime / lispbox  (0) 2012.01.24
우분투에서 lisp 설치하기  (0) 2012.01.15
Posted by 구차니