이전 주제 보기 :: 다음 주제 보기 |
글쓴이 |
메시지 |
AlenaKazakova
가입: 2014년 9월 24일 올린 글: 9
|
올려짐: 2014년12월8일 10:29 주제: Project Problem3 |
|
|
According to the 3rd task I have to check expression before transformation: whether "repeat E1 E2" does not have E1 < 0. But expression E1 itself could have "Read" command, so how to be sure that the "Read" expression will have a same value at "checking before transformation" and at "transformation time" the same input?
Please let me know how should I implement "Read" expression, should I use "input_line stdin"?
Thank you. |
|
위로 |
|
 |
김윤승
가입: 2014년 9월 1일 올린 글: 452 위치: 302동 312-2호
|
올려짐: 2014년12월8일 19:04 주제: |
|
|
I think I don't understand your question clearly.
In this problem, you don't check whether the two programs (before and after the transformation) do the same task, though they should do.
What you should check are:
1. whether the input "exp" contains a meaningless expression.
2. whether the output "cmd" is well-constructed. (Check the two requirements written in the document)
Also, you don't 'implement' "Read". Your task is just to transform an "exp" into a "cmd".
If this doesn't give you the answer, let me know. |
|
위로 |
|
 |
AlenaKazakova
가입: 2014년 9월 24일 올린 글: 9
|
올려짐: 2014년12월8일 19:34 주제: Clarification of the Question |
|
|
This is example of normal expression according to type definition.
How to check whether (read) is not negative? |
|
위로 |
|
 |
김윤승
가입: 2014년 9월 1일 올린 글: 452 위치: 302동 312-2호
|
올려짐: 2014년12월8일 22:22 주제: |
|
|
You don't know the value of "read".
It is always between -100 and 100.
Your check_exp should reject that code, because the value can be negative.
However, something like [repeat (read + 100) 5] is always valid.
The important point is, making perfect [check_exp] is (almost) impossible.
So if you think there is a possibility that the first argument of any [repeat] becomes negative, [check_exp] should reject the expression. |
|
위로 |
|
 |
AlenaKazakova
가입: 2014년 9월 24일 올린 글: 9
|
올려짐: 2014년12월8일 23:09 주제: |
|
|
You made a code to evaluate expression using input int list, in our task source we have "val check_exp: exp -> bool" interface.
So it is not clear how to use your "interpreter.ml". Please explain why did you upload it?
Because "val check_exp: exp -> bool" does not have any way to provide the input stream to Read function, I have implemented it as (input_line stdin), please explain what is correct way to implement Read? |
|
위로 |
|
 |
김윤승
가입: 2014년 9월 1일 올린 글: 452 위치: 302동 312-2호
|
올려짐: 2014년12월9일 0:09 주제: |
|
|
You are misunderstanding the problem.
[check_exp] does not "run" the input expression. It just expects the "possible behavior" of the expression.
Just regard [read] as [random()] which returns a value between -100 and 100.
[check_exp (repeat (read + 1) 1)] should return false, because there is a possible execution that (read+1) becomes negative. (You don't get any keyboard input from outside.)
[check_exp (repeat (read + 101) 1)] may return true, because all executions are valid regardless of the value of [read].
Again, it's impossible to make [check_exp] perfect, which means, sometimes your [check_exp] returns false even if the input expression is always valid, but this is OK.
However, your [check_exp] should not return true for expressions which have at least one "invalid" execution. |
|
위로 |
|
 |
|