Hacker News new | ask | show | jobs
by martinsmit 991 days ago
The lack of an AD primitive is something I've discussed with the creator of BQN, coming from a JAX world I really miss it and feel that it's such an obvious feature, especially in a language which has a way to turn a tacit function into its AST[1], which has been used for symbolic differentiation[2]. Going from symbolic to reverse-mode AD is not much of a leap and users can define their own primitives with ReBQN[3].

I see what you mean by obfuscation, but I think that it's one of those things that feels really hard and stupid until you start being able to do it really quickly. When you learn a foreign language, you first read letters, then words, then sentences because you become accustomed to larger pieces of the language that you can predict what's coming next without reading it. A similar sort of thing happens with APL/BQN, you read letters (primitives), then you begin to recognise words (small, commonly used groups of primitives), then you see larger patterns which look like magical incantations to an inexperienced user.

These "words" are (typically) tacit phrases, many of them only existing due to specific primitives like swap. Once I used BQN to golf, I started wishing Julia had a swap for operators i.e.

  -(3, 5) = -2
  swap(-)(3, 5) = 2
I won't defend these languages to the death, but they are fun to puzzle your brain with in codegolf. Maybe Dex[4] will go somewhere too.

[1]: https://mlochbaum.github.io/BQN/spec/system.html#operation-p...

[2]: https://saltysylvi.github.io/blog/bqn-macros.html

[3]: https://mlochbaum.github.io/BQN/doc/rebqn.html

[4]: https://github.com/google-research/dex-lang

2 comments

> I started wishing Julia had a swap for operators

You can define one pretty easily:

    julia> swap2(f::F) where F<:Function = (a, b) -> f(b, a)
    swap2 (generic function with 1 method)

    julia> swap2(-)(3, 5)
    2
(Perhaps you meant you wished it was pre-defined with the language, I understand the slight friction of having to define things for every project; this is just making sure you know it can be done pretty easily.)
You might be interested in UIua, a stack-based concatenative array language inspired by BQN and others: https://www.uiua.org/
How do you start to learn a language like this? Are there any good resources for example leetcode-type problems to solve with Uiua?
Oh trust me, I am. The new code_report solution video on it convinced me to try it.