- Notifications
You must be signed in to change notification settings - Fork23
Source code for course "How to create your own programming language"
License
aNNiMON/Own-Programming-Language-Tutorial
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
OwnLang - dynamic functional programming language inspired by Scala and Python. Available for PC, Android and Java ME devices.
Free | Pro | Desktop |
---|---|---|
v2.1.0 |
Also available as AUR package:
yay -S ownlang
Functions are values, so we can store them to variables for operating.
operations= {"+":def(a,b)= a+b,"-":def(a,b)= a-b,"*":def(a,b)= a*b,"/":::division}defdivision(v1, v2) {if (v2==0)return"error: division by zero"return v1/ v2}for name,operation : operations { println"2"+ name+" 3 ="+ operation(2,3)}
Pattern matching with value pattern, tuple pattern, list pattern and optional condition.
deffactorial(n)=match n {case0:1case nif n<0:0case_: n* factorial(n-1)}deffizzbuzz(limit=100) {for i=1, i<= limit, i++ { printlnmatch [i%3==0, i%5==0] {case (true,false):"Fizz"case (false,true):"Buzz"case (true,true):"FizzBuzz"case_: i } }}// runfizzbuzz()
Operate data in functional style.
use std, functionalnums= [1,2,3,4,5,6,7,8,9,10]nums= filter(nums,def(x)= x%2==0)// Squares of even numberssquares= map(nums,def(x)= x* x)foreach(squares,::echo)// Sum of squaressum= reduce(squares,0,def(x, y)= x+ y)println"Sum:"+ sum// Same using streamprintln"Sum:"+ stream(range(1,11)) .filter(def(x)= x%2==0) .map(def(x)= x* x) .reduce(0,def(x, y)= x+ y)
Why not?
use std, types, mathdef`..`(a, b)= range(a, b)def`**`(a, b)= int(pow(a, b))fory :1 ..10 { println sprintf("2 ^ %d = %d", y,2** y)}
Easy async HTTP requests withhttp
module.
use std, http, functional, json// GET requesthttp("https://api.github.com/events",def(r) { events= jsondecode(r) println events[0]})// POST requesthttp("http://jsonplaceholder.typicode.com/users","POST", {"name":"OwnLang","versionCode":10},::echo)// PATCH requesthttp("http://jsonplaceholder.typicode.com/users/2","PATCH", {"name":"Patched Name"},::patch_callback)defpatch_callback(v) { println v}
Build using Gradle./gradlew shadowJar
or take a look tolatest release for binaries.
To run script use command
java -jar OwnLang.jar -f input.own
or
java -jar OwnLang.jar < input.own
MIT - seeMIT license information
About
Source code for course "How to create your own programming language"
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.