• Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    Java
  • License
    MIT License
  • Created over 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Source code for course "How to create your own programming language"

OwnLang

Build Status

OwnLang - dynamic functional programming language inspired by Scala and Python. Available for PC, Android and Java ME devices.

Installing

Free Pro Desktop
Free Pro v1.5.0

Also available as AUR package:

yay -S ownlang

Key features

Higher-order functions

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
}

def division(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

Pattern matching with value pattern, tuple pattern, list pattern and optional condition.

def factorial(n) = match n {
  case 0: 1
  case n if n < 0: 0
  case _: n * factorial(n - 1)
}

def fizzbuzz(limit = 100) {
  for i = 1, i <= limit, i++ {
    println match [i % 3 == 0, i % 5 == 0] {
      case (true, false): "Fizz"
      case (false, true): "Buzz"
      case (true, true): "FizzBuzz"
      case _: i
    }
  }
}

// run
fizzbuzz()

Functional data operations

Operate data in functional style.

use ["std", "functional"]

nums = [1,2,3,4,5,6,7,8,9,10]
nums = filter(nums, def(x) = x % 2 == 0)
// Squares of even numbers
squares = map(nums, def(x) = x * x)
foreach(squares, ::echo)
// Sum of squares
sum = reduce(squares, 0, def(x, y) = x + y)
println "Sum: " + sum
// Same using stream
println "Sum: " + stream(range(1, 11))
  .filter(def(x) = x % 2 == 0)
  .map(def(x) = x * x)
  .reduce(0, def(x, y) = x + y)

Operator overloading

Why not?

use ["std", "types", "math"]

def `..`(a, b) = range(a, b)
def `**`(a, b) = int(pow(a, b))
for y : 1 .. 10 {
  println sprintf("2 ^ %d = %d", y, 2 ** y)
}

Network module

Easy async HTTP requests with http module.

use "std"
use "http"
use "functional"

// GET request
http("https://api.github.com/events", def(r) {
  use "json"
  events = jsondecode(r)
  println events[0]
})

// POST request
http("http://jsonplaceholder.typicode.com/users", "POST", {
  "name": "OwnLang",
  "versionCode": 10
}, ::echo)

// PATCH request
http("http://jsonplaceholder.typicode.com/users/2", "PATCH", {"name": "Patched Name"}, ::patch_callback)

def patch_callback(v) {
  println v
}

Language specification

English and Russian

Examples

Build

Build using Gradle ./gradlew dist

or take a look to latest release for binaries.

Run

To run script use command

java -jar OwnLang.jar -f input.own

or

java -jar OwnLang.jar < input.own

License

MIT - see MIT licence information

More Repositories

1

Lightweight-Stream-API

Stream API from Java 8 rewritten on iterators for Java 7 and below
Java
1,602
star
2

Android-Java-8-Stream-Example

Demo app of using Java 8 features with Retrolambda and Lightweight-Stream-API
Java
114
star
3

dex-editor

Edit the dalvik-bytecode on Android.
Java
106
star
4

PaperStyleWidgets

Android material-design widgets
Java
38
star
5

MinizipAndroid

Android archiver using minizip library.
C
14
star
6

tgbots-module

Enhanced Java telegram bots runner built on top of the Telegram Bots library
Java
14
star
7

HotaruFX

Programming language for creating animations
Java
12
star
8

ffmpegbot

Telegram ffmpeg bot for re-encoding media
Java
7
star
9

SimpleVM

Simple virtual machine
Java
7
star
10

Flood-It-Bot

Universal bot for flood-it games
Java
6
star
11

JECP

Java Engine Cross-Platform
Java
5
star
12

Piwigo-Color-Palette

Color palette plugin for Piwigo
PHP
5
star
13

SyncTube-QSwitcher

Quality switcher plugin for SyncTube
JavaScript
4
star
14

TwitchSpeedVideoCreator

Twitch.tv past broadcasts downloader with ability to speed up videos
Java
3
star
15

favis-bot

Tag your favorite stickers and send them in inline mode
Kotlin
2
star
16

DonNUEdgeDetector

Detect edges from camera with OpenCV library
C++
2
star
17

Turrets

Network game
Java
2
star
18

JMethodRearranger

Java methods organizer
Java
2
star
19

JTicTacToe

Java TicTacToe game.
Java
2
star
20

aScheduler

Программа редактирования расписания
Java
2
star
21

University-Java

Лабораторные работы по курсу "Технологии Программной Инженерии" Донецкого Национального Университета
Java
1
star
22

Rouge-et-Noir

Пасьянс Rouge-et-Noir
C#
1
star
23

aNNiMON

1
star