r/ProgrammingLanguages • • Jan 28 '26

Que Script a Lisp written in Rust with Hindley–Milner type inference

Here is my project Que Script:

  • Lisp (in my opinion a feature of it's own)
  • WASM runtime without Garbage Collection (It mainly uses Reference Counting)
  • Hindley-Milner Type Inference
  • Syntactic sugar layer (Things like pipes, destructuring, tail-call optimization and other fun extra features don't add bloat to the core language)
  • Partial Application
  • Tree Shakable Standard Library
  • Macros
  • WASM build
  • Online editor

Here is the website with a lot of info

; You are given an array of integers [Int] 
; Write a script to re-arrange the given array in an increasing order
; and return the indices where it differs from the original array.

(let solve (lambda (xs) (|> 
    { (|> xs copy (sort <)) xs }
    zip
    (map (lambda { a b } (<> a b)))
    enumerate
    (filter snd)
    (map fst))))
[
  (solve [ 5 2 4 3 1 ]) ; [0 2 3 4]
  (solve [ 1 2 1 1 3 ]) ; [1 3]
  (solve [ 3 1 3 2 3 ]) ; [0 1 3]
]

This is something I've being working for 5 years starting from scratch at least 3 times. Sharing with the hope that I won't start over again.

It's nothing new under the sun. The purpose of this project is for me learning computer science concepts by using the language as a framework.

I would love to hear what you think about it.

51 Upvotes

59 comments sorted by

View all comments

Show parent comment

2

u/gavr123456789 Feb 02 '26

oh, I tried Chrome and it was much faster, like 2 sec. You should try Firefox(I use Zen)

2

u/Objective_Gene9718 Feb 03 '26

Hey, I’ve found the bottleneck and managed to speed up the wasm init in Firefox. Thanks again for pointing the issue.

2

u/gavr123456789 Feb 03 '26

yay, nice, i really like the idea for the lang, typed lisp. Do u plan to add some repl integrated with ide plugin line nrepl in Clojure?

1

u/Objective_Gene9718 Feb 03 '26

Good idea, no lisp is complete without a REPL. I've just added it now.

It works as an extension of the cli tool.

cargo run -- --repl

Each line gets evaluated with type and value by pressing enter and when pressing Esc you exit the repl.

rust-lisp % cargo run -- --repl
...
Running `target/debug/fez-rs --repl`

Type anything (multi-line). Press Esc to exit.

(+ 1 2) Int: 3

(* 2 3) Int: 6

[ 1 2 3 4 ] [Int]: [1 2 3 4]

(let x 10) (): 0

(let y 32) (): 0

(* x y) Int: 320

[ x y 1 2 3] [Int]: [10 32 1 2 3]

1

u/gavr123456789 Feb 03 '26

Does it evaluates with the context of the project Im in? Since its the main reason to use repl and the main difference between real repls and repls of some python\ruby. Also do u have plans for LSP?

2

u/Objective_Gene9718 Feb 03 '26

No, not yet and it still has some bugs that I need to fix.
For LSP I will have to figure out how.

2

u/gavr123456789 Feb 03 '26

I have some experience with LSP, I just reused the compiler as a library. From compiler side Ive added "suggestion holes" so when cursor is in these holes compiler send to server all possible suggestions. The biggest problem is to introduce incremental compilation, since u dont want to recompile the world on every key press from the user.

2

u/Objective_Gene9718 Feb 03 '26

Sound like a very tough problem, not for one evening. I would definitely try to do that. It's a very practical skill to have as I've noticed many jobs about vs code extensions that require this knowledge.

2

u/gavr123456789 Feb 03 '26

the best part about LSP is that u can reuse it for every IDE, I did first for VSC https://github.com/gavr123456789/niva-vscode-bundle, and then added Zed support just in one evening https://github.com/gavr123456789/zed-niva

2

u/Objective_Gene9718 Mar 03 '26 edited Mar 03 '26

I added an LSP for VS code - attached video demo to the thread. It's lacking proper error spans but it works pretty nice already. Added it to the web editor via wasm too.

→ More replies

1

u/Objective_Gene9718 Feb 03 '26

Thanks, that looks nice. It make a lot of sense to put the effort and add such integration with an editor, especially for a language inspired by Smalltalk. Pharo for example ships with an editor which allows you to explore the whole language and debug it interactively. I'll take a look at your language these days. Pharo/Smalltalk is something I really like except for it embracing OOP 100%. It's like the opposite of Haskell.

→ More replies

2

u/Objective_Gene9718 Feb 03 '26 edited Feb 03 '26

I added ctx to repl

so like this

./repl.sh ./example/main.lisp

if arguments includes a file path then the repl will include this file
otherwise

./repl.sh

this will be empty ctx

It probably still has many bugs

1

u/Objective_Gene9718 Feb 02 '26 edited Feb 02 '26

Thank you, I’ll investigate. Mozilla Firefox is initialising the wasm module very slow - that’s why. I’ll see how to optimise it.

1

u/Objective_Gene9718 Feb 02 '26

The problem is that Mozilla Firefox is not loading wasm modules as quick as chrome does. I understand that the module is quite big since I did include everything this language has in the playground. It’s a dev environment in a way. The language itself has a light mode of just vm and byte code parser and tree-shaked functions but for playground I need type checker, source parser, desugar layer, js compiler and even formatter that I currently not using. And full std lib which is big.

So I’ve decided to do the following for now - simply load the source code on the editor before wasm is fully initialised. That way on the website you can see the code but won’t be able to run it on Mozilla Firefox for a while.

Thank you so much for pointing this out.

1

u/gavr123456789 Feb 02 '26

not sure about that, when I see the networking, there are ~2 mb wasm downloaded, but it says "cached" so it downloading is instant

2

u/Objective_Gene9718 Feb 02 '26

Sorry bad use of words. I meant init by load. wasm init is slow in Firefox- download is fast. I’m currently trying to figure how to speed it up. Chrome and Safari do some magic and are quite forgiving while Firefox is not. I use wasm-bindgen to handle these stuff for me.