Key features
ArkScript is
  • small (less than 10'000 lines of idiomatic C++20)
  • a scripting language
  • portable, compile once, run your bytecode anywhere
  • functional, every argument is passed by copy
  • homoiconic, you can manipulate code with macros
  • extensible, through C++ plugins
More features
  • async/await on any function
  • no hidden references
  • tail call and unused variable optimization
  • a REPL with autocompletion and coloration
  • a standard library in ArkScript and C++
  • only need to learn 9 keywords
  • docker images: stable, nightly
Fibonacci suite
(let fibo (fun (n)
  (if (< n 2)
    n
    (+ (fibo (- n 1)) (fibo (- n 2))))))
 
(print (fibo 28))  # display 317811
Error messages to help you
CompilationError: Unbound variable error "fib" (did you mean "fibo"?)
In file fibonacci.ark
On line 7:12, got `(Symbol) fib'
   4 |     n
   5 |     (+ (fibo (- n 1)) (fibo (- n 2))))))
   6 | (while continue {
   7 |   (print (fib 28))
     |           ^^^
   8 |   (if (< (/ (random) 32768) 0.1)
   9 |     (set continue false))
Bytecode explorer
Version:   4.0.0
Timestamp: 1745512684
SHA256:    6311b3eb87739fac8751dc8147fb6d29e66230ea8a726e5115515735b8709148

Symbols table (length: 3)
0) foo
1) a
2) b

Constants table (length: 3)
0) (PageAddr) 1
1) (Number) 1
2) (Number) 2

Instruction locations table (length: 2)
 PP, IP
  0,  0 -> a.ark:2
  0,  3 -> a.ark:4

Code segment 0 (length: 24)
   0 39 00 00 00 LOAD_CONST_STORE
   1 38 00 20 01 LOAD_CONST_LOAD_CONST
   2 02 00 00 00 LOAD_SYMBOL_BY_INDEX (0)
   3 0b 00 00 02 CALL (2)
   4 4b 00 10 09 CALL_BUILTIN (4105)
   5 0a 00 00 00 HALT

Code segment 1 (length: 20)
   0 05 00 00 01 STORE a
   1 05 00 00 02 STORE b
   2 0d 00 00 02 BUILTIN nil
   3 09 00 00 00 RET
   4 0a 00 00 00 HALT
Straightforward embedding
#include <Ark/Ark.hpp>
 
int main()
{
    // A state can be shared by multiple VM ; they can't overwrite it
    Ark::State state;
 
    // This will compile the code, but you can also give a file with state.doFile()
    state.doString("(let foo (fun (x y) (+ x y 2)))");
    // You can register C++ function (only before calling vm.run())
    state.loadFunction("cpp_foo", [](std::vector<Ark::Value>& args, Ark::VM* vm) {
        return Ark::Value(static_cast<int>(args.size()));
    });
 
    Ark::VM vm(state);
    vm.run();
 
    auto value = vm.call("foo", 5, 6.0);
    // displays 13
    std::cout << value << "\n";
 
    return 0;
}
Sponsors & donors
Found a bug, need help with the language?

We have a bug tracker where you can report bugs and feature requests.

Head to the forum if your problem / suggestion doesn't fit or if you need help with the language!

OSZAR »