3 #+EMAIL: seudut@gmail.com
6 * Programming Languages
10 #+BEGIN_SRC sh :exports both :results output replace
17 Usage: perl [switches] [--] [programfile] [arguments]
18 -0[octal] specify record separator (\0, if no argument)
19 -a autosplit mode with -n or -p (splits $_ into @F)
20 -C[number/list] enables the listed Unicode features
21 -c check syntax only (runs BEGIN and CHECK blocks)
22 -d[:debugger] run program under debugger
23 -D[number/list] set debugging flags (argument is a bit mask or alphabets)
24 -e program one line of program (several -e's allowed, omit programfile)
25 -E program like -e, but enables all optional features
26 -f don't do $sitelib/sitecustomize.pl at startup
27 -F/pattern/ split() pattern for -a switch (//'s are optional)
28 -i[extension] edit <> files in place (makes backup if extension supplied)
29 -Idirectory specify @INC/#include directory (several -I's allowed)
30 -l[octal] enable line ending processing, specifies line terminator
31 -[mM][-]module execute "use/no module..." before executing program
32 -n assume "while (<>) { ... }" loop around program
33 -p assume loop like -n but print line also, like sed
34 -s enable rudimentary parsing for switches after programfile
35 -S look for programfile using PATH environment variable
36 -t enable tainting warnings
37 -T enable tainting checks
38 -u dump core after parsing program
39 -U allow unsafe operations
40 -v print version, patchlevel and license
41 -V[:variable] print configuration summary (or a single Config.pm variable)
42 -w enable many useful warnings
43 -W enable all warnings
44 -x[directory] ignore text before #!perl line (optionally cd to directory)
45 -X disable all warnings
47 Run 'perldoc perl' for more help with Perl.
53 perl -ne 'print if /expression/' xxx.log;
56 #+BEGIN_SRC perl :results output replace
58 ($tt =~ /h(.*)o/ ) and print $1;
66 perl -wnl -e '/keyword/ and print;' xxx.log
71 perl -ne 'print "$1\n" if /aaa=(\d+)\s.*/' xxx.log;
74 #+BEGIN_SRC fundamental :tangle ./temp/aa.txt
81 #+BEGIN_SRC sh :results output replace
82 perl -wnl -e 'print "==$.: $_"' ./temp/aa.txt
93 See special variable in perl [[http://perldoc.perl.org/perlvar.html][perlvar]], or =perldoc perlvar=
94 - =$.= Current line number
99 #+BEGIN_SRC gnuplot :exports code :file ./temp/sin.png
105 [[file:./temp/sin.png]]
107 2. plot with data file
108 #+BEGIN_SRC fundamental :tangle ./temp/plot.dat
121 #+BEGIN_SRC gnuplot :file ./temp/ll.png
125 plot "./temp/plot.dat" using 1:2 with lines
129 [[file:./temp/ll.png]]
133 #+BEGIN_SRC sh :results output replace
134 netstat -atn # For tcp port
135 netstat -aun # For udp port
140 #+BEGIN_SRC sh :results output replace
141 # listening on port 1234 for a connection
144 # connect to the machine and port
149 ** =add-hook= vs =eval-after-load=
150 Ref [[http://stackoverflow.com/questions/2736087/eval-after-load-vs-mode-hook][eval-after-load-vs-mode-hook]]
152 Code wrapped in =eval-after-load= will be executed only once, so it is typically used to perform
153 one-time setup such as setting default global values and behaviour. An example might be setting
154 up a default keymap for a particular mode. In =eval-after-load= code, there's no notion of the
157 Mode hooks exectue once for every buffer in which the mode is enabled, so they're used for per-buffer
158 configuration. Mode hooks are therefore run later than =eval-after-load= code; this lets them take
159 actions baed upon such information as whether other modes are enabled in the current buffer.
163 ** =#import= vs. =#include=
164 [[http://stackoverflow.com/questions/439662/what-is-the-difference-between-import-and-include-in-objective-c][what-is-the-difference-between-import-and-include-in-objective-c]]
165 - =#import= directive as added to Objective-C as an improvied version of =#include=
166 - =#import= ensures that a file is only ever included onces so that you never have a problem with recursive includes
167 - Bacically, use =#import= for Objective-C thins, =#include= for C stufff.
171 ** Intruduction to Algorithms
173 **** The Role of Algorithms in Computing
174 ** SICP (Structure and Interpretation of Computer Programs)
175 *** Building Abstractions with Procedures
177 The acts of the mind, wherein it exerts its power over simple ideas, are chiefly there threee: 1.
178 Combining serveral simple ideas into one compund one, and thus all complex ideas are made. 2. The
179 second is bringing two idears, whether simple or complex, together, and setting them by one another
180 so as to take a view of them at once, without uniting them into one, by which it gets all its ideas
181 of relations. 3. The third is separating them from all other ideas that accmpany them in there real
182 existence: this is called abstraction, and thus all its general ideas are made.
184 -- Jone Locke, An Essay Concerning Human Understanding (1690)
186 We are about to study the idea of computational process. Computational processes are abstract being
187 that inhabit computers. As they evolve, process manipulate other abstract things called data.
188 The evolution of a process in directed by a pattern of rules called a /programm/. People create
189 programs to direct processes. In effect, we conjure the spirits of the computer with our spells.
191 A computaional process is indeed much like a sorcerer's idea of a spirit. It cannot be seen or
192 touched. It is composed of matter at all. However, it is very real. It can perform intellectual work.
193 It can answer questions. It can affect the world by disbursing money at a bank or by controlling
194 a rebot arm in a factory. The programs we use to conjure processes are like a sorcerer's spell.
195 They are carefully composed from symbolic expressions in arcane and esoteric /programming languages/
196 that prescribe the tasks we want our processes to perform
198 **** The Elements of Programming
200 When we describe a language, we should pay particular attentation to the means that the language
201 provides for combining simple ideas to form more complex ideas. Every powerful language has three
202 mechanisms for accomplishing this:
204 - *primitive expressions*, which represent the simplest entities the language is concerned with,
205 - *means of combination*, by which compound elements are built from simpler ones, and
206 - *means of abstraction*, by which compund elements can be names and manipulated as units.
208 In programming, we deal with two kinds of elements: /procedures/ and /data/. (Later we will discover
209 that they are really not so distinct.)
213 ***** Naming and the Environment
219 ***** Evaluating Combinations
220 To evaluate a combination, do the follow:
221 - Evaluate the subexpressions of the combination.
222 - Apply the procedure that is the value of the leftmost subexpression (the operator) to the
223 values of the other subexpressions (the operands).
225 ***** Compound Procedures
227 We have identified in Lisp some of the elements that must appear in any powerful programming
230 - Numbers and arithmetic operations are primitive data and procedures.
231 - Nesting of combinations provides a means of combining operations..
232 - Definitions that associate names with values provide a limited means of abstraction.
234 The general form of a *procedure definition* is
236 (define (<name> <formal parameters>)
240 ***** The Substitution Model for Procedure Application
242 To apply a compound procedure to arguments, evaluate the body of the procedure with each formal
243 parameter replaced by the corresponding argument.
245 Applicative order versus normal order
247 ***** Conditional Expressions and Predicates
249 =cond= , which stands for "conditional"
257 consisting of the symbol =cond= followed by parenthesized pais of expressions =(<p> <e>)=
258 called /clauses/. The first expression in each pair is a /predicate/-that is, and expression
259 whose value is interpreted as either true or false.
261 =else=, is a special symbol that can be used in place of =<p>= in the final clause of a =cond=
270 (if <predicate> <consequent> <alternative>)
298 (define (sum-two-larger a b c)
299 (cond ((and (> a b) (> c b)) (+ a c))
300 ((and (> c a) (> b a)) (+ c b))
301 ((and (> a c) (> b c)) (+ a b))))
303 (sum-two-larger 1 2 3)
304 (sum-two-larger 7 3 5)
307 (define (minimal-of-two a b)
312 (define (sum-two-larger-2 a b c)
313 (- (+ a b c) (minimal-of-two a (minimal-of-two b c))))
315 (sum-two-larger-2 1 2 3)
318 ***** Example: Square Roots by Newton's Method
320 ***** Procedures as Black-Box Abstractions
324 - Internal definitions and block structure
327 **** Procedures and the Processes They Generate
329 ***** 1.2.1 Linear Recursion and Iteration
330 sample, factorial function of n!
332 ***** 1.2.2 Tree Recursion
335 ***** 1.2.3 Orders of Grouth
337 ***** 1.2.4 Exponentiation
340 ***** 1.2.5. Greatest Common Divisior
342 ***** 1.2.6 Example: Testing for Primality
344 Fermat's Little Theorem:
346 **** Formulating Abstractions with Higher-Order Procedures
348 Procedures that manipulate procedures are called /higher-order procedures/.
350 ***** 1.3.1 Procedures as Arguments
352 (define (inc n) (+ n 1))
353 (define (cube a) (* a a a))
354 (define (sum-cubes a b)
360 ***** 1.3.2 Constructing Procedures Using lambda
362 (lambda (<formal-parameters>) <body>)
365 In general, =lambda= is used to create procedures in the same way as =define= except that no
366 name is specified for the procedure
368 Like any expression that has a procedure as its values. a =lambda= expression can be used as
369 the operator in a combination such as
371 ((lambda (x y z) (+ x y (square z)))
377 Useing =let= to create local variable
379 (let ((<var1> <exp1>)
386 ***** 1.3.3 Procedures as General Methods
388 ***** 1.3.4 Procedures as Returned Values
391 (define (average-damp f)
392 (lambda (x) (average x (f x))))
394 ((average-damp square) 10)
398 *** Building Abstractions with Data