![]() |
|
Navigation |
Synopsis Question about the value of a Rascal expression or program.
Syntax
Description A value question presents a Rascal expression and poses a question about its value.
OptName is an optional name of the question (enclosed between [ and ] ).
If OptName is missing, the question gets a unique number as name.
The desired type of the expression is given by a TypeDescriptor. The first form presents the value generated for the TypeDescriptor and asks about its value.
The second form allows more preparatory steps and also allows adding a listing to the question. The following steps are defined:
Examples See the effect of the following value questions in the Questions section below.
Question 1The following question can be paraphrased as: I give you a union of two sets of integers, what is its value?QValue: <A:set[int]> + <B:same[A]> Question 2The following question can be paraphrased as: What is the size of a given list of integers?QValue: prep: import List; test: size(<A:list[int]>) == <?>Note that the List module is imported as a preparatory step.
Question 3The following question can be paraphrased as: I give you a union of integers or strings and an unknown set and the result of the union; what is the value of the unknown set?QValue: make: A = set[arb[int,str]] make: B = same[A] expr: C = <A> + <B> hint: <B> test: <A> + <?> == <C>Observe that we generate values for A and B and compute the value of C .
The value of B is the answer we are looking for, and we replace it by <?> in the posed test.
When the student gives a wrong answer, we show the value of B as hint.
Question 3The following question can be paraphrased as: Fill in the hole in the definition of funcion find to ensure that it returns all strings that contain "o".QValue: desc: Return the strings that contain "o". list: text = ["andra", "moi", "ennepe", "Mousa", "polutropon"]; public list[str] find(list[str] text){ return for(s <- text) if(/o/ := s) <?>; } test: find(text) == ["moi", "Mousa", "polutropon"]; Questions
Question [1].
![]() ![]()
Question [2].
![]() ![]()
Question [3].
![]() ![]()
Question [4].
![]() ![]() ![]() |