게시판 인덱스

 
 FAQFAQ   검색검색   멤버리스트멤버리스트   사용자 그룹사용자 그룹   사용자 등록하기사용자 등록하기 
 개인 정보개인 정보   비공개 메시지를 확인하려면 로그인하십시오비공개 메시지를 확인하려면 로그인하십시오   로그인로그인 

식을 평가하면 이렇게 되는건가요?

 
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.210 Principles of Programming (Spring 2007)
이전 주제 보기 :: 다음 주제 보기  
글쓴이 메시지
박창범



가입: 2007년 3월 21일
올린 글: 4

올리기올려짐: 2007년4월11일 12:42    주제: 식을 평가하면 이렇게 되는건가요? 인용과 함께 답변

아래 처럼 정의가 되었다고 하면
(define nil ())
(define (link x lst) (lambda (f) (f x lst)))
(define (first lst) (lst (lambda (x y) x)))
(define (rest lst) (lst (lambda (x y) y)))
(define empty? null?)

이를 실행시에
(first (link 1 nil))

=> (first (lambda (f) (f 1 nil)))
=> ((lambda (f) (f 1 nil)) (lambda (x y) x))
=> ((lambda (x y) x) 1 nil)
=> 1

순서로 평가가 되는것인지요?
아니면

=> ((link 1 nil) (lambda (x y) x))
=> ((lambda (f) (f 1 nil)) (lambda (x y) x))
=> ((lambda (x y) x) 1 nil)
=> 1

이렇게 평가가 되는건지요?

복잡하네요.
위로
사용자 정보 보기 비밀 메시지 보내기 글 올린이의 웹사이트 방문 MSN 메신저
공순호



가입: 2005년 9월 29일
올린 글: 363
위치: 302동 312-2호

올리기올려짐: 2007년4월12일 6:54    주제: 인용과 함께 답변

좋은 질문이네요. Smile

인용:

SICP, 1.1.3 Evaluating Combinations

One of our goals in this chapter is to isolate issues about thinking procedurally. As a case in point, let us consider that, in evaluating combinations, the interpreter is itself following a procedure.

* To evaluate a combination, do the following:

1. Evaluate the subexpressions of the combination.

2. Apply the procedure that is the value of the leftmost subexpression (the operator) to the arguments that are the values of the other subexpressions (the operands).


인용:

SICP, 1.1.5 The Substitution Model for Procedure Application

Applicative order versus normal order

According to the description of evaluation given in section 1.1.3, the interpreter first evaluates the operator and operands and then applies the resulting procedure to the resulting arguments. This is not the only way to perform evaluation. An alternative evaluation model would not evaluate the operands until their values were needed. Instead it would first substitute operand expressions for parameters until it obtained an expression involving only primitive operators, and would then perform the evaluation.

.
.
.

This alternative ``fully expand and then reduce'' evaluation method is known as normal-order evaluation, in contrast to the ``evaluate the arguments and then apply'' method that the interpreter actually uses, which is called applicative-order evaluation. It can be shown that, for procedure applications that can be modeled using substitution (including all the procedures in the first two chapters of this book) and that yield legitimate values, normal-order and applicative-order evaluation produce the same value. (See exercise 1.5 for an instance of an ``illegitimate'' value where normal-order and applicative-order evaluation do not give the same result.)

Lisp uses applicative-order evaluation, partly because of the additional efficiency obtained from avoiding multiple evaluations of expressions such as those illustrated with (+ 5 1) and (* 5 2) above and, more significantly, because normal-order evaluation becomes much more complicated to deal with when we leave the realm of procedures that can be modeled by substitution. On the other hand, normal-order evaluation can be an extremely valuable tool, and we will investigate some of its implications in chapters 3 and 4.16



읽어보시면 답을 아실 수 있을겁니다.
_________________
- soon@ropas
위로
사용자 정보 보기 비밀 메시지 보내기 글 올린이의 웹사이트 방문
이전 글 표시:   
이 게시판은 잠겼으므로 글을 올리거나, 답변을 하거나 수정을 할 수 없습니다   이 주제는 잠겼으므로 답변을 하거나 수정을 할 수 없습니다     게시판 인덱스 -> 4190.210 Principles of Programming (Spring 2007) 시간대: GMT + 9 시간(한국)
페이지 11

 
건너뛰기:  
새로운 주제를 올릴 수 없습니다
답글을 올릴 수 없습니다
주제를 수정할 수 없습니다
올린 글을 삭제할 수 없습니다
투표를 할 수 없습니다


Powered by phpBB 2.0.21-7 (Debian) © 2001, 2005 phpBB Group
Translated by kss & drssay