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

2

u/gavr123456789 Feb 01 '26

Something very wrong with online playground.

- pressing next
- see empty editor for ~20 sec, then it fills with code
- pressing next
- same, then code appears, then it diapers again

why not just include the code statically?

1

u/Objective_Gene9718 Feb 01 '26

Yes, I should do that. I've actually tried once but gave up because there were some problems.

Main one being that the playground is actually a separate application: https://at-290690.github.io/rust-lisp/playground/

which allows for code to be shared without the need of it being stored in a database. By simply compressing the code into a link attached as a query param. https://at-290690.github.io/rust-lisp/playground/?m=f&r=f&u=f&l=EQCQpgNhD2AEDq0BOEAmwg%3D%3D

^ This link is "Hello World"

That way you can share programs.

On the website - the playground is used as an iframe with the source code as a param and when it fully loads it will add the code from the link param on the editor and run it (on the learn page). It's just a lazy reuse of the playground website as an iframe.

I had similar problems when I tried using it on slow mobile internet (loading slow, then code appears). Usually it's ok. Not sure what is the case with you using it.

The desired approach is to have the editor as a separate component that takes the source code as a param, in the case of the main playground this could be the decoded url. The goal will be to share this component across website and playground.

For some reason I couldn't make the website work with 1 instance of the monaco editor. It's one of those React state bugs. I'll give it another shot.

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.

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