- objects contain:
- data in the form of member variables (also called instance variables).
- as well as the functions we can use to interact with that data, in the form of member functions.
- objects allow us to provide information hiding.
- We cannot see and interact with the private members of an object.
- We can only use the public member functions.
- A class is a blueprint for objects (technically a bit more).
- Name and type of the member variables.
// segfault_example | |
// author: Haris Skiadas | |
// date: 2-14-20 | |
// Compile with something like: | |
// g++ segfault_example.cpp -ldw -g -pthread -lgtest -o segfault_example | |
// ./segfault_example | |
#include "gtest/gtest.h" |
- Download the zip file from Moodle. Unzip the file in your downloads directory. You should now be seeing a project directory named "AVLTreeAssignment". The other directory, _MACOSX, can be ignored.
- Copy the AVLTreeAssignment directory and paste it into your IDEA projects directory, or simply move the AVLTreeAssignment directory into your IDEA projects directory.
- Start IntelliJ IDEA and Close your current project if you have one open. You should be seeing the IDEA welcome screen.
- Choose "Create New Project". Make sure Java is selected, and click on Next twice to get to the screen that prompts for a project name. Use the file popup to the right of the "project location" line to select the
AVLTreeAssignment
directory from inside your IDEA projects directory. Then click Finish to complete the Project creation process. - Go to the File->Project Structure menu, and select the Modules tab on the sidebar. You should be seeing the src and test folders in the middle area of
- What is a directed acyclic graph?
- Example: CS major course prerequisites.
- What is a topological sorting for such a graph?
- How does DFS work in a directed graph? When will we encounter back-edges in this case?
- Perform DFS, noting the order in which vertices become dead-ends.
As always, these problems go far and beyond what is required/expected from the class, and should only be pursued after you have finished all other requirements for the week. That being said, you might find the problems in the first section a good practice in understanding how MUPL works, and as good tests of your MUPL interpreter.
We will write here more MUPL macros and functions. A "MUPL function" is basically a Racket definition of a (fun ...)
MUPL expression. A "MUPL macro" is a Racket function that takes in MUPL expressions and produces a MUPL expression.
- We will start with "boolean" expressions. A boolean expression is going to be a MUPL expression that always evaluates to either
int 1
(mupl-true) orint 0
(mupl-false). You might find it convenient to create those synonyms first. - Write a MUPL macro
mupl-if
that takes a boolean expressione1
and two more MUPL expressionse2
,e3
. It would evaluatee1
, and if it is equal tomupl-true
then it evalua
Most of this will make sense once you hit the "conditionals" part of the project.
It is important to understand how the desugarer differs from the interpreter. Think of the desugarer as a "program transformation". You give it a program in one form, and it turns it into another form. It does NO evaluation of the program, only a syntactic transformation.
For example if you recall in the early days we talked about the expression: e1 or e2
and how we can instead get the same thing going with if
statements:
if e1
The thing that students have the hardest time on when learning functional programming is how to process a recursive structure while maintaining some sort of "state", the result if you will. I'll attempt here to demystify the process.
Functional programming languages almost always use a lot of recursively defined structures. Depending on the language those can be implemented in various ways, but in any case the end result is the same. A structure of this type is either an "atom", i.e. an irreducible thing, or a "compound" consisting of substructures of the same form.
For example a "list" is either an Empty/Nil list (the "atom") or it is formed as a Cons of a value and another list (compound form). That other "sublist" can itself be empty or another cons and so on and so forth. A tree is similar. It is either empty, or it consists of a triple of a value and two sub-trees, left and right.
Almost every problem we encounter is a question about doing something with all entries in a structure. To solve these prob
fun divisible x xs = | |
case xs of | |
[] => false | |
| y::xs' => x mod y = 0 orelse divisible x xs' | |
fun primes lst = | |
let fun acc(x, rest) = | |
if divisible x rest then rest else x::rest | |
in rev (foldl acc [] lst) | |
end |