Hi all,
I have a problem in which students are giving lists of pairs of strings. Thus, a correct answer might be (a,b), (c,d). Alternately, if only one pair of strings is correct, the answer might be a list of one pair: (a,b).
What I'm finding is that I can't get the case of a list of a list of one pair of strings to correctly answer-check. That is, if I define
$ans = List( List(String("a"),String("b")) );
I find that $ans is the list "a,b", not a list of one list of two strings: "(a,b)". At least, that's my interpretation. As a result, the student answer "a,b" is marked correct, but the answer "(a,b)" is marked wrong.
Can I force $ans to be a list of a list?
Thanks,
Gavin
Hi Gavin,
The code for making lists (in Value::List) has this at line 20:
It's too bad that Point objects need to take numerical coordinates, and don't allow for strings. Otherwise I think that a list of points would get what you want.
Alex
The code for making lists (in Value::List) has this at line 20:
my $isSingleton = (scalar(@_) == 0 && !(Value::isValue($p) && $p->classMatch('List')));which seems to identify singleton lists. Then later down there are some conditional statements using $isSingleton. I don't quite understand what they do, but it seems like they might be (among other things) identifying when a list is a nested singleton like you describe, and downgrading it to not be nested. Maybe a better understanding of this code would help?
It's too bad that Point objects need to take numerical coordinates, and don't allow for strings. Otherwise I think that a list of points would get what you want.
Alex
Gavin:
List-handling is a bit delicate, and there are some ambiguities. In particular, lists consisting of a single item are troublesome, mostly because the student can't really enter one. For example, the string "
There is also a problem based on the fact that lists sometimes want parentheses (as in "
The solution to your problem is to use
Davide
List-handling is a bit delicate, and there are some ambiguities. In particular, lists consisting of a single item are troublesome, mostly because the student can't really enter one. For example, the string "
(a)
" is not a list, in general, it is just the value "a
". Perhaps and better example is "(5-2)
" which is just the value 3 not a list containing the value 3. Similarly, "((1,2))
" is just parentheses around the list (1,2) (or the point (1,2), depending on the context). (The problem is really the overuse of parentheses for both lists and grouping). So a student can't really make the distinction between a singleton list and the element that makes it up. While you as the program author can use List(List(...))
to make the meaning clear, the student entering an answer can't.There is also a problem based on the fact that lists sometimes want parentheses (as in "
(1,2)
") and other times don't (as in "(1,2),(3,4)
"). Most of the time, lists are used for students to enter without parentheses, so List(1,2)
is usually entered by students as "1,2
" with no parentheses. Thus the List()
function usually produces lists without parentheses. So your List(List("a","b"))
produces a list with a list with no parentheses. That's why "a,b
" is the correct answer, while "(a,b)
" is not. (The list must match not just in the elements, but in the parentheses, too, in general, though there are flags you can set to change that.)The solution to your problem is to use
$ans = List("(a,b)")
(giving the answer in the form that the student will enter it). This makes a list were the parentheses are required, and it will match "(a,b)
" but not "a,b
".Davide