10 ms·
Show HN: Eslisp – Minimal JavaScript S-expression syntax and macro system
- nanny 11y agoNeat. Why would I use this over ClojureScript or Parenscript?
- an_ko 11y agoClojureScript tries to be Clojure, and Parenscript tries to be Common Lisp. Eslisp tries to be JavaScript; it's intended to just be an obvious one-to-one syntax replacement. I wrote a brief comparison in the docs: https://github.com/anko/eslisp/blob/master/doc/comparison-to-other-js-lisps.markdown https://github.com/anko/eslisp/blob/master/doc/comparison-to...
- agumonkey 11y agoMust be fairly fun to use inside of emacs, leveraging sexp based navigation.
- an_ko 11y agoI'm a vim user actually! gasp Seeing ParEdit in action makes me extremely jealous though. http://danmidwood.com/content/2014/11/21/animated-paredit.html http://danmidwood.com/content/2014/11/21/animated-paredit.ht... I wonder if the vim plugin https://github.com/vim-scripts/paredit.vim https://github.com/vim-scripts/paredit.vim is any good.
- agumonkey 11y agoYou know, it doesn't really matter. ;) Never tried the paredit vim extension, but I've heard a few people happy editing clojure/lisp under vim so I'm sure it's more than OK.
- kuschku 11y ago> it doesn't really matter. ;) Best way to start a flamewar on IRC: "the difference between emacs and vi doesn't really matter" Luckily, this won't happen here xD
- agumonkey 11y agoI suffer from Abstractitis. Everything is the same to me. #turingcompleteness
- agumonkey 11y agoFunny, just found this about Emacs and Vi. https://youtu.be/4YfkwfZ7AV4?t=1521 https://youtu.be/4YfkwfZ7AV4?t=1521 Don Stewart, haskeller, talking about is editor of choice, vi, emacs, Yi, and the eternally self reemergent struggle.
- deepaksurti 11y agoI code in CL, Clojure using only vim. I use only % operator, set sw = 2, visual > or < to edit lisp forms and I am very happy!!!
- agumonkey 11y agoM-x betrayal RET What does %, > and < do in your setup ? An emacser wrote a thing called lispy to have vi-like sexp manipulation UX (aka single letter commands).
- deepaksurti 11y agoIf I want to move a nested s-exp outside: (foo (bar baz) quux zot) Using d% on (bar baz) then move to desired loc, and p. So % is for matching ( ). Again v% visually selects a form, then < and > for indent and dedent.
- Gonzih 11y agoI used paredit vim. It's good, nowodays I use emacs+evil, but still would advise using paredit in vim. It's pretty good, different from one in Emacs though.
- aidenn0 11y agoReally only macros are in common lisp for Parenscript. Parenscript very strongly tries to be close to JavaScript.
- an_ko 11y agoThat's very true. For anyone with an existing Common Lisp stack who wants to use CL macros to write JS, Parenscript is great. I wanted to write JS macros in JS, hence eslisp.
- natrius 11y agoDo you prefer JavaScript's semantics to Clojure's? I don't, but I'm interested in being convinced. This is a neat project regardless.
- an_ko 11y agoI think Clojure is the better-designed language overall, but JavaScript's simplicity and the size of its community and deployment make it very attractive. The enemy of "better" is "good enough", I suppose.
- eggy 11y agoI am learning Shen [1], and this talk [2] shows how you can write Shen on JavaScript, Ruby, front an backend. Shen is a lisp with pattern matching, optional lazy evaluation, optional static type checking, macros of course, and many other cool treats! It can run on top of CL (SBCL), Clojure, JavaScript, Python, and more. [1] http://www.shenlanguage.org/ [2] https://www.youtube.com/watch?v=lMcRBdSdO_U
- joubert 11y agoHow does its macrology stack up against sweetjs? http://sweetjs.org http://sweetjs.org
- an_ko 11y agoEslisp macros are compile-time functions that operate on code consisting of lists. Sweet.js macros are special-case separate structures that have to introduce special syntax, pattern-matching rules and a whole lot of other cruft, mainly to deal with JavaScript not being homoiconic. tldr eslisp macros are prettier, otherwise quite similar.
- dherman 11y agoFun :) Back in my Racket days (back then it was known as PLT Scheme and dinosaurs roamed the web) I did a similar thing: http://planet.racket-lang.org/package-source/dherman/javascript.plt/9/2/planet-docs/javascript/pjs.html http://planet.racket-lang.org/package-source/dherman/javascr... The Javadot notation was really convenient -- might be worth checking out: http://jscheme.sourceforge.net/jscheme/doc/javadot.html http://jscheme.sourceforge.net/jscheme/doc/javadot.html
- an_ko 11y agoWow, many thanks for sharing! PJS is very neat and its documentation very clear. I'm surprised how little JavaScript has changed in 16 years… I've got a Javadot-like thing https://github.com/anko/eslisp-propertify https://github.com/anko/eslisp-propertify for converting a.b.c → (. a b c). Eslisp uses "." for property access, like PJS' "field". It hasn't got a next-line (.property args) thing though, which seems useful. I'll be trying that.
- jrapdx3 11y agoTo my taste, Lisp's hierarchical list notation is by far the most natural, intuitive way to represent HTML. I exploited this Lisp feature to create a web server using Scheme and C (a 5-year project). While my server still works well, it's obvious Node and JS have become predominant tools in the space. I used these tools for my most recent project and while not too difficult to get up to speed, it lacked the elegance and simplicity I preferred. Eslisp looks promising, surprisingly close to Lisp/Scheme I'm familiar with. I'm thinking that a few changes might make it even closer. For example, one could use "define" instead of "=" to declare bindings, or "begin" instead of "block". The "this" syntax in macros is reminiscent of the arguments to ER syntax transformers which can be used to operate on elements in macros. Is it possible to simplify it further? Something like (this/evaluate) instead of (. this evaluate)? Just ideas that pop into mind... I agree that using s-expr syntax to create macros makes is much better than the elaborate syntax of other JS macro systems. I'm looking forward to learning more and trying it out. Eslisp looks like it will be excellent.
- an_ko 11y agoMany thanks for your thoughts. > Lisp's hierarchical list notation is by far the most natural, intuitive way to represent HTML. HTML-representation is also important to me, and it's how I got started on eslisp actually. I wrote an XML templater https://github.com/anko/whatxml https://github.com/anko/whatxml for LiveScript that abused the ".." cascaded-function-call feature to create XML hierarchies. It took me a while to realise it was basically an S-expression in disguise! I'm working on an "eslisp-html"-macro that compiles to an HTML-templating function. Here's the gist of it so far https://gist.github.com/anko/f8ecc66a99a8ec656b49 https://gist.github.com/anko/f8ecc66a99a8ec656b49 No implementation yet, just an early-ideas readme with an example. What do you think? > For example, one could use "define" instead of "=" to declare bindings, or "begin" instead of "block". If you want to use different names for the built-in macros, you are welcome to. Aliasing them is just a matter of "(macro define =)", then "define" does the same as "=". > The "this" syntax in macros is reminiscent of the arguments to ER syntax transformers which can be used to operate on elements in macros. Is it possible to simplify it further? Something like (this/evaluate) instead of (. this evaluate)? Property access can be sugared to "this.evaluate" with the eslisp-propertify macro https://github.com/anko/eslisp-propertify https://github.com/anko/eslisp-propertify It's quite convenient if you use it as a transform macro https://github.com/anko/eslisp/blob/master/doc/how-macros-work.markdown#transform-macros https://github.com/anko/eslisp/blob/master/doc/how-macros-wo... from the command line, like this https://github.com/anko/eslisp-fancy-function/blob/master/makefile#L6 https://github.com/anko/eslisp-fancy-function/blob/master/ma... Is that what you mean?
- dangoor 11y agoThis reminds me of wisp: https://github.com/Gozala/wisp https://github.com/Gozala/wisp
- an_ko 11y agowisp was indeed an inspiration! A pretty fundamental difference is that eslisp macros are ordinary JavaScript functions, which you can put on npm, and write in any language. In wisp, macros are magic compiler-internal things. Here's a brief comparison to a few other JS-lisps too: https://github.com/anko/eslisp/blob/master/doc/comparison-to-other-js-lisps.markdown https://github.com/anko/eslisp/blob/master/doc/comparison-to...
- Gonzih 11y ago> (The non-JVM self-hosted implementation does not yet support macros at the time of writing.) Fixed, you can remove this line :)
- Kjeldahl 11y agoLooks great. At the very least it needs a built-in function shortcut; people are already used to ES6/Coffeescript shortcuts. Yes, I understand I can probably macro it myself, but that doesn't mean it's not needed in core. Anyway, looks like a great piece of work!
- an_ko 11y agoIf you mean shortcuts like argument-splats and implicit return-statements, https://github.com/anko/eslisp-fancy-function https://github.com/anko/eslisp-fancy-function is on npm. All you need is to npm install it and do (macro function (require "eslisp-fancy-function")) If you want it in all files, it's safe to cat that onto the start of each as a build step. I do see your point though—it's a very common thing for people to want to use. I'm adhering strictly to UNIX design priciples for now because I'm afraid of featuritis, but perhaps that will change as the project matures. I'm playing with the idea of having a separate convenience "getting started" package called "eslisp-coffee" or something, which acts like the core eslisp compiler but with a certain set of macros attached by default. What do you think?
- Kjeldahl 11y agoeslisp-fancy-function looks great. One standard package with a lot of sensible defaults - based on learnings from ES6, Coffeescript etc - sounds like a great idea. Again, great work!
- beders 11y agoListen to an old man that has gotten his feet wet with Allegro Common Lisp back in the day: Avoid macros if at all possible. Use functions if you can. Special forms that don't follow the standard evaluation rules are putting additional mental load on the readers of your code. If you go overboard with macro use, good luck having other people understand your code. If you are a lone coder, feel free to go happy-crazy with macros. If you are a team, just stay with standard lisp as long as you can.
- sklogic 11y agoYou do not understand macros at all. One should always prefer macros to anything else. Macros must be used to implement hierarchies of composable eDSLs - by far the most powerful and advanced way to handle abstraction. Functions are not a match to this. Heavily DLSed code is much more readable and maintainable than your mess of functions.