Skip to content

Commit 58bbde2

Browse files
authored
Merge pull request #1350 from jpaulterry/master
Update to LaTech Problems in Programming Languages
2 parents a013ca6 + 79517ab commit 58bbde2

File tree

20 files changed

+2541
-0
lines changed

20 files changed

+2541
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## DESCRIPTION
2+
## Generates a sequence of val declarations in ML and asks for the
3+
## final values.
4+
## ENDDESCRIPTION
5+
6+
## DBsubject(Programming Languages)
7+
## DBchapter(ML)
8+
## DBsection(Data Structures)
9+
## Date(12/04/2021)
10+
## Institution(Louisiana Tech)
11+
## Author(Jason Terry)
12+
## Level(2)
13+
## KEYWORDS('programming languages','ml','sml','expressions','val')
14+
15+
16+
DOCUMENT();
17+
18+
## Load libraries
19+
loadMacros(
20+
"PGstandard.pl",
21+
"PGcourse.pl",
22+
"contextArbitraryString.pl",
23+
"PGML.pl"
24+
);
25+
26+
## Change context to strings answers
27+
Context("Numeric");
28+
29+
## Create random parameters
30+
$n1 = random(2,5,1);
31+
$n2 = random(6,9,1);
32+
33+
## Create answers to problems
34+
$a = $n1;
35+
$b = $n2;
36+
$b = $a + $b;
37+
$c = $a*$b;
38+
$a = $c - $a;
39+
$c = $c + $a;
40+
41+
## Display question
42+
TEXT(beginproblem());
43+
44+
BEGIN_PGML
45+
Determine the final value of the all variables after all the following ML value declarations.
46+
47+
*val a = [$n1];*
48+
49+
*val b = [$n2];*
50+
51+
*val b = a + b;*
52+
53+
*val c = a \* b;*
54+
55+
*val a = c - a;*
56+
57+
*val c = c + a;*
58+
59+
FINAL VALUE OF ALL VARIABLES:
60+
61+
a = [__________]{$a}
62+
63+
b = [__________]{$b}
64+
65+
c = [__________]{$c}
66+
67+
END_PGML
68+
69+
BEGIN_PGML_SOLUTION
70+
Solution:
71+
72+
a = [$a]
73+
74+
b = [$b]
75+
76+
c = [$c]
77+
78+
END_PGML_SOLUTION
79+
80+
ENDDOCUMENT();
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
## DESCRIPTION
2+
## Generates ML expressions using tuples and lists and asks for their types.
3+
## ENDDESCRIPTION
4+
5+
## DBsubject(Programming Languages)
6+
## DBchapter(ML)
7+
## DBsection(Data Structures)
8+
## Date(12/04/2025)
9+
## Institution(Louisiana Tech)
10+
## Author(Jason Terry)
11+
## Level(2)
12+
## KEYWORDS('programming languages','ml','sml','expressions','type','tuple','list')
13+
14+
15+
DOCUMENT();
16+
17+
## Load libraries
18+
loadMacros(
19+
"PGstandard.pl",
20+
"PGcourse.pl",
21+
"contextArbitraryString.pl",
22+
"PGML.pl"
23+
);
24+
25+
## Change context to strings answers
26+
Context("ArbitraryString");
27+
28+
## Create custom answer checker for ML types
29+
$typeChecker = sub {
30+
my ($correct,$student,$ansHash) = @_; # get correct and student MathObjects
31+
$correct = $correct->string;
32+
$student = $student->string;
33+
$student =~ s/^ *(.*?) *$/$1/; # remove front/end whitespace
34+
$student =~ s/ *~~* */~~*/g; # * shall have no space on each side
35+
$student =~ s/~~( */~~(/g; # ( shall have no space after
36+
$student =~ s/ *~~)/~~)/g; # ) shall have no space before
37+
$student =~ s/ *list/ list/g; # list shall have 1 space before
38+
return ($correct eq $student); # return 1 if correct, 0 otherwise
39+
};
40+
41+
$a = random(1,20,1);
42+
$b = random(1,20,1);
43+
$c = random(1,20,1);
44+
45+
## Create answers to problems and install custom type checker
46+
$ans1 = String("int*string")->cmp(
47+
checker => $typeChecker
48+
);
49+
50+
$ans2 = String("real*bool*char")->cmp(
51+
checker => $typeChecker
52+
);
53+
54+
$ans3 = String("(real*bool)*char")->cmp(
55+
checker => $typeChecker
56+
);
57+
58+
$ans4 = String("bool list")->cmp(
59+
checker => $typeChecker
60+
);
61+
62+
$ans5 = String("int list list")->cmp(
63+
checker => $typeChecker
64+
);
65+
66+
67+
## Display question
68+
TEXT(beginproblem());
69+
70+
BEGIN_PGML
71+
Write the type of the following ML expressions. *WARNING: Only use required parentheses for types to match the ML compiler's response.*
72+
73+
*([$a], \"hello\") : [_________________________]{$ans1}*
74+
===
75+
*([$b].4, true, #\"q\") : [_________________________]{$ans2}*
76+
===
77+
*(([$b].4, true), #\"q\") : [_________________________]{$ans3}*
78+
===
79+
*\[false\] : [_________________________]{$ans4}*
80+
===
81+
*\[\[[$c]\]\] : [_________________________]{$ans5}*
82+
83+
84+
END_PGML
85+
86+
BEGIN_PGML_SOLUTION
87+
Solution:
88+
89+
*([$a],\"hello\") : int\*string*
90+
===
91+
*([$b].4,true,#\"q\") : real\*bool\*char*
92+
===
93+
*(([$b].4,true),#\"q\") : (real\*bool)\*char*
94+
===
95+
*\[false\] : bool list*
96+
===
97+
*\[\[[$c]\]\] : int list list*
98+
99+
100+
END_PGML_SOLUTION
101+
102+
ENDDOCUMENT();
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
## DESCRIPTION
2+
## Generates ML expressions using tuples and lists and asks for their types.
3+
## ENDDESCRIPTION
4+
5+
## DBsubject(Programming Languages)
6+
## DBchapter(ML)
7+
## DBsection(Data Structures)
8+
## Date(12/04/2025)
9+
## Institution(Louisiana Tech)
10+
## Author(Jason Terry)
11+
## Level(2)
12+
## KEYWORDS('programming languages','ml','sml','expressions','type','tuple','list')
13+
14+
15+
DOCUMENT();
16+
17+
## Load libraries
18+
loadMacros(
19+
"PGstandard.pl",
20+
"PGcourse.pl",
21+
"contextArbitraryString.pl",
22+
"PGML.pl"
23+
);
24+
25+
## Change context to strings answers
26+
Context("ArbitraryString");
27+
28+
## Create custom answer checker for ML types
29+
$typeChecker = sub {
30+
my ($correct,$student,$ansHash) = @_; # get correct and student MathObjects
31+
$correct = $correct->string;
32+
$student = $student->string;
33+
$student =~ s/^ *(.*?) *$/$1/; # remove front/end whitespace
34+
$student =~ s/ *~~* */~~*/g; # * shall have no space on each side
35+
$student =~ s/~~( */~~(/g; # ( shall have no space after
36+
$student =~ s/ *~~)/~~)/g; # ) shall have no space before
37+
$student =~ s/ *list/ list/g; # list shall have 1 space before
38+
return ($correct eq $student); # return 1 if correct, 0 otherwise
39+
};
40+
41+
$a = random(1,20,1);
42+
$b = random(1,20,1);
43+
$c = random(1,20,1);
44+
45+
## Create answers to problems and install custom type checker
46+
$ans1 = String("int*int")->cmp(
47+
checker => $typeChecker
48+
);
49+
50+
$ans2 = String("int list*int")->cmp(
51+
checker => $typeChecker
52+
);
53+
54+
$ans3 = String("(int*int) list")->cmp(
55+
checker => $typeChecker
56+
);
57+
58+
$ans4 = String("real*(string*int list)")->cmp(
59+
checker => $typeChecker
60+
);
61+
62+
$ans5 = String("((int*int)*int) list")->cmp(
63+
checker => $typeChecker
64+
);
65+
66+
67+
## Display question
68+
TEXT(beginproblem());
69+
70+
BEGIN_PGML
71+
Write the type of the following ML expressions. *WARNING: Only use required parentheses for types to match the ML compiler's response.*
72+
73+
*([$a], [$b]) : [_________________________]{$ans1}*
74+
===
75+
*(\[[$a]\], [$b]) : [_________________________]{$ans2}*
76+
===
77+
*\[([$a],[$b])\] : [_________________________]{$ans3}*
78+
===
79+
*([$a].77,(\"[$b]\",\[[$c]\])) : [_________________________]{$ans4}*
80+
===
81+
*\[(([$a],[$b]),[$c])\] : [_________________________]{$ans5}*
82+
83+
84+
END_PGML
85+
86+
BEGIN_PGML_SOLUTION
87+
Solution:
88+
89+
*([$a],\"hello\") : int\*string*
90+
===
91+
*([$b].4,true,#\"q\") : real\*bool\*char*
92+
===
93+
*(([$b].4,true),#\"q\") : (real\*bool)\*char*
94+
===
95+
*\[false\] : bool list*
96+
===
97+
*\[\[[$c]\]\] : int list list*
98+
99+
100+
END_PGML_SOLUTION
101+
102+
ENDDOCUMENT();

0 commit comments

Comments
 (0)