Skip to content

Commit 6d6f248

Browse files
authored
Merge pull request #1336 from jpaulterry/master
Update University Contact Info/New Problems for a Programming Languages course in Computer Science
2 parents 0abad1d + b1d9a29 commit 6d6f248

File tree

7 files changed

+482
-2
lines changed

7 files changed

+482
-2
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
## DESCRIPTION
2+
## Generates arithmetic expressions in ML and asks for value and type.
3+
## ENDDESCRIPTION
4+
5+
## DBsubject(Programming Languages)
6+
## DBchapter(ML)
7+
## DBsection(BasicTypesOperators)
8+
## Date(12/04/2025)
9+
## Institution(Louisiana Tech)
10+
## Author(Jason Terry)
11+
## Level(2)
12+
## KEYWORDS('programming languages','ml','sml','expressions','type','operators')
13+
14+
15+
DOCUMENT();
16+
17+
## Load libraries
18+
loadMacros(
19+
"PGstandard.pl",
20+
"PGcourse.pl",
21+
"parserPopUp.pl",
22+
"PGML.pl"
23+
);
24+
25+
## Change context to numeric answers
26+
Context("Numeric");
27+
28+
## Generate random numbers for problems.
29+
$a = random(1,3,1);
30+
$b = random(4,6,1);
31+
$c = random(7,9,1);
32+
$d = random(1,7,2);
33+
34+
## Generate solutions to problems
35+
$ans1 = $a + $b * $c;
36+
$ans2 = ($a + $b) * $c;
37+
$ans3 = $c - $d/2.0;
38+
$ans4 = int(($b*$c)/3);
39+
$ans5 = ($b*$c) % 3;
40+
41+
## Create the popup menus with the correct ML type answers
42+
$popInt = PopUp(["Choose...","int","bool","real","char","string"], 1);
43+
$popBool = PopUp(["Choose...","int","bool","real","char","string"], 2);
44+
$popReal = PopUp(["Choose...","int","bool","real","char","string"], 3);
45+
$popChar = PopUp(["Choose...","int","bool","real","char","string"], 4);
46+
$popString = PopUp(["Choose...","int","bool","real","char","string"], 5);
47+
48+
## Display question
49+
TEXT(beginproblem());
50+
51+
BEGIN_PGML
52+
Determine the value and type returned when the following ML expressions are evaluated.
53+
54+
*[$a] + [$b] * [$c];*
55+
56+
*val it = [__________]{$ans1} : [_____]{$popInt}*
57+
===
58+
*([$a] + [$b]) * [$c];*
59+
60+
*val it = [__________]{$ans2} : [_____]{$popInt}*
61+
===
62+
*[$c].0 - [$d].0 / 2.0;*
63+
64+
*val it = [__________]{$ans3} : [_____]{$popReal}*
65+
===
66+
*([$b]\*[$c]) div 3;*
67+
68+
*val it = [__________]{$ans4} : [_____]{$popInt}*
69+
===
70+
*([$b]\*[$c]) mod 3;*
71+
72+
*val it = [__________]{$ans5} : [_____]{$popInt}*
73+
74+
75+
END_PGML
76+
77+
BEGIN_PGML_SOLUTION
78+
Solution:
79+
80+
*[$a] + [$b] * [$c];*
81+
82+
*val it = [$ans1] : [$popInt] *
83+
===
84+
*([$a] + [$b]) * [$c];*
85+
86+
*val it = [$ans2] : [$popInt] *
87+
===
88+
*[$c].0 - [$d].0 / 2.0;*
89+
90+
*val it = [$ans3] : [$popReal] *
91+
===
92+
*([$b]\*[$c]) div 3;*
93+
94+
*val it = [$ans4] : [$popInt] *
95+
===
96+
*([$b]\*[$c]) mod 3;*
97+
98+
*val it = [$ans5] : [$popInt] *
99+
100+
END_PGML_SOLUTION
101+
102+
ENDDOCUMENT();
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
## DESCRIPTION
2+
## Generates bool, string, and int expressions in ML
3+
## using if-then-else and asks for their values and types.
4+
## ENDDESCRIPTION
5+
6+
## DBsubject(Programming Languages)
7+
## DBchapter(ML)
8+
## DBsection(BasicTypesOperators)
9+
## Date(12/04/2025)
10+
## Institution(Louisiana Tech)
11+
## Author(Jason Terry)
12+
## Level(2)
13+
## KEYWORDS('programming languages','ml','sml','expressions','type','operators','string','ifthenelse','bool')
14+
15+
16+
DOCUMENT();
17+
18+
## Load libraries
19+
loadMacros(
20+
"PGstandard.pl",
21+
"PGcourse.pl",
22+
"contextArbitraryString.pl",
23+
"parserPopUp.pl",
24+
"PGML.pl"
25+
);
26+
27+
## Change context to strings answers
28+
Context("ArbitraryString");
29+
30+
## Create answer to static problem
31+
$ans1 = String("~~"arcsine~~"");
32+
33+
## Create parameters for boolean statements
34+
$a = random(1,20,1);
35+
$b = random(1,20,1);
36+
$c = random(1,3,1);
37+
$d = random(21,30,1);
38+
$e = random(31,40,1);
39+
40+
## Create answers to boolean statements
41+
if ($a < $b) { $ans2 = String("~~"yes~~""); } else { $ans2 = String("~~"no~~""); }
42+
if ($c == 2) {$ans3 = $d;} else {$ans3 = $e;}
43+
if ($c == 3) {$ans4 = String("false");} else {$ans4 = String("true");}
44+
if ($a < $b || $c == 2) {$ans5 = String("true");} else {$ans5 = String("false");}
45+
46+
## Create the popup menus with the correct ML type answers
47+
$popInt = PopUp(["Choose...","int","bool","real","char","string"], 1);
48+
$popBool = PopUp(["Choose...","int","bool","real","char","string"], 2);
49+
$popReal = PopUp(["Choose...","int","bool","real","char","string"], 3);
50+
$popChar = PopUp(["Choose...","int","bool","real","char","string"], 4);
51+
$popString = PopUp(["Choose...","int","bool","real","char","string"], 5);
52+
53+
## Display question
54+
TEXT(beginproblem());
55+
56+
BEGIN_PGML
57+
Determine the value and type returned when the following ML expressions are evaluated.
58+
59+
*\"arc\" ^ \"sine\" ^ \"\";*
60+
61+
*val it = [__________]{$ans1} : [_____]{$popString}*
62+
===
63+
*if ([$a] < [$b]) then \"yes\" else \"no\";*
64+
65+
*val it = [__________]{$ans2} : [_____]{$popString}*
66+
===
67+
*if ([$c] = 2) then [$d] else [$e];*
68+
69+
*val it = [__________]{$ans3} : [_____]{$popInt}*
70+
===
71+
*if ([$c] = 3) then false else true;*
72+
73+
*val it = [__________]{$ans4} : [_____]{$popBool}*
74+
===
75+
*[$a] < [$b] orelse [$c] = 2;*
76+
77+
*val it = [__________]{$ans5} : [_____]{$popBool}*
78+
79+
80+
END_PGML
81+
82+
BEGIN_PGML_SOLUTION
83+
Solution:
84+
85+
*\"arc\" ^ \"sine\" ^ \"\";*
86+
87+
*val it = [$ans1] : [$popString] *
88+
===
89+
*if ([$a] < [$b]) then \"yes\" else \"no\";*
90+
91+
*val it = [$ans2] : [$popString] *
92+
===
93+
*if ([$c] = 2) then [$d] else [$e];*
94+
95+
*val it = [$ans3] : [$popInt] *
96+
===
97+
*if ([$c] = 3) then false else true;*
98+
99+
*val it = [$ans4] : [$popBool] *
100+
===
101+
*[$a] < [$b] orelse [$c] = 2;*
102+
103+
*val it = [$ans5] : [$popBool] *
104+
105+
END_PGML_SOLUTION
106+
107+
ENDDOCUMENT();
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
## DESCRIPTION
2+
## Generates expressions using coercion in ML and asks for value and type.
3+
## ENDDESCRIPTION
4+
5+
## DBsubject(Programming Languages)
6+
## DBchapter(ML)
7+
## DBsection(BasicTypesOperators)
8+
## Date(12/04/2025)
9+
## Institution(Louisiana Tech)
10+
## Author(Jason Terry)
11+
## Level(2)
12+
## KEYWORDS('programming languages','ml','sml','expressions','type','operators','ceil','floor','chr','str','ord','coercion')
13+
14+
15+
DOCUMENT();
16+
17+
## Load libraries
18+
loadMacros(
19+
"PGstandard.pl",
20+
"PGcourse.pl",
21+
##"niceTables.pl",
22+
##"contextArbitraryString.pl",
23+
"parserPopUp.pl",
24+
"PGML.pl"
25+
);
26+
27+
## Change context to numeric answers
28+
Context("Numeric");
29+
30+
## Create string for output
31+
Context()->strings->add("~~"Q~~"" => {caseSensitive => 1});
32+
Context()->strings->add("#~~"a~~"" => {caseSensitive => 1});
33+
34+
## Generate random numbers for problems.
35+
$a = random(-30.1,-10.1,0.2);
36+
$b = random(100,115,1);
37+
$c = random(7,9,1);
38+
$d = random(1,7,2);
39+
40+
## Generate solutions to problems
41+
$ce = ceil($a);
42+
$fl = floor($a);
43+
$abs_a = abs($a);
44+
$p = abs($ce);
45+
$q = abs($fl);
46+
Context()->strings->add("~~~$p" => {caseSensitive => 1});
47+
Context()->strings->add("~~~$q" => {caseSensitive => 1});
48+
$ans1 = String("~~~$p");
49+
$ans2 = String("~~~$q");
50+
$ans3 = $b;
51+
$ans4 = String("~~"Q~~"");
52+
$ans5 = String("#~~"a~~"");
53+
54+
## Create the popup menus with the correct ML type answers
55+
$popInt = PopUp(["Choose...","int","bool","real","char","string"], 1);
56+
$popBool = PopUp(["Choose...","int","bool","real","char","string"], 2);
57+
$popReal = PopUp(["Choose...","int","bool","real","char","string"], 3);
58+
$popChar = PopUp(["Choose...","int","bool","real","char","string"], 4);
59+
$popString = PopUp(["Choose...","int","bool","real","char","string"], 5);
60+
61+
## Display question
62+
TEXT(beginproblem());
63+
64+
BEGIN_PGML
65+
Determine the value and type returned when the following ML expressions are evaluated.
66+
67+
*ceil(~[$abs_a]);*
68+
69+
*val it = [__________]{$ans1} : [_____]{$popInt}*
70+
===
71+
*floor(~[$abs_a]);*
72+
73+
*val it = [__________]{$ans2} : [_____]{$popInt}*
74+
===
75+
*ord(chr([$b]));*
76+
77+
*val it = [__________]{$ans3} : [_____]{$popInt}*
78+
===
79+
*str(#\"Q\");*
80+
81+
*val it = [__________]{$ans4} : [_____]{$popString}*
82+
===
83+
*chr(97);*
84+
85+
*val it = [__________]{$ans5} : [_____]{$popChar}*
86+
87+
88+
END_PGML
89+
90+
BEGIN_PGML_SOLUTION
91+
Solution:
92+
93+
No solution available yet.
94+
95+
96+
END_PGML_SOLUTION
97+
98+
## There is some mistake in the PGML CODE Solution below
99+
## *ceil(~[$abs_a]);*
100+
##
101+
## *val it = [$ans1] : [$popInt]*
102+
##===
103+
## *floor(~[$abs_a]);*
104+
##
105+
## *val it = [$ans2] : [$popInt]*
106+
##===
107+
## *ord(chr([$b]));*
108+
##
109+
## *val it = [$ans3] : [$popInt]*
110+
##===
111+
## *str(#\"Q\");*
112+
##
113+
## *val it = [$ans4] : [$popString]*
114+
##===
115+
## *chr(97);*
116+
##
117+
## *val it = [$ans5] : [$popChar]*
118+
119+
ENDDOCUMENT();

0 commit comments

Comments
 (0)