Sugar – a typed lispy language targeting webasm/wat
ph1lter.bitbucket.io
Sugar – a typed lispy language targeting webasm/wat
1–10 of 28 posts
Re: Sugar – a typed lispy language targeting webasm/wat
#2Compiler is incomplete but I have written some reasonably complex programs.
Interesting to read for the, very short, compiler.
Re: Sugar – a typed lispy language targeting webasm/wat
#3This format uses S-expressions like lisp, and it's got a stack machine like forth. [1] [2]
I'm a bit surprised something so mainstream ended up being a lispy forth.
[1] https://ph1lter.bitbucket.io/blog/2020-12-03-webasm-forth-wi... [2] https://developer.mozilla.org/en-US/docs/WebAssembly/Underst...
Re: Sugar – a typed lispy language targeting webasm/wat
#4TIL that there's a format called wat, which means "WebAssembly text format" and it can be converted to wasm (and back to wat). This format uses S-expressions like lisp, and it's got a stack machine like forth. [1] [2] I'm a bit surprised something so mainstream ended up being a lispy forth. [1] https://ph1lter.bitbucket.io/blog/2020-12-03-webasm-forth-wi... [2] https://developer.mozilla.org/en-US/docs/WebAssembly/Und…
Thanks for reading the post :)
Update 2020-12-07: There was a bug in the macro expansion logic. I've backported the fix to the linked source and explained the bug in the 'mistakes' section.
Re: Sugar – a typed lispy language targeting webasm/wat
#5Re: Sugar – a typed lispy language targeting webasm/wat
#6Re: Sugar – a typed lispy language targeting webasm/wat
#7Super interesting; bookmarked! Looking forward to more updates :)
I am currently working on some of the "future directions" ideas and will post again soon about that.
Re: Sugar – a typed lispy language targeting webasm/wat
#8Re: Sugar – a typed lispy language targeting webasm/wat
#9When I read about a new typed Lisp I always hope to see a Lisp with Haskell-like type annotations. Is this easily feasible? That would be real sugar .
Do you mean literally the syntax
foo :: Type0 -> Type1 -> Type2
? Or do you mean the ability to have the type annotation on a separate line from the function implementation itself (rather than e.g. annotating its arguments individually)?In the case of the former you have Hackett (https://lexi-lambda.github.io/hackett/reference-syntactic-fo...) which unfortunately I think isn't seeing too much work on it anymore.
In the latter case something like Typed Clojure may work (https://github.com/clojure/core.typed).
Re: Sugar – a typed lispy language targeting webasm/wat
#10When I read about a new typed Lisp I always hope to see a Lisp with Haskell-like type annotations. Is this easily feasible? That would be real sugar .
In the Coursera course Programming Languages, I ported some of the first assignments from SML to F# and Typed Racket, and you can see the similarities of type annotations in the very simple examples below.
SML:
(* Helper function. Takes a generic list and an integer n and returns the nth element of the list. *)
fun get_nth_element (xs : 'a list, n : int) =
if n = 1
then hd xs
else get_nth_element(tl xs, n-1)
(* Takes a list of strings and an integer n and returns the nth element of the list. *)
fun get_nth (strings : string list, n : int) = get_nth_element(strings,n)
F#: /// Helper function. Takes a generic list and an integer n and returns the nth element of the list.
let rec getNthElement (xs : 'a list, n : int) =
if n = 1
then List.head xs
else getNthElement(List.tail xs, n-1)
/// Takes a list of strings and an integer n and returns the nth element of the list.
let getNth (strings : string list, n : int) = getNthElement(strings,n)
Racket: #lang typed/racket
;; Helper function. Takes a generic list and an integer n and returns the nth element of the list.
(: get-nth-element (All (T) (Listof T) Integer -> T))
(define (get-nth-element xs n)
(if (equal? n 1)
(first xs)
(get-nth-element (rest xs) (- n 1))))
;; Takes a list of strings and an integer n and returns the nth element of the list.
(: get-nth ((Listof String) Integer -> String))
(define (get-nth strings n) (get-nth-element strings n))