Skip to main content

Home/ ProgrammingPages/ Group items tagged closures

Rss Feed Group items tagged

Navneet Kumar

Javascript Closures - 0 views

  • If a value is assigned and the actual object does not have a property with the corresponding name a property of that name is created and the value is assigned to it. If it has the property then its value is re-set.
  • all objects may have prototypes, and prototypes are objects so they, in turn, may have prototypes, which may have prototypes, and so on forming what is called the prototype chain. The prototype chain ends when one of the objects in the chain has a null prototype. The default prototype for the Object constructor has a null prototype so
  • When a javascript function is called it enters an execution context, if another function is called (or the same function recursively) a new execution context is created and execution enters that context for the duration of the function call. Returning to the original execution context when that called function returns. Thus running javascript code forms a stack of execution contexts
  • ...5 more annotations...
  • First, in the execution context of a function, an "Activation" object is created.
  • The next step in the creation of the execution context for a function call is the creation of an arguments object, which is an array-like object with integer indexed members corresponding with the arguments passed to the function call, in order.
  • Next the execution context is assigned a scope. A scope consists of a list (or chain) of objects.
  • the Activation object is used as the Variable object (note this, it is important: they are the same object). Named properties of the Variable object are created for each of the function's formal parameters, and if arguments to the function call correspond with those parameters the values of those arguments are assigned to the properties (otherwise the assigned value is undefined)
  • It is the fact that the Activation object, with its arguments property, and the Variable object, with named properties corresponding with function local variables, are the same object, that allows the identifier arguments to be treated as if it was a function local variable.
  •  
    Detailed description of How javascript lanaguage handles resolution of property names, scopes of the functions, the importance prototype, and how closures are ultimately formed taking into consideration the above facts
Navneet Kumar

JavaScript Closures for Dummies | Developing thoughts - Morris Johns - 0 views

    • Navneet Kumar
       
      good one. shown with exaples
Navneet Kumar

defmacro - Functional Programming For The Rest of Us - 0 views

  • In a lazy language you have no guarantee that the first line will be executed before the second! This means we can't do IO, can't use native functions in any meaningful way (because they need to be called in order since they depend on side effects), and can't interact with the outside world! If we were to introduce primitives that allow ordered code execution we'd lose the benefits of reasoning about our code mathematically
  • continuations, monads, and uniqueness typing.
  • Alonzo Church developed a formal system called lambda calculus. The system was essentially a programming language for one of these imaginary machines
  • ...18 more annotations...
  • Functions that operate on other functions (accept them as arguments) are called higher order functions.
  • currying is used to reduce the number of arguments
  • only executes code when it's required
  • A lazy compiler thinks of functional code exactly as mathematicians think of an algebra expression - it can cancel things out and completely prevent execution, rearrange pieces of code for higher efficiency, even arrange code in a way that reduces errors, all guaranteeing optimizations won't break the code.
  • John McCarthy (also a Princeton graduate) developed interest in Alonzo Church's work. In 1958 he unveiled a List Processing language (Lisp)
  • Lisp machine - effectively a native hardware implementation of Alonzo's lambda calculus!
  • it was proved that lambda calculus is equivalent to a Turing machine.
  • It turns out that functional programs can keep state, except they don't use variables to do it. They use functions instead. The state is kept in function parameters, on the stack. If you want to keep state for a while and every now and then modify it, you write a recursive function
  • Erlang engineers have been upgrading live systems without stopping them for years.
  • Erlang systems are not scalable and reliable. Java systems are. Erlang systems are simply rock solid
  • Ericsson designed a functional language called Erlang for use in its highly tolerant and scalable telecommunication switches.
  • Continuation Passing Style or CPS
  • A "continuation" is a parameter we may choose to pass to our function that specifies where the function should return.
  • continuations are a generalization of functions.
  • CPS version needs no stack! No function ever "returns" in the traditional sense, it just calls another function with the result instead. We don't need to push function arguments on the stack with every call and then pop them back, we can simply store them in some block of memory and use a jump instruction instead. We'll never need the original arguments - they'll never be used again since no function ever returns!
  • What does the stack contain? Simply the arguments, and a pointer to memory where the function should return. Do you see a light bulb? The stack simply contains continuation information! The pointer to the return instruction in the stack is essentially the same thing as the function to call in CPS programs!
  • A continuation and a pointer to the return instruction in the stack are really the same thing, only a continuation is passed explicitly, so that it doesn't need to be the same place where the function was called from
  • When we get a current continuation and store it somewhere, we end up storing the current state of our program - freezing it in time. This is similar to an OS putting itself into hibernation. A continuation object contains the information necessary to restart the program from the point where the continuation object was acquired.
  •  
    deals from the history of functional languages
    what are functional languages, benefits

1 - 6 of 6
Showing 20 items per page