From ee57957140b979f90876a2b614d138bea42c7440 Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 30 Jun 2016 14:26:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D1=91?= =?UTF-8?q?=D0=BD=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 116 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ae6b215..29dde9a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,121 @@ # OwnLang -OwnLang - dynamic functional programming language. Available for PC, Android and Java ME devices. +OwnLang - dynamic functional programming language inspired by Scala and Python. Available for PC, Android and Java ME devices. + +## Key features + +#### Function values + +Functions are values, so we can store them to variables for operating. + +```scala +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" + return v1 / v2 +} + +for operation : operations { + println operation(2, 3) +} +``` + +#### Pattern Matching + +Pattern matching with value pattern, tuple pattern, list pattern and optional condition. + +```scala +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 + } + } +} +``` + +#### Functional data operations + +Operate data in functional style. + +```scala +use "std" +use "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 +``` + +#### Operator overloading + +Why not? + +```scala +use "std" +use "types" +use "math" + +def `..`(a, b) = range(a, b - 1) +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. + +```scala +use "std" +use "http" +use "functional" + +// GET request +http("https://api.github.com/events", def(r) { + use "json" + events = jsondecode(r) +}) + +// 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 + +[Available on GitBook (English and Russian)](https://www.gitbook.com/book/annimon/ownlang/details) + +[Examples](examples/) ## Build @@ -23,13 +138,6 @@ or `java -jar OwnLang.jar < input.own` -## Language specification - -[Wiki (Russian)](https://github.com/aNNiMON/Own-Programming-Language-Tutorial/wiki) - -[Examples](examples/) - - ## License MIT - see [MIT licence information](LICENSE) \ No newline at end of file