Giter VIP home page Giter VIP logo

lizp's Introduction

Lizp -- A Toy Functional Language


Lizp is a functional language which based on lambda calculus.

Features

  • Currying
  • High level functions
  • Call by value
  • Dynamic typed

Grammar

<expr> ::= <var> | <list> | \<sym>.<expr> | (<expr> <expr>) | <let-expr>
<let-expr>  ::= let <var> = <expr> in <expr>
<var>  ::= <num> | <str> | <sym>
<list> ::= /[<expr>(,<expr>)*]/
<num>  ::= /-?[0-9]+/
<str>  ::= /"[^\"\0]*"/
<sym>  ::= /[^0-9][a-zA-Z0-9_-'~!@#$%^&*]+/

Code Sample

  • Lambda Definition
  (\x.x)
  • Lambda Application
  ((\x.x) y) 
    -> y
  • Currying
  (\x.\y.(+ x y) z)
    -> \y.(+ z y) 
  • Function Definition
  let add1 = \x.(+ x 1) in (add1 2)
    -> 3
  • Function Application
  (add1 2) 
    -> (\x.(+ x 1) 2)
      -> 2+1 
        -> 3
  • High level function definition

    • To apply a lambda
    let apply = \f.\x.(f x) in ...
  • To reduce a lambda
    let addn = \x.\y.(+ x y) in ...
  • High level function application

    • Apply a lambda
    apply add1 2 
      -> ((\f.\x.(f x) add1) 2) 
        -> (\x.(add1 x) 2)
          -> (\x.\y.((+ y 1) x) 2)
            -> (\y.(+ y 1) 2) 
              -> (+ 2 1) 
                -> 3
  • Reduce a lambda
    addn 2 
      -> (\y.\x.(+ x y) 2) 
        -> \x.(+ x 2)
  • Variable Definition
  let var = 1 in ...

Future Features

  • Recursion Trick
  let fact = \n.(if (== n 0)
                    1
                    (self n))
  in ...

Actually, We can define everything as lambda(s).

  • Builtins:
Element(s) Symantic
number nature numbers
string native strings
[+,-,*,/] algebra operators
[&,|,~] bitwise operators
[&&,||,!] logic operators
[>,<,==,/=] compare operators
if symantic for branch
self symantic for recursion
cons symantic for list constuctor

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.