Log Message:
-----------
Update the List() object to not add "(" and ")" around the list unless
they are explicitly entered by the author. This prevents extraneous
parentheses from being introduced into the problem text that the
author hadn't expected.
Parentheses now are added only for nested lists, as in
List(1,List(2,3)), which will display as "1, (2, 3)", not "1, 2, 3".
Modified Files:
--------------
pg/lib:
Value.pm
pg/lib/Parser/Context:
Default.pm
pg/lib/Value:
List.pm
Revision Data
-------------
Index: Value.pm
===================================================================
RCS file: /webwork/cvs/system/pg/lib/Value.pm,v
retrieving revision 1.91
retrieving revision 1.92
diff -Llib/Value.pm -Llib/Value.pm -u -r1.91 -r1.92
--- lib/Value.pm
+++ lib/Value.pm
@@ -325,8 +325,8 @@
sub canBeInUnion {
my $self = shift;
my $def = $self->context->lists->get($self->class);
- my $open = $self->{open}; $open = $def->{open} unless defined $open;
- my $close = $self->{close}; $close = $def->{close} unless defined $close;
+ my $open = $self->{open}; $open = $def->{open}||$def->{nestedOpen} unless defined $open;
+ my $close = $self->{close}; $close = $def->{close}||$def->{nestedClose} unless defined $close;
return $self->length == 2 && $self->typeRef->{entryType}{name} eq 'Number' &&
$open =~ m/^[\(\[]$/ && $close =~ m/^[\)\]]$/;
}
Index: Default.pm
===================================================================
RCS file: /webwork/cvs/system/pg/lib/Parser/Context/Default.pm,v
retrieving revision 1.42
retrieving revision 1.43
diff -Llib/Parser/Context/Default.pm -Llib/Parser/Context/Default.pm -u -r1.42 -r1.43
--- lib/Parser/Context/Default.pm
+++ lib/Parser/Context/Default.pm
@@ -120,7 +120,8 @@
'Point' => {class =>'Parser::List::Point', open => '(', close => ')', separator => ','},
'Vector' => {class =>'Parser::List::Vector', open => '<', close => '>', separator => ','},
'Matrix' => {class =>'Parser::List::Matrix', open => '[', close => ']', separator => ','},
- 'List' => {class =>'Parser::List::List', open => '(', close => ')', separator => ', '},
+ 'List' => {class =>'Parser::List::List', open => '', close => '', separator => ', ',
+ nestedOpen => '(', nestedClose => ')'},
'Interval' => {class =>'Parser::List::Interval', open => '(', close => ')', separator => ','},
'Set' => {class =>'Parser::List::Set', open => '{', close => '}', separator => ','},
'Union' => {class =>'Parser::List::Union', open => '', close => '', separator => ' U '},
Index: List.pm
===================================================================
RCS file: /webwork/cvs/system/pg/lib/Value/List.pm,v
retrieving revision 1.26
retrieving revision 1.27
diff -Llib/Value/List.pm -Llib/Value/List.pm -u -r1.26 -r1.27
--- lib/Value/List.pm
+++ lib/Value/List.pm
@@ -15,10 +15,12 @@
sub new {
my $self = shift; my $class = ref($self) || $self;
my $context = (Value::isContext($_[0]) ? shift : $self->context);
+ my $def = $context->lists->get("List");
my $p = shift; my $isFormula = 0;
my $isSingleton = (scalar(@_) == 0 && !(Value::isValue($p) && $p->classMatch('List')));
$p = $p->data if (Value::isValue($p) && $p->classMatch('List') && scalar(@_) == 0);
- $p = [$p,@_] if (ref($p) ne 'ARRAY' || scalar(@_) > 0);
+ $p = [] unless defined $p;
+ $p = [$p,@_] if ref($p) ne 'ARRAY' || scalar(@_) > 0;
my $type;
foreach my $x (@{$p}) {
$x = Value::makeValue($x,context=>$context) unless ref($x);
@@ -27,11 +29,20 @@
if (!$type) {$type = $x->type}
else {$type = 'unknown' unless $type eq $x->type}
} else {$type = 'unknown'}
+ if (!$isSingleton && $x->type eq 'List') {
+ $x->{open} = $def->{nestedOpen} unless $x->{open};
+ $x->{close} = $def->{nestedClose} unless $x->{close};
+ }
}
return $p->[0] if ($isSingleton && $type eq 'List' && !$p->[0]{open});
return $self->formula($p) if $isFormula;
my $list = bless {data => $p, type => $type, context=>$context}, $class;
- $list->{correct_ans} = $p->[0]{correct_ans} if $isSingleton && defined $p->[0]{correct_ans};
+ $list->{correct_ans} = $p->[0]{correct_ans}
+ if $isSingleton && defined scalar(@{$p}) && defined $p->[0]{correct_ans};
+ if (scalar(@{$p}) == 0) {
+ $list->{open} = $def->{nestedOpen};
+ $list->{close} = $def->{nestedClose};
+ }
return $list;
}
|