npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yascriptlang

v1.1.0

Published

A simple scripting language inspired by Lisp

Downloads

12

Readme

Yascriptlang

Build Status npm version Downloads Package Size

Yet Another Script Language

Because everyone should have their own Lisp

Yascriptlang is high-level and multi-paradigm language. It has curly-bracket syntax, strong dynamic typing, recursion, and first-class functions.

As a multi-paradigm language, yascriptlang supports functional and imperative programming styles both.

Yascriptlang can be interpreted as well as compiled in JavaScript.

Installing

npm install -g yascriptlang

Documentation

The documentation is located in the docs folder.

Usage

Run interpreter:

yas input.yas

Compile to JS:

yasc input.yas output.js

Compile to JS and run:

yasjs input.yas

Building

Pre-reqs

To build and run this app locally you will need a few things:

Getting start

  • Clone the repository
git clone --depth=1 https://github.com/maxbarsukov/yascriptlang.git
  • Install dependencies
cd yascriptlang
yarn
  • Run
node bin/yas.js input.yas
# or
node bin/yasc.js input.yas output.js
# or
node bin/yasjs.js input.yas

Examples of code

Here are some code examples. Go to there docs to see more.

Comments:

### Comments
# comment
// comment
/*
multi
line
comment
*/

Strings:

println("Hello World!");
println('Hello World!');
println('Hello " World!');
println("Hello ' World!");

Math:

println(2 + 2 * 2); # => 6
println(3 ** 3); # => 27
println(10 / 5); # => 2
println(17 % 3); # => 2

Variables: (variables are immutable by default)

def pi = 3.14;
println(pi);

def a = {
  10;
  15   # the last semicolon can be missing
};
print(a); # prints 15

def mut b = 1;
b += 2;
b **= 3;
println(b); # => 27

Raw JS:

println(_js_ '[0, 1, 2, 3].length * 2') # => 8
println(_js_ 'console.log("HI!"); 2+4') # => prints HI! and 6
println(_js_ '((a) => { console.log(`HI, ${a}!`)})("Max")') # => prints HI, Max!

Mutable Variables:

def mut a = 3
a = 2;
println(a); # => 2

Functions:

def fib = fn (n) -> if n < 2 then n else fib(n - 1) + fib(n - 2);
println(fib(15));

def print_range = fn(a, b) ->
                if a <= b then {
                  print(a);
                  if a + 1 <= b {
                    print(", ");
                    print_range(a + 1, b);
                  } else println("");
                };
print_range(1, 5); # => 1, 2, 3, 4, 5

def func = fn-> {
  10;
  20;
};

println(func()); # => 20. Functions returns the last var

Lambdas:

# fn -> {} is short for fn() -> {}

(fn->{
println(3 ** 3);
})();

Pipes:

def k = 200;
k |> println; # prints 200

2 |> fn(x) -> (x * x) |> println; # prints 4

Benchmarks:

time(fn-> {
  println(fib(15));
});

Let:

def a = 1;
let (mut a = 10) -> {
    println(a); # => 10
  };
println(a); # => 1


print(let loop(n = 10) ->
  if n > 0 then n + loop(n - 1)
  else 0);
# => 55

let (x = 2, y = x + 1, z = x + y) ->
  println(x + y + z); # => 10


let (x = 10) -> {
  let (x = x * 2, y = x * x) -> {
    println(x); # 20
    println(y); # 400
  };
  println(x); # 10
};

if / else:

def f = fn-> { true; };
def a = if f() then "OK" else "FAIL"; # OK
if 1 == 1 && 2 < 5 then print("OK"); # OK

true / false :

if true then print("OK"); # OK
if !false then print("OK"); # OK
if false then print("Won't be printed");

Lists:

def list = cons(1, cons(2, cons(3, cons(4, cons(5, NIL)))));
print(car(list)); # 1
print(car(cdr(list))); # 2
print(car(cdr(cdr(list)))); # 3
print(car(cdr(cdr(cdr(list))))); # 4
print(car(cdr(cdr(cdr(cdr(list)))))); # 5

Yield:

foo = with-yield(fn(yield) -> {
  yield(1);
  yield(2);
  yield(3);
  "DONE";
});

println(foo()); # 1
println(foo()); # 2
println(foo()); # 3
println(foo()); # DONE

Some stdlib methods:

# foreach
foreach(x, println); # prints from 1 to 5 by println

# range
foreach(range(1, 8), fn(x) -> println(x * x));
# or
foreach(range(1, 8), fn(x) -> (x * x) |> println);
# prints 1, 4, 9, 16, ... 49, 64

# throw / catch
exit = false;
x = 0;
callcc( fn(k) -> exit = k );
if x == 0 then catch("foo", fn-> {
println("in catch");
x = 1;
exit();
});
println("After catch");
throw("foo", "FOO");

License

The package is available as open source under the terms of the MIT License.