JavaScript. It is awesome.
Not sure if it's sarcasm. True, JavaScript is fun to meta-program. But it's hell to debug.
Ask HN: What metaprogrammable language do you/would like to use?
61–70 of 76 posts
Re: Ask HN: What metaprogrammable language do you/would like to use?
#62> Of all the kitchen-sink features that Nim has, I can't accept camelCased == under_scored names otherwise it could have been first. Just to clarify for the general public (because this is often a source of confusion and misunderstandings): first letters are case-sensitive in Nim, so you can do `var car: Car` (where `car` is a name of the variable, and `Car` is a type). When it comes to style-insensitivity, I also th…
Re: Ask HN: What metaprogrammable language do you/would like to use?
#63I have used Nim extensively and done a lot of metaprogramming in it. The biggest risk to metaprogramming is that it allows crazy syntax that you have to learn separately. Nim does very well here to enforce limitations which work well in reducing this risk. Comparing Nim's metaprogramming to Rust's shows what I mean. In Rust you can write macros that act on token streams, so as long as the token stream is valid it can…
Re: Ask HN: What metaprogrammable language do you/would like to use?
#64> Ruby is notably absent as I use it and am looking for something better/different what issues do you have with ruby? it's the de-facto standard for meta-programming I often use things like `define_method`, `constants`, `method_missing`, etc in select places. last fun thing I did was adding `let` and `it` to rails's tests.
Re: Ask HN: What metaprogrammable language do you/would like to use?
#65I have used Nim extensively and done a lot of metaprogramming in it. The biggest risk to metaprogramming is that it allows crazy syntax that you have to learn separately. Nim does very well here to enforce limitations which work well in reducing this risk. Comparing Nim's metaprogramming to Rust's shows what I mean. In Rust you can write macros that act on token streams, so as long as the token stream is valid it can…
Please don't let adherence to stlye-insensitivity limit language adoption.
There are still plenty of people who dislike Python because "significant whitespace, bleh" with no objective reason why they dislike it except "it gets messed up when I copy the code". That's a tooling problem, just like with style insensitivity, it's not hard to search in a style insensitive manner and in fact all tools should allow this mode for convenience.
Re: Ask HN: What metaprogrammable language do you/would like to use?
#66Its quite powerful for certain types of problem domains like expert systems.
Re: Ask HN: What metaprogrammable language do you/would like to use?
#67Red's heritage comes from Lisp, Forth, and Logo. It's homoiconic and metacircular (it is its own meta language). Where Rebol was strictly interpreted, Red can also be compiled, and has hygienic macros. But you don't really need them. They're nice for moving things to compile time, but Red puts a twist on Lisp's sexpr model that obviates the "need" for them in most cases. Technically, you can say Red uses an fexpr model, but a more human-friendly way to say it is that "Everything is data until it is evaluated.", and you have a lot of control over when evaluation occurs.
For interop, Red has a system-level dialect called Red/System. It's a C level language and is a dialect of Red. That is, Red is high level and is used to define the Red/System dialect, which is used to implement Red. It's the circle of life. :^) You can also compile Red as a library and call into it via an API, so you can use it as an embedded language, or doing things like the Excel example in this blog entry about Red's macros: https://www.red-lang.org/2017/03/062-libred-and-macros.html which also mentions one of the easiest ways to preprocess input, with the `system/lexer/pre-load` feature.
ASTs are mentioned in a few comments, so I should add that while you can certainly do that with Red, it's another thing that can often be avoided entirely. With other langs and tools, you almost have to take that approach, to make it manageable. With Red, there is a function called `parse` which consumes input and supports BNF-like rules to process it. `Parse` is a Red dialect, and the rules are just data it interprets. Rather than building ASTs (though there are some cool examples, and tree-rewriting systems out there), just interpret the input directly.
If it sounds like I'm against metaprogramming, while being on a team creating a language that supports it deeply, that's not the case. Metaprogramming is a great tool for thinking, but it can also make things much harder to debug and maintain. For real work, use what makes your intent clear, and avoids as much complexity as possible.
Re: Ask HN: What metaprogrammable language do you/would like to use?
#68Considering only production code here. Do use: Common Lisp, Racket, Python, Ruby Would like to use: Julia, Rust, Elixir I metaprogram when I see I have already built a mini-language/pattern in my code. Even when writing Lisp, I begin with simple code without extending the language, and only when I have written a bit do I consider looking for patterns.
Out of curiosity, why do you have Python on your list? Python doesn’t really support metaprogramming? I’ve written my fair share of Python but don’t remember ever coming across anything meta in the language. Even if it has some passing implementation, it definitely doesn’t have it in the way Lisp/Julia/Rust/etc have it.
Yes, but then again, Rust, Julia, and Lisp are _high_ standards of metaprogramming. Python's approach to metaprogramming, like most of its other parts, is simple and concise. For simple tasks that are repeated often, Python sometimes provides easy ways to abstract the how and show only the what. While Python does have metaclasses — which, unfortunately or otherwise, I've never needed to write — I've sometimes found myself reaching for simpler tools like decorators, magic dunder methods, even iterators and generators. And, of course, there's always the ability to generate Python AST, or have something generate it for you.
Examples:
1. the new-in-3.7 feature: dataclasses[0];
2. the library that inspired it: attrs[1];
3. the (de)serialisation library with a strikingly simple design: marshmallow[2];
4. the leaky-abstraction of SQL that makes it somewhat composable: sqlalchemy[3];
5. Google's python bindings for Protocol Buffers[4]; and, of course
6. the lisp-in-Python: Hy[5];
----
[0]: https://www.python.org/dev/peps/pep-0557/
[2]: https://marshmallow.readthedocs.io/en/3.0/_modules/marshmall...
[3]: https://docs.sqlalchemy.org/en/13/orm/extensions/declarative...
[4]: https://developers.google.com/protocol-buffers/docs/pythontu...
[5]: http://docs.hylang.org/en/stable/language/internals.html
Re: Ask HN: What metaprogrammable language do you/would like to use?
#69OCaml has some metaprogramming facilities through the ppx system. It wouldn't be my first choice for metaprogramming, but it's there if you just want to know the full map of how different languages do it. I have found the ppx system a little bit underdocumented and challenging to use, but it can be very powerful. OCaml fits all of your other requirements.
Re: Ask HN: What metaprogrammable language do you/would like to use?
#70It depends a bit what you mean, but Groovy is quite interesting from a meta-programming point of view. Much of the syntax can be completely reprogrammed at run time through an object's 'metaClass', and you can write AST transformations that deeply rearrange the code at compile time. Although it is certainly not as pure as the Lisp-like languages, it can be an incredibly fast and easy way to create a DSL to solve your…