Giter Site home page Giter Site logo

functional-programming's Introduction

functional-programming

functional programming based on various language.

Java

  • foldLeft, reduce
  • recursive data structure

scheme

S-Expression definition

  1. an atom, or
  2. an expression of the form (x โ€ข y) where x and y are s-expressions.

Lisp is homoiconic language.

If a language has homoiconicity, it means that the language text has the same structure as its abstract syntax tree (i.e. the AST and the syntax are isomorphic)

Cons

  1. Cons is the fundamental function in most dialects of Lisp programming language. cons construct memory objects which hold two values or poiners to values.
  2. Cons looks like
(cons 42 (cons 69 (cons 613 nil)))

Cons-cells

Non-atomic S-expressions

history

Lisp was originally implemented on the IBM 704 computer, in the late 1950s. The 704 hardware had special support for splitting a 36bits machine word into four parts. and "address part" and "decrement part" of 15bits each and "prefix part" and "tag part" of three bits each.

car (short for "Contents of the Address part of Register number"),
cdr ("Contents of the Decrement part of Register number"),
cpr ("Contents of the Prefix part of Register number"), and
ctr ("Contents of the Tag part of Register number"),

example

  1. sum(a, b) => a + sum(a+1, b)
(+ a (f (+ a 1) b)) 
  1. definition of data structure
  • list
(list 1 2 3)
'(1 2 3)
(quote (1 2 3))
  • macro
(define-syntax 
  (syntax-rules () ...))

Javascript

Javascript closure

var name = "global";

function varClosestPriciple(name) {
    return function(name) {
        console.log(name);
    };  
}
var p = varClosestPriciple();
p("hello"); 
=> hello
p()
=> undefined

var p1 = varClosestPriciple("world");
p("hello"); 
=> hello
p(); 
=> undefined

functional-programming's People

Contributors

qianyan avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.