RustScript is a functional scripting language with as much relation to Rust as Javascript has to Java.

Overview

RustScript

RustScript is a scripting language as much relation to Rust as JavaScript has to Java


I made this for a school project; it's meant to be implemented into a messaging app as a chat bot so everything should be a one liner.

Usage

This is an expression based language; everything is an expression. There are global variables though.

The following examples are created using the repl.

Basic Arithmetic

> 4 * -3 + 12 - -3 + 4 * 15
63

Variables

> let x = 5
> x * 15
75

Lists

> let ls = [1, 2, 9, 4, 5]
> ls
[1, 2, 9, 4, 5]

> let ls = ls + [2, 4, 6, 8]
> ls
[1, 2, 9, 4, 5, 2, 4, 6, 8]

> ^ls
1

> $ls
[2, 9, 4, 5, 2, 4, 6, 8]

Ranges

> [5..12]
[5, 6, 7, 8, 9, 10, 11]

List Comprehensions

> [x * x for x in [0..15]]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196]

Lambdas

> let f = fn (x) => x * 2
> f(30)
60

> let apply_twice = fn (f, x) => f(f(x))
> apply_twice(f, 5)
20

Conditionals

> if (3 < 5) then (4) else (3)
4

> [if (x % 3 == 0) then (x / 3) else (x * 2) for x in [0..10]]
[0, 2, 4, 1, 8, 10, 2, 14, 16, 3]

> let fib = fn (n) => if (n < 2) then (1) else (fib(n - 1) + fib(n - 2))
> fib(15)
987

Small Standard Library

> range(3, 5)
[3, 4]

> fmap(fib, [5..10] + [3, 2])
[8, 13, 21, 34, 55, 3, 2]

> filter(fn (n) => n % 3 == 0, [0..20])
[0, 3, 6, 9, 12, 15, 18]

> fold(fn (a, b) => a + b, 0, [0..20])
190

> sum([0..20])
190

> product([1..10])
362880

Project Euler

A few project euler problems

Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.

> sum([x for x in [0..1000] if x % 3 == 0 || x % 5 == 0])
233168

Problem 2

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

> let fib = fn (n) => ^$fold(fn (ls, i) => [^$ls, ^ls + ^$ls], [1, 1], [0..n])
> let fibs = [fib(n) for n in [1..35]]
> sum([f for f in fibs if f < 4000000 && f % 2 == 0])
4613732

Problem 3

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?

let find = fn (f, ls) => if (ls) then (if (f(^ls)) then (^ls) else (find(f, $ls))) else (false)
let factor = fn (n) => find(fn (i) => n % i == 0, [2..n / 2])

600851475143 is larger than int allows so I'd have to make it support longs to do this one.

It's worth noting that factor doubles as is_prime, since it returns false for prime numbers.

Problem 5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

> let gcd = fn (a, b) => if (b == 0)  then (a) else (gcd(b, (a % b)))
> let lcm = fn (a, b) => (a * b) / (gcd(a, b))
> fold(lcm, 1, [1..20])
232792560

Problem 6

The sum of the squares of the first ten natural numbers is, 1^2 + 2^2 + ... + 10^2 = 385$$

The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)^2 = 55^2 = 3025$$

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is $3025 - 385 = 2640$.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

let square = fn (x) => x * x
square(sum([1..100])) - (sum(fmap(square, [1..100])))
``

Once again the numbers are too big
You might also like...

Transform ML models into a native code (Java, C, Python, Go, JavaScript, Visual Basic, C#, R, PowerShell, PHP, Dart, Haskell, Ruby, F#, Rust) with zero dependencies

m2cgen m2cgen (Model 2 Code Generator) - is a lightweight library which provides an easy way to transpile trained statistical models into a native cod

Jan 4, 2023

esProc SPL is a scripting language for data processing, with well-designed rich library functions and powerful syntax, which can be executed in a Java program through JDBC interface and computing independently.

esProc SPL is a scripting language for data processing, with well-designed rich library functions and powerful syntax, which can be executed in a Java program through JDBC interface and computing independently.

esProc esProc is the unique name for esProc SPL package. esProc SPL is an open-source programming language for data processing, which can perform comp

Dec 27, 2022

Scripting language written in, and, designed to communicate with, java

Scripting language written in, and, designed to communicate with, java

mi-lang Scripting language designed to communicate with java, to allow for easy plugins, addons, etc in any project, all without having to create an e

Dec 17, 2022

Sqript is a scripting language.

Sqript is a scripting language.

Sqript Sqript allows to edit the behavior and the content of the game with scripts. In a few lines, you can change the gameplay, add items or blocks,

Feb 23, 2022

Simple Design for Java bridge with Javascript. Also can get javascript console.log.

Simple Design for Java bridge with Javascript. Also can get javascript console.log.

SDBridgeKotlin is here. If your h5 partner confused about how to deal with iOS and Android. This Demo maybe help. 最常见的问题. WebViewJavascriptBridge is n

Dec 18, 2022

lazy-language-loader improves loading times when changing your language by only reloading the language instead of all the game resources!

lazy-language-loader lazy-language-loader improves loading times when changing your language by only reloading the language instead of all the game re

Sep 7, 2022

⚡️Lightning-fast linter for .env files. Written in Rust 🦀

⚡️ Lightning-fast linter for .env files. Written in Rust 🦀 Dotenv-linter can check / fix / compare .env files for problems that may cause the applica

Jan 1, 2023

A Zombie invasion has occurred at the Code Academy Campus and now Alcatrinha has to fight the zombies to death! (2D TopView Shooter)

A Zombie invasion has occurred at the Code Academy Campus and now Alcatrinha has to fight the zombies to death! (2D TopView Shooter)

Hello everyone, welcome to Zombie ACADalypse!! A Zombie invasion has occurred at the Code Academy Campus and now Alcatrinha has to fight the zombies t

Dec 17, 2021

LaetLang is an interpreted C style language. It has file reading/writting, TCP network calls and awaitable promises.

LaetLang 💻 LaetLang is an interpreted C style language built by following along Robert Nystrom's book Crafting Interpreters. This is a toy language t

Mar 14, 2022

A MATLAB-like scientific scripting environment for Kotlin, a simpler Kotlin only version of KotlinLab

KotlinLab: Easy and effective MATLAB-like scientific programming with Kotlin and Java JShell Installation The installation of KotlinLab is very simple

Sep 28, 2022

VisualScripting - Visual scripting using nodes, see README for more details

VisualScripting - Visual scripting using nodes, see README for more details

VisualScripting Make code using nodes This program does the heavy lifting of making nodes work, to make use of this program plugins are required, plug

Sep 4, 2022

Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ). This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners.

Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ).  This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners.

Java-Programs---For-Practice is one of the Java Programming Practice Series By Shaikh Minhaj ( minhaj-313 ). This Series will help you to level up your Programming Skills. This Java Programs are very much helpful for Beginners. If You Have any doubt or query you can ask me here or you can also ask me on My LinkedIn Profile

Nov 8, 2022

Kotlin-decompiled - (Almost) every single language construct of the Kotlin programming language compiled to JVM bytecode and then decompiled to Java again for better readability

Kotlin: Decompiled (Almost) every single language construct of the Kotlin programming language compiled to JVM bytecode and then decompiled to Java ag

Dec 14, 2022

this repo is probs gonna die cuz idk very much java but i will update it when i learn how to actually DO SHIT

pastegod.cc shitty rename of zihasz client base rn but as i learn java i will paste-i mean add modules ;) (23/9/2021) why is everyone starring and wat

Dec 9, 2022

I had too much coffee and decided to mirror my actions by writing too many programs in Java.

Raging Coffee Table of Contents Description Running the Programs Extra Dependencies Roadmap Further Reading Known Issues Resources Contributions Descr

Dec 15, 2022

This application can recognize the sign language alphabets and help people who do not understand sign language to communicate with the speech and hearing impaired.

This application can recognize the sign language alphabets and help people who do not understand sign language to communicate with the speech and hearing impaired.

Sign Language Recognition App This application can recognize the sign language alphabets and help people who do not understand sign language to commun

Oct 7, 2021

Jamal is a macro language (JAmal MAcro Language)

Jamal is a macro language (JAmal MAcro Language)

Jamal Macro Language Jamal is a complex text processor with a wide variety of possible use. The first version of Jamal was developed 20 years ago in P

Dec 20, 2022

For Jack language. Most of codes were commented with their usage, which can be useful for beginner to realize the running principle of a compiler for object-oriented programming language.

Instructions: Download the Java source codes Store these codes into a local folder and open this folder Click the right key of mouse and click ‘Open i

Jan 5, 2023
Comments
  • Boolean logic, Strings and Character types

    Boolean logic, Strings and Character types

    Changes

    • Adds support for Boolean comparisons using the already existing isTruthy() method, operands are evaluated if one of them is true or false. therefore, [] == [1] cannot be run, but [] == false can and returns true, indicating that [] truth-value is false.
    • Adds support for Boolean negation using the existing - symbol, this can be linked to mathematics where negation is indicated by ¬ which is a very similar symbol. This is a simple solution but it can be considered to implement a dedicated operator like ! For this as in other languages.

    Discussion

    Suppose you have a list list like in the example below:

    let list = [9, 8, 7, 6]
    

    And you want to extract the first element safely by first checking of the list has elements because the ^ operator throws an exception in case the operand is an empty list Index 0 out of bounds for length 0. This is at the moment not possible what I know as the language is lacking a match or case keyword for pattern matching? Therefore one would want to do this using if and with this PR, users are able to compare the truthiness of the list with a Boolean as follows:

    let first = fn (l) => if (l == true) then (^l) else (null)
    

    Now you can select the first element without the need to worry about getting an exception.

    > first(list)
    9
    > first([])
    null
    

    The second part of this PR is mostly about to the negation of Boolean expressions. For this I suggest the use of the - prefix operator, as it is similar to the ¬ symbol in mathematics. It might wanted to consider using a dedicated operator for this, but to do it this way minimizes the size of the language and increases expressiveness with fewer operators.

    opened by WilliamRagstad 9
Owner
Mikail Khan
¯\_(ツ)_/¯
Mikail Khan
vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.

Vavr is an object-functional language extension to Java 8, which aims to reduce the lines of code and increase code quality. It provides persistent co

vavr 5.1k Jan 3, 2023
Functional patterns for Java

λ Functional patterns for Java Table of Contents Background Installation Examples Semigroups Monoids Functors Bifunctors Profunctors Applicatives Mona

null 825 Dec 29, 2022
A library that simplifies error handling for Functional Programming in Java

Faux Pas: Error handling in Functional Programming Faux pas noun, /fəʊ pɑː/: blunder; misstep, false step Faux Pas is a library that simplifies error

Zalando SE 114 Dec 5, 2022
Functional programming course

Functional-Programming-101-Java functional programming course with Mohamed Hammad https://www.youtube.com/playlist?list=PLpbZuj8hP-I6F-Zj1Ay8nQ1rMnmF

Ibrahim 14 Nov 9, 2022
Backport of Java 8's lambda expressions to Java 7, 6 and 5

Retrolambda: Use Lambdas on Java 7 Just as there was Retroweaver et al. for running Java 5 code with generics on Java 1.4, Retrolambda lets you run Ja

Esko Luontola 3.5k Dec 30, 2022
Java 8 annotation processor and framework for deriving algebraic data types constructors, pattern-matching, folds, optics and typeclasses.

Derive4J: Java 8 annotation processor for deriving algebraic data types constructors, pattern matching and more! tl;dr Show me how to write, say, the

null 543 Nov 23, 2022
Stream utilities for Java 8

protonpack A small collection of Stream utilities for Java 8. Protonpack provides the following: takeWhile and takeUntil skipWhile and skipUntil zip a

Dominic Fox 464 Nov 8, 2022
Enhancing Java Stream API

StreamEx 0.7.3 Enhancing Java Stream API. This library defines four classes: StreamEx, IntStreamEx, LongStreamEx, DoubleStreamEx which are fully compa

Tagir Valeev 2k Jan 3, 2023
java port of Underscore.js

underscore-java Requirements Java 1.8 and later or Java 11. Installation Include the following in your pom.xml for Maven: <dependencies> <dependency

Valentyn Kolesnikov 411 Dec 6, 2022