CSCI 2041 Week 1 notes
CSCI 2041 Week 1 notes CSCI 2041
U of M
Popular in Advanced Programming Principles
Popular in Computer Science and Engineering
This 3 page Class Notes was uploaded by Lauren Arbisi on Monday August 15, 2016. The Class Notes belongs to CSCI 2041 at University of Minnesota taught by James Moen in Fall 2016. Since its upload, it has received 411 views. For similar materials see Advanced Programming Principles in Computer Science and Engineering at University of Minnesota.
Reviews for CSCI 2041 Week 1 notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 08/15/16
Written by Lauren Arbisi Week 1Notes CSCI 2041 Fall 2016 James Moen Wednesday, September 7, 2016 1. Administrative stuff a. First time teaching class. b. No textbook for this class. i. Clojure is a relatively new language. ii. Functional programming generally doesn’t have good texts. c. 3 projects, 2 midterms, 1 final for this course. d. We’ll learn a little bit of OCaml at the end of the semester because previous teachers often have taught in their classes. 2. Functional programming a. Paradigms in programming i. Procedural programming: like C and Fortran ii. Object-oriented programming: like Java and Python iii. Functional programming: like Clojure and OCaml 1. Treats computation as evaluation of expressions (involve functions) and avoids state changes and mutable data (variables). 2. Functional programming doesn’t change variables. It uses nested functions. b. Why we use functional programming: multi-processing. i. Moore’s “Law”: the number of transistors in computers doubles every 2 years. In Professor Moen’s words, “We get better and better at building computers, and we can cram more and more transistors into them, making them increasingly powerful.” ii. Moore’s “Law” will eventually be disproven… because that’s how the universe works. iii. Computing power will continue to increase by making computers with multiple processors that run simultaneously. c. Multi-processing needs functional programming to work properly. Here is an example of non-functional programming messing up a multi-processing situation. In the diagram above, P and P represent separate processors which both have pointers to the top of 1 2 the stack. In this situation,1P needs to push to the stack and 2 needs to pop from the stack. i. Imagine that P 1ushes a new element called D first, then P p2ps. Element P has2popped D. ii. Imagine that P2pops first, then P1pushes a new element called D. Element P ha2 popped C. iii. If 1 pushes and P 2ops at the exact same time, you’re probably screwed due to the limitations of computer hardware. iv. In any situation, the outcome is different! d. Let’s take a look at what would happen if the pointers went directly to the top element of the stack, effectively eliminating the “top” variable. Written by Lauren Arbisi In the diagram above, P a1d P rep2esent separate processors which both have pointers to the first element of the stack. In this situation, P1needs to push to the stack and P ne2ds to pop from the stack. i. Imagine that P p1shes a new element called D first, then P pops2 Because P ’s poin2er was still pointing to element C after P 1ushed D, P po2ped C. ii. Imagine that P 2ops first, then P 1ushes a new element called D. Element P has po2ped C. iii. If 1 pushes and P 2ops at the exact same time, P wil2 have popped C for the same reasons given in situation i. iv. Because of the flexibility afforded by functional programming, we can basically do the the steps in any order. 3. Clojure a. Clojure is a member of the Lisp family. i. How it got its name: Lis(t) p(rocessor). ii. Lisp is the 2 oldest programming language still in widespread use. iii. Lisp 1 was introduced by John McCarthy and his students in 1958. iv. Lisp uses homoiconicity, meaning that programs and data have the same representation. (Programs work on other programs.) v. Lisp 1.5 (1960) has many derivatives, most notably: 1. Scheme (1975) 2. Common Lisp (1984) 3. Clojure (2007) b. Homoiconicity in Clojure i. (F a b c) can work as a data structure: a list/sequence with 4 parts: F, a, b, and c. ii. (F a b c) could be calling function F with parameters a, b, and c. c. Example program defining a factorial function. (def factorial (fn [n] (if (= n 0 (* n (factorial (- n 1))))))) Friday, September 9, 2016 1. Clojure runs on the Java virtual machine. Where Java runs, Clojure runs. 2. Parts of Clojure functions a. Literals: evaluate to themselves. i. Numbers (as in Java) ii. Strings (“…”) iii. Characters (\c, \newline, \backspace, etc…) iv. Boolean values (false, true) Written by Lauren Arbisi v. nil (pointer to nothing, like Java’s null.) vi. Keywords b. Symbols: names/identifiers i. Name can be bound to a value. ii. Starts with a non-numeric character and can contain alphanumeric characters and these other characters: *, +, !, -, _, ', and ? c. Composite forms i. List 1. This is an empty list:() 2. This is a filled li(e:1 e2 … e k 3. Jth element O(j) ii. Vector 1. This is an empty vector  2. This is a filled vecto[e 1 e 2 … e k 3. A vector is like an array, except that its elements can be any form. 4. Jth element O(1) d. Special Forms: look like functions, but may evaluate their arguments in unusual ways. i. def (def n e) binds n to the result of evaluating e. ii. fn (in other Lisp languages, called lambda) (fn [p 1 p 2 … p k e) results in a function with parameters p1, 2,d p akd body e. iii. quote 1. (quote e) returns e without evaluating it. Can also be written as‘e 2. ‘(F a b c) returns the list with elements F, a, b, and c. iv. Commenting: ;comment until end of line