What is a Program#
A program is a black box that takes input and produces the desired output.
The technology for controlling complexity in large systems is key to computer technology; the complexity of computer science is not "real," unaffected by factors like physics. Computer science deals with idealized components, where there is not much difference between the ideal and the real, allowing for free combination and construction. Computer engineering is like building blocks without constraints. Abstraction is an important concept in computer science. The black box of a program can consist of countless black boxes (hiding details, black box abstraction).
What is a Programming Language#
A programming language is the spell that implements the black box; it consists of instructions.
Complex instructions are built from basic instructions, and complex data is constructed from basic data, encapsulated using black boxes. This is the process of programming.
Controlling Complexity#
The way to control complexity is to leave agreed-upon interfaces in the program and find ways to combine them. Object-oriented thinking and aggregation thinking ("flow") are the two main approaches.
What is Lisp#
Understanding a language mainly involves three points:
What are the basic elements that make up the language?
How are these elements combined?
What are the methods of abstraction?
Methods of Combination#
3 + y 12.1
Symbols like this are abstract data in Lisp.
(+ 3 12 1.1)
This is a combination expression composed of operators and operands (prefix notation).
In fact, a combination expression is also a "tree."
+
/ | \
3 12 1.1
More branches follow the same principle.
+
/ | \
3 12 1.1
|
+
| \
1 0.1
We can understand it as: a program is constructing these trees.
Methods of Abstraction#
(define (add a b) (+ a b))
This defines a function named add, which takes two values and returns their sum.
Of course, a process can also be constructed using lambda.
(define square
(lambda (x) (* x x)))
All of this is part of the construction process.
(define (average x y)
(/ (+ x y) 2))
(define (mean-square (x y)
(average (square x)
(square y))))
A simple mean square evaluator
Constructing based on conditions
(define (abs x)
(cond ((< x 0) (- x)
(= x 0) (0)
(> x 0) (x))))
;; OR
(define (abs x)
(if (< x 0)
(- x)
x))