9 ms·
Sugar – a typed lispy language targeting webasm/wat
- marksmillibend 6y agoSugar - a typed lispy language targeting webasm/wat. Compiler is incomplete but I have written some reasonably complex programs. Interesting to read for the, very short, compiler.
- fouc 6y agoTIL 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-with-lisp-syntax.html https://ph1lter.bitbucket.io/blog/2020-12-03-webasm-forth-wi... [2] https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format https://developer.mozilla.org/en-US/docs/WebAssembly/Underst...
- marksmillibend 6y agoTIL that TIL means "Today I Learned". 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.
- foota 6y agoIn case you're not aware, I believe that web assembly is a stack based language. You may be interested to read this, which talks about a proposal to add additional stack instructions: https://github.com/WebAssembly/design/issues/1381 https://github.com/WebAssembly/design/issues/1381
- camgunz 6y agoSuper interesting; bookmarked! Looking forward to more updates :)
- marksmillibend 6y agoThank you for your encouraging words. I am currently working on some of the "future directions" ideas and will post again soon about that.
- robin-a 6y agoI know WebAssembly language (WASM), as the thing Dfinity (https://sdk.dfinity.org/docs/index.html https://sdk.dfinity.org/docs/index.html) uses. They have a nice language called Motoko (https://sdk.dfinity.org/docs/language-guide/motoko.html https://sdk.dfinity.org/docs/language-guide/motoko.html) I was playing with. But I like the idea of this kind of Lispy Forth.
- galfarragem 6y agoWhen 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.
- dwohnitmok 6y agoWhat do you mean by Haskell-like type annotations? 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-forms.html#%28part._reference-type-annotation%29 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 https://github.com/clojure/core.typed).
- bmitc 6y agoTyped Racket is pretty close. I imagine that with some work and Racket's macro and module system that someone could rewrite it to be more ML-like in syntax. 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))
- chriszhang 6y agoWill you say it is ok for a complete new person to lisp to learn sugar? Example is someone who has never learnt lisp in life? Or will you recommend learning sugar after learning some other lisp?
- lbotos 6y agoNot OP, I've only written a tiny bit of lisp, but this looks pretty similar. I'd probably suggest SICP: https://mitpress.mit.edu/sites/default/files/sicp/index.html https://mitpress.mit.edu/sites/default/files/sicp/index.html if you want a "lisp intro"
- nobleach 6y agoThat book can get really dense really quickly. It DOES appeal to certain types of learners though. So since, you can find the HTML version for free, check it out. I personally suggest "The Little Schemer". It literally starts with Atoms and works its way out. It uses Scheme, which Racket is based on. I highly recommend it.
- TurboHaskal 6y agoIf you already know how to program, I'd recommend to just install SBCL and start a project with https://lispcookbook.github.io/cl-cookbook/ https://lispcookbook.github.io/cl-cookbook/ as a companion. Forget about the perfect editor setup, idiomatic code and all that fuzz about becoming enlightened. (Common) Lisp is first and foremost a productive, pragmatic language to get things done, so just start hacking.
- thealig 6y agoI am particularly looking to learn a LISP style language. Scheme and Racket caught my interest, given its concise, expressive syntax. Is it advisable to start with Common Lisp first, or go with Scheme/Racket? Thanks for the tip btw.
- TurboHaskal 6y ago
- valenterry 6y agoI really like the power and flexibility of Lisps, but I am so much more productive with good(!) statical typesystems. Looking at both typed racket and now sugar, it doesn't look really good to me. I think I would rather decide to go straight for Haskell/Scala/... or Lisp/Clojure. Maybe it's not really possible to combine both in a good way _yet_, or maybe it's not possible in general. I hope for the former.
- timdeve 6y agoYou should check out Carp[1]. The language is still young but it might scratch that itch. [1] https://github.com/carp-lang/Carp https://github.com/carp-lang/Carp
- banjomet 6y agoThere is also bonelisp[0], but I think that is dead. [0]: https://github.com/wolfgangj/bone-lisp https://github.com/wolfgangj/bone-lisp
- Chris2048 6y agoAny relations to sweetjs.org - "Hygienic Macros for JavaScript"?
- tpoacher 6y ago... WAT?