U E D R , A S I H C RSS

Programming Language Class/2006/Report3

Report 3

Specification

~cpp
C supports two kinds of parameter passing mode, pass-by-value and pass-byreference,
but not pass-by-name. A technique for implementing pass-by-name is to
treat the actual parameters as thunks. Whenever a formal parameter is referenced in a
subprogram, the corresponding thunk compiled for that parameter is executed. Even
though it is difficult to avoid run-time overhead in the execution of thunks, sometimes it
provides a very powerful feature for some applications like a generic summation routine.
Suppose that whenever a programmer wants to pass a parameter by name in C, it is
required to prefix the keyword name just in front of both the actual and formal
parameters as below:
Sum (name i + j, 1, n, name V[i]);
Of course, if a C program with the call statement above is to be compiled by a
conventional compiler, syntax errors should occur since it violates the syntactical rules
of C.
You are required to implement C preprocessor that supports the pass-by-name
parameter-passing method. The preprocessor should transform C programs with name
parameters into pure C programs so that the transformed programs manage to handle
parameters prefixed with name as if they were called by name without causing any
syntax errors.
숙제의 이해를 위해서 우선 thunks 라는 단어의 의미를 알아야합니다.
thunks 는 두가지 의미로 해석됩니다. 첫번째, 함수형 언어에서 말하는 지연형 계산 두번째, 호환성의 이유로 서로다른 데이터형 간의 매핑을 행하는 행위
이번 숙제에서 구현하려는 것은 첫번째의 의미로 지연형 계산(delayed computation)을 의미합니다. call-by-name, call-by-need를 통해 함수에게 넘어오는 일련의 매개변수를 thunk라는 이름으로 부릅니다. 간단히 말해 thunk라는 것은 실행시에 계산되어 변수의 값이 얻어진다는 의미입니다. (이는 기존의 함수에서 파라메터 패싱에서 Call 시에 변수에 바인딩되는 것과는 다릅니다.) 이런 기능이 최초로 구현된 Algol60입니다.

Requirement
~cpp
x = sigma(i=1, n) {V}

1) Your program should handle Jensen’s device; show that your program works
properly by testing it for various summation below.
2) You are also recommended to check if Swap (x, y) does work properly or not
by passing parameters by name.
3) You have to show off the robustness of your program by checking various
error conditions.
Jensen's Machine 은 Jørn Jensen라는 사람이 Algol 60을 제안하는 보고서에서 제시한 프로그래밍 테크닉을 말합니다.
~cpp
  begin integer i;
     real procedure sum(i, lo, hi, term);
          value lo, hi; integer i, lo, hi; real term;
          comment term is passed by-name;
     begin real temp; temp := 0;
           for i := lo step 1 until hi do
              temp := temp + term;
           sum := temp
     end;
     print( sum(i, 1, 100, 1/i))
  end
제시된 문제는 상기와 같으며, 이는 100번째의 조화수를 구하는 문제를 해결하는 방법입니다. 차후에 그 이름도 유명한 Knuth 님께서 Man Boy Test로 발전시켰습니다.
소스가 잘 이해가 안되신다면... -_-; 계속 보시라고 밖엔;;;
cf) Jensen's Device, Man Boy Test 는 Compiler Theory 의 한 항목들입니다.

Hand-In
~cpp
You should follow the guideline suggested later. To be specific, your report is
supposed to include an external documentation as well as an internal documentation.
The external documentation should explain your program in detail so that we can
understand what kind of data structures have been used, the characteristics and general
as well as unique features of your program, etc. An internal documentation means the
comment attached in your source.
You are supposed to upload your source program and executable file. You are also
required to submit a listing of your program and a set of test data of your own choice,
and its output, when you show up for demo. Be sure to design carefully your test data
to exercise your program completely.

brief note

음 잠깐 하면서 생각한건데.... 이 숙제 정말로 구리다. -_- 내가 이렇게 재미없는 숙제를 하게된건 파일구조때 binary 가지고 장난친 이후 처음인듯하다. 문자열 장난할꺼면 펄로하게 해주던지... C 문자열 함수 가지고 놀려니... 정말로 구리다라는 생각뿐~ - eternalbleu
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:24:02
Processing time 0.0101 sec