Synopsis Question about the value of a Rascal expression or program.
  • QValue OptName: TypeDescriptor
  • QValue OptName: QSteps Test Listing
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:
  • prep: Cmd: execute Cmd as preparatory step. Mostly used to import necessary libraries.
  • make: Var = TypeDescriptor: create a new variable and use TypeDescriptor to generate its value.
  • expr: Var = Exp: evaluate the Rascal expression Exp and assign its value to the new variable Var.
  • list: Lines: lines that will be displayed as a listing. The listing may contain a placeholder in the form of <?> and ends where a new step begins.
  • test: Exp1 == Exp2: the equality is ecvaluated as Rascal expression. The outcome determines the success or failure to answer this question.
  • hint: Text: a hint that will be shown when the user enters a wrong answer.
The following restrictions apply:
  • Each step starts at the beginning of a new line.
  • Every Exp or Cmd or listing may contain one or more variable references of the form <Var>.
  • Each variable reference <Var> is first replaced by the the value of Var. Var should have received a value in a preceeding make or expr step.
  • The listing, and the expressions in the test may contain at most one placeholder <?>.
Examples See the effect of the following value questions in the Questions section below.

Question 1

The 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 2

The following question can be paraphrased as: What is the size of a given list of integers?
prep: import List;
test: size(<A:list[int]>) == <?>
Note that the List module is imported as a preparatory step.

Question 3

The 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?
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 3

The 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".
desc: Return the strings that contain "o".
text = ["andra", "moi", "ennepe", "Mousa", "polutropon"];
public list[str] find(list[str] text){
    for(s <- text)
      if(/o/ := s)
test: find(text) == ["moi", "Mousa", "polutropon"];

Question [1].
{-12, -16, 7, -8} + {3} == 

Question [2].
size([-8, 3, 5]) == 

Question [3].
{17} +  == {-18,2,17,-15}

Question [4]. Return the strings that contain "o".
Fill in
text = ["andra", "moi", "ennepe", "Mousa", "polutropon"];
public list[str] find(list[str] text){
    for(s <- text)
      if(/o/ := s)
and make the following true:
find(text) == ["moi", "Mousa", "polutropon"];

Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit