Git Product home page Git Product logo

fava's Introduction

fava: Functional Programming Language on Scala

image image image image

fava is a Turing complete, pure functional programming language, which was designed for the educational purpose in computational theory.

Features

Package Feature
univ universal Turing machine using two tapes
regl parser combinators for regular languages
gram parser combinators for parsing expression grammars (PEGs)
math arithmetic calculator with a simple stack machine and PEG
fava fava REPL
lisp LISP REPL

Documents

Usage

$ gradle build
$ java -jar build/libs/fava.jar
which language do you use?
[0]: fava
[1]: math
[2]: univ
[3]: regl
[4]: lisp
select: 0
fava$

Fava Examples

basic operation

  • fava supports some arithmetic, logic, and relational operations.
fava$ 114 + 514
628
fava$ 3 > 1? "LOOSE": "WIN"
LOOSE

lambda calculus

  • fava does not accept local variable and function declarations, and block statements are also prohibited.
fava$ ((x)=>(y)=>3*x+7*y)(2)(3)
27

Church booleans

  • fava is Turing complete and can theoretically define boolean operations without using system functions.
fava$ ((l,r)=>l(r,(x,y)=>y))((x,y)=>x,(x,y)=>y)(true,false) // true & false
false
fava$ ((l,r)=>l((x,y)=>x,r))((x,y)=>x,(x,y)=>y)(true,false) // true | false
true

Church numerics

  • fava is Turing complete and can theoretically define numeric operations without using system functions.
fava$ ((l,r)=>(f,x)=>l(f)(r(f)(x)))((f)=>(x)=>f(x),(f)=>(x)=>f(f(x)))((x)=>x+1,0) // 1 + 2
3
fava$ ((l,r)=>(f,x)=>l(r(f))(x))((f)=>(x)=>f(f(x)),(f)=>(x)=>f(f(x)))((x)=>x+1,0) // 2 * 2
4

anonymous recursion

  • fava evaluates function arguments lazily.
fava$ ((f)=>((x)=>f(x(x)))((x)=>f(x(x))))((f)=>(n)=>(n==0)?1:n*f(n-1))(10)
3628800

Lisp Examples

name space

  • Functions and variables are declared in the same namespace.
elva$ (set ’function-in-variable list)
#<native form list>
elva$ (function-in-variable 1 2 3 4 5)
(1 2 3 4 5)

lambda definition

  • Use the define-lambda macro to define a function.
elva$ (define-lambda fact (x) (if (eq x 1) x (* x (fact (- x 1)))))
(lambda (x) (if (eq x 1) x (* x (fact (- x 1)))))

syntax definition

  • Use the define-syntax macro to define a macro or syntax.
elva$ define-lambda
(syntax (name pars body) (list (quote setq) name (list (quote lambda) pars body)))
elva$ define-syntax
(syntax (name pars body) (list (quote setq) name (list (quote syntax) pars body)))

Contribution

Feel free to contact @nextzlog on Twitter.

License

Author

無線部開発班 (JOURNAL OF HAMRADIO INFORMATICS LETTERS)

Clauses

BSD 3-Clause License

fava's People

Contributors

jg1vpp 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.