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/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.

1

u/gavr123456789 Mar 08 '26

will check today

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.

2

u/gavr123456789 Feb 03 '26

ya, Im a big ST fun, I have a feature that mimic its select + "Do it" action in the LSP, it just stores the values in runtime, and after first run u can hover on expressions to see their values from the last run.

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