emacs - c auto insert
authorPeng Li <seudut@gmail.com>
Tue, 13 Sep 2016 12:15:32 +0000 (20:15 +0800)
committerPeng Li <seudut@gmail.com>
Tue, 13 Sep 2016 12:15:32 +0000 (20:15 +0800)
emacs.d/config.org
study-note.org

index b9c0209..df43076 100644 (file)
@@ -2135,7 +2135,7 @@ Set the environments vairables in compilation mode
           (file-name-nondirectory (buffer-file-name)))
          ".hpp\"" \n \n
          "using namespace std;" \n \n
-         "int main ()"
+         "int main (int argc, char *argv[])"
          "\n{" \n 
          > _ \n
          "return 0;"
@@ -2154,7 +2154,7 @@ Set the environments vairables in compilation mode
          (file-name-sans-extension
           (file-name-nondirectory (buffer-file-name)))
          ".h\"" \n \n
-         "int main ()\n"
+         "int main (int argc, char *argv[])\n"
          "{" \n
          > _ \n
          "return 0;\n"
index e9cc7d9..3935a5e 100644 (file)
@@ -169,3 +169,238 @@ actions baed upon such information as whether other modes are enabled in the cur
 
 * Books
 ** Intruduction to Algorithms 
+*** Foundations
+**** The Role of Algorithms in Computing
+** SICP (Structure and Interpretation of Computer Programs)
+*** Building Abstractions with Procedures
+
+The acts of the mind, wherein it exerts its power over simple ideas, are chiefly there threee: 1.
+Combining serveral simple ideas into one compund one, and thus all complex ideas are made. 2. The
+second is bringing two idears, whether simple or complex, together, and setting them by one another
+so as to take a view of them at once, without uniting them into one, by which it gets all its ideas
+of relations. 3. The third is separating them from all other ideas that accmpany them in there real
+existence: this is called abstraction, and thus all its general ideas are made.
+
+-- Jone Locke, An Essay Concerning Human Understanding (1690)
+
+We are about to study the idea of computational process. Computational processes are abstract being
+that inhabit computers. As they evolve, process manipulate other abstract things called data.
+The evolution of a process in directed by a pattern of rules called a /programm/. People create
+programs to direct processes. In effect, we conjure the spirits of the computer with our spells.
+
+    A computaional process is indeed much like a sorcerer's idea of a spirit. It cannot be seen or
+touched. It is composed of matter at all. However, it is very real. It can perform intellectual work.
+It can answer questions. It can affect the world by disbursing money at a bank or by controlling 
+a rebot arm in a factory. The programs we use to conjure processes are like a sorcerer's spell.
+They are carefully composed from symbolic expressions in arcane and esoteric /programming languages/
+that prescribe the tasks we want our processes to perform
+
+**** The Elements of Programming
+
+When we describe a language, we should pay particular attentation to the means that the language
+provides for combining simple ideas to form more complex ideas. Every powerful language has three
+mechanisms for accomplishing this:
+
+- *primitive expressions*, which represent the simplest entities the language is concerned with,
+- *means of combination*, by which compound elements are built from simpler ones, and
+- *means of abstraction*, by which compund elements can be names and manipulated as units.
+
+In programming, we deal with two kinds of elements: /procedures/ and /data/. (Later we will discover
+that they are really not so distinct.)
+
+***** Expressions
+
+***** Naming and the Environment
+
+#+BEGIN_SRC scheme
+  (define size 2)
+#+END_SRC
+
+***** Evaluating Combinations
+To evaluate a combination, do the follow:
+- Evaluate the subexpressions of the combination.
+- Apply the procedure that is the value of the leftmost subexpression (the operator) to the
+  values of the other subexpressions (the operands).
+
+***** Compound Procedures
+
+We have identified in Lisp some of the elements that must appear in any powerful programming
+language:
+
+- Numbers and arithmetic operations are primitive data and procedures.
+- Nesting of combinations provides a means of combining operations..
+- Definitions that associate names with values provide a limited means of abstraction.
+
+The general form of a *procedure definition* is 
+#+BEGIN_SRC scheme
+  (define (<name> <formal parameters>)
+    <body>)
+#+END_SRC
+
+***** The Substitution Model for Procedure Application
+
+To apply a compound procedure to arguments, evaluate the body of the procedure with each formal
+parameter replaced by the corresponding argument.
+
+Applicative order versus normal order
+
+***** Conditional Expressions and Predicates
+=cond= , which stands for "conditional"
+#+BEGIN_SRC scheme
+  (cond (<p1> <e1>)
+        (<p2> <e1>)
+        ...
+        (<pn> <en>))
+#+END_SRC
+
+consisting of the symbol =cond= followed by parenthesized pais of expressions =(<p> <e>)=
+called /clauses/. The first expression in each pair is a /predicate/-that is, and expression
+whose value is interpreted as either true or false.
+
+=else=, is a special symbol that can be used in place of =<p>= in the final clause of a =cond=
+#+BEGIN_SRC scheme
+  (define (abs x)
+    (cond ((<x 0) (-x))
+          (else x)))
+#+END_SRC
+
+=if=
+#+BEGIN_SRC scheme
+  (if <predicate> <consequent> <alternative>)
+#+END_SRC
+
+- =and=, =or=, =not=
+#+BEGIN_SRC scheme
+  (and <e1> ... <en>)
+
+  (or <e1> ... <en>)
+
+  (not <e>)
+#+END_SRC
+
+****** Exercise
+- 1.2
+#+BEGIN_SRC scheme
+  (/ (+ 5
+        4
+        (- 2
+           (- 3
+              (+ 6
+                 (/ 4 5)))))
+     (* 3
+        (- 6 2)
+        (- 2 7)))
+#+END_SRC
+
+- 1.3
+#+BEGIN_SRC racket
+  (define (sum-two-larger a b c)
+    (cond ((and (> a b) (> c b)) (+ a c))
+          ((and (> c a) (> b a)) (+ c b))
+          ((and (> a c) (> b c)) (+ a b))))
+  ;; test
+  (sum-two-larger 1 2 3)
+  (sum-two-larger 7 3 5)
+
+  ;; another way
+  (define (minimal-of-two a b)
+    (if (> a b)
+        b
+        a))
+
+  (define (sum-two-larger-2 a b c)
+    (-  (+ a b c) (minimal-of-two a (minimal-of-two b c))))
+
+  (sum-two-larger-2 1 2 3)
+#+END_SRC
+
+***** Example: Square Roots by Newton's Method
+
+***** Procedures as Black-Box Abstractions
+
+- Local Name
+
+- Internal definitions and block structure
+
+
+**** Procedures and the Processes They Generate   
+
+***** 1.2.1 Linear Recursion and Iteration
+sample, factorial function of n!
+
+***** 1.2.2 Tree Recursion
+Fibonacci number
+
+***** 1.2.3 Orders of Grouth
+
+***** 1.2.4 Exponentiation
+b^3
+
+***** 1.2.5. Greatest Common Divisior
+
+***** 1.2.6 Example: Testing for Primality
+- Fermat test
+Fermat's Little Theorem:
+
+**** Formulating Abstractions with Higher-Order Procedures
+
+Procedures that manipulate procedures are called /higher-order procedures/. 
+
+***** 1.3.1 Procedures as Arguments
+#+BEGIN_SRC scheme
+  (define (inc n) (+ n 1))
+  (define (cube a) (* a a a))
+  (define (sum-cubes a b)
+    (+ cube a inc b))
+
+  (sum-cubes 1 10)
+#+END_SRC
+
+***** 1.3.2 Constructing Procedures Using lambda
+#+BEGIN_SRC scheme
+  (lambda (<formal-parameters>) <body>)
+#+END_SRC
+
+In general, =lambda= is used to create procedures in the same way as =define= except that no
+name is specified for the procedure
+
+Like any expression that has a procedure as its values. a =lambda= expression can be used as 
+the operator in a combination such as
+#+BEGIN_SRC scheme
+  ((lambda (x y z) (+ x y (square z)))
+   1 2 3)
+
+  12
+#+END_SRC
+
+Useing =let= to create local variable
+#+BEGIN_SRC scheme
+  (let ((<var1> <exp1>)
+        (<var2> <exp2>)
+        ...
+        (<varn> <expn>))
+    <body>)
+#+END_SRC
+
+***** 1.3.3 Procedures as General Methods
+
+***** 1.3.4 Procedures as Returned Values
+Sample
+#+BEGIN_SRC scheme
+  (define (average-damp f)
+    (lambda (x) (average x (f x))))
+
+  ((average-damp square) 10)
+  55
+#+END_SRC
+
+*** Building Abstractions with Data
+#+BEGIN_SRC scheme
+  (define a 3)
+  a
+#+END_SRC
+
+#+RESULTS:
+: 3
+