Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize sibilant output #98

Open
matthewp opened this issue Oct 30, 2017 · 6 comments
Open

Modernize sibilant output #98

matthewp opened this issue Oct 30, 2017 · 6 comments

Comments

@matthewp
Copy link
Contributor

I think there would be some benefit of modernizing sibilant js output to modern ES201x. In particular it would be good to support:

  • Classes
  • Different binding types (var, let and const, or at least updating to allow const).
  • Import and export variations.

This would of course be a breaking change

@riatzukiza
Copy link

I've written sibilant macros which compile to these forms, it is relatively easy.

(macro => (args ...body)

       ["((" ...(interleave ", " args.contents) ") => {\n\t"

             (indent (apply ^do body))

             "\n})"])

this implements an arrow function

(macro class  (name super-class body)
       "create an es6 style class."
       ["class " name
                 ...(if body (interleave " " [" extends" super-class ]) [])
                 " "
                 `(curly ...@(.map (get (or body super-class)
                                        "contents") global.lit-macros ))])

this implements the class syntax, which I based this on top of some macros I built implementing the various new object literal syntaxes

(meta

 (macro lit (...body) `(literal ...@(.map body global.lit-macros )))
 (macro describe (name ...body)
        `(mixin (lit ...@body) @name))

 (macro transpile-and-format (form)
        `(pipe  @form
                transpile
                output-formatter))
 (macro def-lit-macro (name args ...body)

        (assign name (transpile-name `(@ name)))

        (var t (transpile-and-format  `(lambda @args ...@body)))

        (set lit-macros name (eval t))

        null)

 (def global.lit-macros (el)


   (if (expression? el)

       (do (var name (transpile-name el))

           (if (and (literal? (first el.contents))
                    (has-key? lit-macros name))

               ((get lit-macros name) (dots (rest (content-of el))))

               `(property ...@(content-of el)))) el))

 (def lit-macros.init (args ...body)
   `(init @args ...@body))

 (def lit-macros.gett (name ...body)
   `(gett @name ...@body))

 (def lit-macros.alias (name from)
   `(alias @name @from))

 (def lit-macros.sett (name value-name ...body)
   `(sett @name @value-name ...@body)))

@riatzukiza
Copy link

But I never use the class syntax, I'm not a fan of it much. I mostly wrote it to understand the macroing system of sibilant a bit better.

If your interested, I've got a whole tool set of macros and other tools for working with sibilant and the newer versions of js.

@matthewp
Copy link
Contributor Author

Hey @riatzukiza, I really think these macros (or some of them) should be in sibilant proper. I don't particularly love classes either, but some APIs require them, so using sibilant at least allows you to author them in a functional way.

matthewp added a commit to matthewp/sibilant that referenced this issue Dec 14, 2017
This is part of jbr#98 and adds the "const" macro. It's just like "var" but
produces JavaScript constants:

```lisp
(const a 3)
```
@jbr
Copy link
Owner

jbr commented Dec 20, 2017

@riatzukiza I'd love to see those macros, either PRed into sibilant core or possibly as a package of macros that would be easy to npm install and include. One of my goals for this project was to make it easy to publish macros on npm, which potentially could be as large as whole language variants. I imagine some work would be required to actually achieve that goal, but I'd love to see it happen. If the changes are very sweeping or don't belong in core, it would be awesome to have an official list of dialects or macro sets listed prominently on the readme and docs

@riatzukiza
Copy link

https://github.com/riatzukiza/kit

This is the core language I use in several other libraries, which I am getting ready to publish to npm all together.

@riatzukiza
Copy link

riatzukiza commented Feb 22, 2018

I recently published several of the other libraries I've written with sibilant as well:

Kits (libs)

https://github.com/riatzukiza/kit-interface
https://github.com/riatzukiza/tree-kit
https://github.com/riatzukiza/kit-html
https://github.com/riatzukiza/kit-file-system
https://github.com/riatzukiza/language-model

This last one is broken atm, theres definately a working version some where in the git history, and I have a plan of action for this lib, it just keeps getting pushed back every time I touch it.

https://github.com/riatzukiza/kit-http

Programs

Here are a few programs I wrote with sibilant as well.
https://github.com/riatzukiza/Algae-speciation-tech-demo
https://github.com/riatzukiza/symbiant

No garentee that these run/compile with out some work atm though. Its on my list of things to get fixed. the "kits" are a lot more stable than the programs.

There will be other programs published in the near future, I've written a lot. I have a lot of time on my hands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants