61a_scip_python_01

Fundamental ideas:

  1. represent information
  2. specify logic to process it
  3. design abstractions that manage the complexity of that logic

 

Three mechanisms of powerful language:

  1. primitive expression and statements: represent the simplest building blocks that the language provides
  2. means of combination: compound elements are built from simpler ones
  3. means of abstraction: compound elements can benamed and manipulated as units

 

Statements and Expressions:

  1. statements typically describe actions
  2. expressions typically describe computations

 

Expressions:

'''

value: the amount represented by  a letter or synbol  数值  数

computation: an act or the process of calculating sth 计算  计算过程

evaluation: to form an opinion of the amount, value or quality of sth

operator: a symbol or function which represents an operation in mathematics 算子

operand: the number on which an operation is to be done 运算数

'''

  • an expression describe a computation and evaluate to value
  • all expression can use function call notation
  • primitive expressions:
    • number: the expression you type consists of the numerals that represent the number in base 10
    • names 
    • string

 

Call expressions:

  • structure:    operator(operand,operand...)  max(1,2)
  • operator and operand are also expressions. name or numbers or subexpressions?
  • evaluation procedure for call expressions:
    • evaluate the operator to get function and then operand subexpression to get arguments
    • apply the fuction that is the value of the the operator subexpression to the arguments that are the values of the operand subexpressions
  • evaluate nested expressions: use expression tree
    mul(add(4,mul(4,6)),add(3,5))

 

Names:

  • use names to refer to computational objects
  • if a value has been given a name, we say that name binds to the value
  • how to bind:
    • assigment statement: (name = expression) evaluate expression and bind it to the name
    • import statement: just built-in names
    • def statement: def a fuction
  • names are often called variable names or variables because they can be bound to different values but just bind one
  • change the value of one name does not affect other name because after evaluation just value to be bound to the name
    x=2
    y=x+1
    x=3
    print(y)

     but the function

    def f(a):
        return a+1
    
    x=2
    y= f(x)
    print(y)
    x=3
    print(y)

     

   because return statement, it get re-revaluated everytime it's called

  • environment:
    • environments are real things, they're the way in which an interpreter for programming language keeps track of what names mean, so it's sort of menory that keeps track of the bindings between names and values

 

    

posted @ 2017-02-13 19:41  lixinnjupt  阅读(333)  评论(0编辑  收藏  举报