This is an automated archive made by the Lemmit Bot.

The original was posted on /r/programminglanguages by /u/dibs45 on 2024-10-12 06:48:46+00:00.


Hey everyone, just wanted to introduce a language I’ve been working on in my spare time called Sprig. I work with NodeJS daily and so I thought it would be an interesting idea to build a language using it.

Sprig is a dynamic (for now) programming language that focuses on direct interop with NodeJS/Javascript, allowing bi-directional data flow to leverage the powerhouse that is the V8 engine.

Here’s the repo, it’s quite minimalistic at the moment. I’ll be working on updating it to showcase all the features of the language:

Edit: Working on the official docs.

Examples:

Simple example showcasing the different ways functions can be called/chained:

const greet = (name) => `Hey {{name}}, welcome to Sprig 🌿`

"friend"->greet->print // Hey friend, welcome to Sprig 🌿
greet("pal")->print() // Hey pal, welcome to Sprig 🌿
print(greet("buddy")) // Hey buddy, welcome to Sprig 🌿

Example showcasing how to leverage NodeJS on the fly:

const nativeAdd = jsEval(`(a, b) => a + b`);

(100 + nativeAdd(20, 30))->print // 150

const rawBuffer = jsEval(`(size) => Buffer.alloc(size)`)

const buffer = rawBuffer(10)

print(buffer) // Buffer* Raw

print(buffer->value) // { 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0, 8: 0, 9: 0, readBigUInt64LE: native: 'readBigUInt64LE' (offset = 0), readBigUInt64BE: native: 'readBigUInt64BE' (offset = 0) ... }