All Projects → thesephist → xin

thesephist / xin

Licence: MIT license
Xin (신/心) is a flexible functional programming language with a tiny core, inspired by Lisp and CSP

Programming Languages

go
31211 projects - #10 most used programming language
Vim Script
2826 projects
Makefile
30231 projects

Projects that are alternatives of or similar to xin

openj9
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Stars: ✭ 2,973 (+14765%)
Mutual labels:  interpreter
mlang
My toy programming languages
Stars: ✭ 36 (+80%)
Mutual labels:  interpreter
clover2
Clover2 can be used as shell. The completion is powerfull like IDE. Also clover2 is a Ruby-like compiler language with static type like Java. This is high performnace. Please see the wiki for details
Stars: ✭ 100 (+400%)
Mutual labels:  interpreter
punchscript
A programming language made up of Rajinikanth punch dialogues
Stars: ✭ 17 (-15%)
Mutual labels:  interpreter
vonuvoli-scheme
vonuvoli Scheme -- an R7RS interpreter written in Rust focused on systems programming and scripting (i.e. processes, file-system, etc.) with performance and safety in mind
Stars: ✭ 81 (+305%)
Mutual labels:  interpreter
thislang
A subset of javascript implemented in that subset of javascript. Yes, it can run itself.
Stars: ✭ 31 (+55%)
Mutual labels:  interpreter
tinySelf
Self-like language implemented in the RPython language toolkit.
Stars: ✭ 25 (+25%)
Mutual labels:  interpreter
tiny-lang
tiny-lang — A different programming language. Supports a bunch of spoken languages.
Stars: ✭ 26 (+30%)
Mutual labels:  interpreter
klisp
A Lisp written in about 200 lines of Ink, featuring an interactive literate programming notebook
Stars: ✭ 28 (+40%)
Mutual labels:  interpreter
minima
A fast, byte-code interpreted language
Stars: ✭ 43 (+115%)
Mutual labels:  interpreter
python-agentspeak
A Python-based interpreter for the agent-oriented programming language JASON
Stars: ✭ 32 (+60%)
Mutual labels:  interpreter
color-math
Expressions to manipulate colors.
Stars: ✭ 18 (-10%)
Mutual labels:  interpreter
xstate
State machines and statecharts for the modern web.
Stars: ✭ 21,286 (+106330%)
Mutual labels:  interpreter
Own-Programming-Language-Tutorial
Репозиторий курса "Как создать свой язык программирования"
Stars: ✭ 95 (+375%)
Mutual labels:  interpreter
kpspemu
PSP Emulator written in Kotlin for JVM, JS and Native. Can work as PWA.
Stars: ✭ 57 (+185%)
Mutual labels:  interpreter
AmazonSpeechTranslator
End-to-end Solution for Speech Recognition, Text Translation, and Text-to-Speech for iOS using Amazon Translate and Amazon Polly as AWS Machine Learning managed services.
Stars: ✭ 50 (+150%)
Mutual labels:  interpreter
consize
Consize is a concatenative programming language
Stars: ✭ 27 (+35%)
Mutual labels:  interpreter
bfloader
🧠 Brainfuck IDE and interpreter in 512 bytes. (boot sector)
Stars: ✭ 41 (+105%)
Mutual labels:  interpreter
Garam-Interpreter
"훈민정음은 디자인이다" 가람은 튜링 완전 프로그래밍 언어입니다.
Stars: ✭ 23 (+15%)
Mutual labels:  interpreter
whilelang
A small programming language created with ANTLR and Scala
Stars: ✭ 29 (+45%)
Mutual labels:  interpreter

Xin programming language

GoDoc Build Status

Xin is a functional programming language inspired by Lisp and CSP. Xin aspires to be an expressive, extensible language built on a small number of simple elements that work well together. You can find a deep dive into the language design in the spec document.

Xin is my second toy programming language, after Ink. With Xin, I'm specifically exploring ideas around code as a data structure, lazy evaluation in an interpreter context, and streaming evented I/O.

Here's the fibonacci sequence, written naively in Xin.

(: (fib n)
   (if (< n 2)
     1
     (+ (fib (- n 1))
        (fib (- n 2)))))

; 30th fibonacci number
(fib 30)

Xin supports proper tail calls, so we can write this in a faster (O(n)) tail-recursive form.

(: (fast-fib n)
   ((: (f n a b)
       (if (< n 2)
         b
         (f (- n 1) b (+ a b))))
    n 1 1))

; 50th fibonacci number
(fib 50)

You can find more example and real-world Xin code in the sample programs in the repository:

Goals

  • Expressive, readable, extensible syntax that's natural to read and suitable for defining DSLs
  • Programs that lend themselves to smart data structures and dumb algorithms, rather than vice versa
  • Great interactive Repl

Installation and usage

While Xin is under development, the best way to get it is to build it from source. If you have Go installed, clone the repository and run

go build ./xin.go -o ./xin

to build Xin as a standalone binary, or run make install to install Xin alongside the vim syntax highlighting / definition file.

Xin can currently run as a repl, or execute from a file or standard input. To run the repl, simply run from the command line:

xin

And a prompt will appear. Each input and output line in the prompt is numbered, and you can access previous results from the repl with the corresponding number. For example, take this repl session:

0 ) (+ 1 2)
0 ) 3

1 ) (vec 1 2 3)
1 ) (<vec> 1 2 3)

We can access 3, the result from line 0, as the variable _0. Likewise, _1 will reference the vector from line 1.

To run Xin programs from files, pass file paths to the interpreter. For example, to run samples/list.xin

xin samples/list.xin

You can also pass input as stdin piped into the CLI:

$ echo '(log (vec::sum (nat 10))) | xin'
55      # -> output

Key ideas explored

While Xin is meant to be a practical general-purpose programming language, as a toy project, it explores a few key ideas that I couldn't elegantly fit into Ink, my first language.

Lazy evaluation

In Xin, the evaluation of every expression is deferred until usage. We call this lazy evaluation. Values are kept in "lazy" states until some outside action or special form coerces a lazy value to resolve to a real value.

Code as data structure

Like all Lisps, the power and flexibility of Xin comes from its syntax, and the fact that it's trivial to express Xin programs as simple nested list data structures. Xin is not a "real" Lisp, because Xin does not use linked lists internally to represent its own syntax. But the idea of runtime syntax introspection with list data structures through macros is alive in Xin, and it's much of what makes the language so extensible.

Expressing all syntax as lists (auto-resizing vectors, internally) allows functions to modify or introspect their syntax at runtime, and this allows Xin programmers to build language constructs like switch cases, variadic functions, and lambdas in the userspace, as a library function, rather than having to add them to the language core, which remains tiny.

Streaming I/O and pipes

Xin expresses all I/O operations as operations to streams.

Syntax minimalism and extensibility

Xin is unusual among even toy programming languages in that there are only four special forms defined in the language spec: : (called "bind"), if, do, and import. All other language constructs, like loops, switch cases, booleans, and iteration primitives are defined in the standard library as Xin forms, not in the runtime as special cases.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].