Live data from Hacker News

Ask HN: What metaprogrammable language do you/would like to use?

news.ycombinator.com

51–60 of 76 posts

Re: Ask HN: What metaprogrammable language do you/would like to use?

#51
Personally, I use Nim to develop domain specific language for VM, JIT, emulators and neural networks.

I'm currently writing a compiler for deep learning with both AOT (emitting Nim code) and hopefully later JIT (emitting LLVM IR) capabilities complete with SIMD support. I don't see how I could do that in another language.

My biggest successes:

- include a quite maintainable JIT for x86_64 (compared to asmjit and xbyak I don't need to parse or codegen the C++ code): https://github.com/numforge/laser/blob/master/laser/photon_j...

- a DSL for neural network: https://github.com/mratsim/Arraymancer#sequence-classificati...

- a matrix multiplication BLAS written from scratch competitive with OpenBLAS and MKL on select matrix shape (2000x2000) but that can also support int8/int16/int32/int64 and not just float32/float64 thanks to metaprogramming. Expanding to new SIMD architecture (ARM) is very easy:

--> benchmark: https://github.com/numforge/laser/blob/master/benchmarks/gem...

--> Metaprogramming AVX512 support: https://github.com/numforge/laser/blob/master/laser/primitiv...

The most important thing for me for metaprogramming is being able to operate on the AST directly

Re: Ask HN: What metaprogrammable language do you/would like to use?

#52

Python has way more metaprogramming capabilities than people think. Of course you can intercept pretty much anything with __dunder__methods (attribute missing, method access, instantiation, etc), you have full instrospection of pretty much anything (functions, objects, modules, call stacks...) and you also have monkey patching, decorators, metaclasses, bytecode injection... But while we are far away from Lisp based l…

The Hy language (HyLang) is a good example of this. A lisp syntax to transformed to an AST that is executed as Python is. Hy is an interesting project and a good bet if you really want to use Keras and TensorFlow in a Lisp language.

Re: Ask HN: What metaprogrammable language do you/would like to use?

#55
OCaml 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?

#56
I 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 be used. This allows libraries like the typed-html package[1].

In Nim you cannot do this unless you put the HTML in a string literal. This limitation created a syntax that is far more idiomatic, admittedly at the expense of familiarity for users of HTML:

    buildHTML():
      html():
        head():
          title: text "My webpage"
      body:
        p(class="red"): text "Hello World"
In my experience this works quite well, you can see a larger example in our Forum's code which is written using a SPA framework called Karax[2].

Please don't let style insensitivity discourage you from using this wonderful language.

1 - https://docs.rs/typed-html/0.2.0/typed_html/

2 - https://github.com/nim-lang/nimforum/blob/master/src/fronten...

Re: Ask HN: What metaprogrammable language do you/would like to use?

#57

> 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…

Absolutely! I hear this complaint a lot for people who seem to read about the language without ever trying it out. It does sound a bit crazy to begin with, but not having to write code that's a mish-mash of styles while still being able to use a library written by someone who didn't adhere to the style guide is a really nice feature.

Re: Ask HN: What metaprogrammable language do you/would like to use?

#58
You can do some nice things in Lua [1], but the one I'm most interested in at the moment is probably Terra [2]. Its concept is that it's a language like C, but uses Lua as a sort of preprocessor Language, so you can use complex macros, templates, etc. There's even a java-like class-system, if I remember correctly.

[1] https://github.com/darkwiiplayer/moonxml

[2] http://terralang.org/

Re: Ask HN: What metaprogrammable language do you/would like to use?

#60
post #5

If you're interested in functional programming and meta-programming as paradigms, then you should really focus on functional first. The reason is that functional is all about transformation of data structures as a whole (as opposed to altering them bit by bit as in procedural programming) and meta-programming is about treating programs as data and transforming them. You really can only do advanced meta-programming us…

The generation of globally fresh variables (the Lisp community uses the famous

   gensym
function for this purpose) is notoriously non-functional. Template Haskell uses a variant of the IO monad to hide the global state involved in the definition of gensym.
Post reply on HN