This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fava: Functional Programming Language
- Loading branch information
0 parents
commit 6ce1026
Showing
34 changed files
with
11,975 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.* | ||
/build | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2014, Journal of Hamradio Informatics | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
fava: Functional Programming Language on Scala | ||
==== | ||
|
||
 | ||
 | ||
 | ||
 | ||
|
||
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| | ||
|`wire` |WireWorld| | ||
|
||
## Documents | ||
|
||
- [Scalaで自作するプログラミング言語処理系 (PDF)](https://nextzlog.dev/fava.pdf) [(HTML)](https://nextzlog.dev/fava.html) | ||
|
||
## Usage | ||
|
||
```sh | ||
$ gradle build | ||
$ java -jar build/libs/fava.jar --fava | ||
fava$ "HELLO, WORLD!" | ||
HELLO, WORLD! | ||
fava$ compile(1 + 2) | ||
Push(1) Push(2) IAdd | ||
fava$ exit | ||
$ java -jar build/libs/fava.jar --lisp | ||
lisp$ (+ 1 2 3) | ||
6 | ||
lisp$ (exit) | ||
``` | ||
|
||
## Fava Examples | ||
|
||
### basic operation | ||
|
||
- fava supports some arithmetic, logic, and relational operations. | ||
|
||
```Scala | ||
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. | ||
|
||
```Scala | ||
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. | ||
|
||
```Scala | ||
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. | ||
|
||
```Scala | ||
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. | ||
|
||
```Scala | ||
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. | ||
|
||
```lisp | ||
lisp$ (set ’function-in-variable list) | ||
list | ||
lisp$ (function-in-variable 1 2 3 4 5) | ||
(1 2 3 4 5) | ||
``` | ||
|
||
### lambda definition | ||
|
||
- Use the `define-lambda` macro to define a function. | ||
|
||
```lisp | ||
lisp$ (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. | ||
|
||
```lisp | ||
lisp$ define-lambda | ||
(syntax (name pars body) (list (quote setq) name (list (quote lambda) pars body))) | ||
lisp$ define-syntax | ||
(syntax (name pars body) (list (quote setq) name (list (quote syntax) pars body))) | ||
``` | ||
|
||
## WireWorld | ||
|
||
### 3 + 6 | ||
|
||
 | ||
|
||
### 3 + 7 | ||
|
||
 | ||
|
||
## Contribution | ||
|
||
Pull requests are not accepted. | ||
If you need enhancements, feel free to make issues at [nextzlog/todo](https://github.com/nextzlog/todo). | ||
|
||
## License | ||
|
||
### Author | ||
|
||
[無線部開発班](https://nextzlog.dev) | ||
|
||
### Clauses | ||
|
||
[BSD 3-Clause License](LICENSE.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
plugins { | ||
id 'scala' | ||
id 'application' | ||
id 'org.openjfx.javafxplugin' version '0.0.13' | ||
} | ||
|
||
application { | ||
mainClassName = 'Main' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.scala-lang:scala3-library_3:3.0.+' | ||
implementation 'org.scala-lang.modules:scala-jline:+' | ||
} | ||
|
||
javafx { | ||
version = '18' | ||
modules = ['javafx.controls'] | ||
} | ||
|
||
compileScala { | ||
options.encoding = 'UTF-8' | ||
} | ||
|
||
jar { | ||
duplicatesStrategy = 'exclude' | ||
manifest.attributes 'Main-Class': mainClassName | ||
} | ||
|
||
jar.from configurations.compileClasspath.collect { | ||
it.isDirectory()? it: zipTree(it) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.