Skip to content

Instantly share code, notes, and snippets.

@SSARCandy
Last active August 29, 2015 14:23
Show Gist options
  • Save SSARCandy/7eef3b0b7ae2d5b7060c to your computer and use it in GitHub Desktop.
Save SSARCandy/7eef3b0b7ae2d5b7060c to your computer and use it in GitHub Desktop.
key point of PL

程式語言三面向:

  • Syntax
  • Semantics
  • Implementation

FP and Haskell:

  • Basics (tail-recursion, higher-order functions)

  • Closure

    • No free-variable
  • Argument Evaluation Strategies

    • Call-by-value
      • Always evaluate the argument before applying the function/operation
      • May result in errors/non-termination when it is not necessary
    • Call-by-name
      • Arguments are not evaluated: only when needed (referenced) during function application
      • Variable capturing problem
    • Call-by-name(thunk)
      • Thunk: Wrap the argument with a dummy lambda
      • May lead to repetitive evaluation
    • Call-by-text
      • A variation of Call-By-Name
      • Use the referencing environment, not the defining environment
    • Call-by-need(Lazy evaluation)
      • A variation of Call-By-Name
      • supported using cache
      • no repetitive evaluation
  • Environment, static vs. dynamic scoping

    a = 100 in
    h = \x->x+a in
    twice = \f->\x->f (f x) in
    let a = 10
        in twice h a
    • for dynamic scoping: (x+a)+a = 10+10+10 = 30
    • for static scoping: (x+a)+a = 100+10+10 = 210
  • Assignment 2-3; 看得懂稍複雜的Haskell程式

Semantic copcepts的理解與運用

  • Variables in imperative languages: names, locations, values and scopes

  • Memory model:

    -----------------
    |     Code      |
    -----------------
    |  Static data  |
    -----------------
    |     Stack     |
    -----------------
    |               |
    |               |
    -----------------
    |     Heap      |
    -----------------
    
    • stack and heap
    • Garbage and dangling pointers
      • dangling pointers:
        Pointers that point to deallocated memory locations
      • Garbage:
        Memory (heap) cell that is allocated but cannot be accessed. (No pointers reference it)
  • Data types and type systems (strong vs. weak)

  • Type coercion vs. type cast

  • Type checking: static vs. dynamic check

OOP:

  • Message passing and method lookup
  • Dynamic binding of methods
  • Inheritance and polymorphism
    不管many裡面是colorpoint還是point都可以move()
    many = new vector();
    many[0] = new Point(3, 4);
    many[1] = new ColorPoint(2, 2, BLUE);
    many[2] = new Point(1, 5);
    move_all(many, 2, 4);
    
    move_all(vector v,  dx, dy)�{ // move all members of vector v by dx and dy�
        // don’t care the exact kind of points�
         for (i=0; i<v.length; i++)� v[i].move(dx, dy); 
     }
  • Overloading vs. Overriding
    • Overriding
      • Early vs. Late Binding
        By default, the C++ compiler implements early (static) binding;
        For virtual functions, the compiler implements dynamic binding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment