Arc.js

An Arc-language interpreter written in JavaScript.

Arc.js

This is an Arc-language interpreter written in JavaScript. It can run both on nodejs and on a web-site.

REPL

Demo

Client side

  1. REPL (fullscreen)
  2. Maze generator
  3. Strange attractor generator
  4. Reversi player
  5. Tetris in 80 lines

Server side

  1. Running on node server (comming soon)

Documentation

Features

Stack based vm ( visualizer ) Self-hosting compiler
First-class continuations Tail call optimization
mac macro Almost of anarki’s functions.
user tagged objects (annotate) defgeneric (object system)
complex-args (let, fn) regexp (#/exp/)
Special syntax (:~.!) user defined special syntax (defss)
User difined type function (deftf) stack-tracer

How to install

You have to install nodejs and npm first.

$ sudo npm install -g arc-js

Then, You can run REPL.

$ arcjs
arc> (pr 'hello-world)
hello-world
hello-world
arc> (+ 1 2)
3
arc> (def average (x y) (/ (+ x y) 2))
#<fn:average>
arc> (average 2 4)
3

How to use on the website

1. Basic interface

In the HTML ‘<head>’

<script type="text/javascript" src="arc.min.js"></script>

Then, You can run arc-language in your javascript.

var arc_runner = ArcJS.context();
var res = arc_runner.evaluate("(+ 1 2 3 4)");
console.log(res); // 10
// FizzBuzz
var code = [
 "(prn 'Start_FizzBuzz)",
 "(for n 1 100",
 "  (prn (case (gcd n 15)",
 "         1 n",
 "         3 'Fizz",
 "         5 'Buzz",
 "         'FizzBuzz)))"].join("\n");
arc_runner.evaluate(code);  // 1, 2, Fizz ...

Demo Page

2. Auto loading interface

In the HTML ‘<head>’

<script type="text/javascript" src="arc.min.js"></script>
<!-- jQuery is required in arc-loader.js -->
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="arc-loader.js"></script>

Then, You can load arc files as follows.

<script type="text/arc" src="fizzbuzz.arc"></script>

fizzbuzz.arc

(def fizzbuzz (limit)
  (for x 1 limit
    (prn
      (aif (mappend [if (is 0 (mod x car._)) cdr._] '((3 Fizz) (5 Buzz)))
           (string it)
           x))))

Then you can do following

<script type="text/arc">
(fizzbuzz 3)
(fizzbuzz 100)
</script>

Demo Page

referred to

License

# ArcJS

Copyright (c) 2012 Shin Aoyama
-----------------
Perl Foundations's Artistic License 2.0

# Anarki

Copyright (c) Paul Graham
Copyright (c) Robert Morris
Copyright (c) A lot of contributors (see https://github.com/arclanguage/anarki/graphs/contributors)
-----------------
Perl Foundations's Artistic License 2.0

# Arc language

Copyright (c) Paul Graham
Copyright (c) Robert Morris
-----------------
Perl Foundations's Artistic License 2.0