scicloj / wolframite

An interface between Clojure and Wolfram Language (the language of Mathematica)
https://scicloj.github.io/wolframite/
Mozilla Public License 2.0
56 stars 2 forks source link

Some symbols in wolframite.wolfram are illegal, especially those that start/end with . #90

Closed holyjak closed 2 months ago

holyjak commented 3 months ago

clj-kondo tells us that "Symbols starting or ending with dot (.) are reserved by Clojure: =." - and we have couple more, such as ..> ..= =. . .>> .>. This may cause problems sometimes - in particular, we've observed it when trying to build the site (clojure -T:build build-site).

In any case, I think we should aim to be on the save side and only use legal and unreserved symbols.

  1. [EDN] Legal symbols must satisfy: "Symbols begin with a non-numeric character and can contain alphanumeric characters and . * + ! - _ ? $ % & = < >. If -, + or . are the first character, the second character (if any) must be non-numeric. Additionally, : # are allowed as constituent characters in symbols other than as the first character. / has special meaning in symbols. ..."
  2. [Clojure] Avoid things forbidden by Clojure, namely respect "Symbols beginning or ending with '.' are reserved by Clojure" and "Symbols beginning or ending with ':' are reserved by Clojure. A symbol can contain one or more non-repeating ':'s." Notice that Clojure Reader's docs are more strict then EDN, and only allow *, +, !, -, _, ', ?, <, > and =, commenting that "other characters may be allowed eventually". (It must compile fn names containing these into class names, which are much more limited; currently, it does solve that by replacing some characters with safer forms, e.g. = -> _EQ_ .) I believe that in practice it accepts everything EDN does (minus reserved cases) so we could follow the richer EDN spec and hope for the best. Though it may be better to do that as little as possible and prefer to stick to the smaller clojure set. (Notice that . and $ have special meaning in Java class names, compiled from clj fns; but perhaps clj is smart enough to replace them??; though our curren problem with ._EQ_ demonstrates that dots, contrary to =, are not replaced...)
light-matters commented 3 months ago

Thanks for working on this. The symbol restrictions are a pain; particularly because part of the tutorial is singing the praises of Clojure for being more permissive than Wolfram! I'll need to think about replacing these symbols. I guess the official aliases should try to avoid as many errors as possible.

light-matters commented 3 months ago

There's something not quite right about that list as datomic uses '$'s all over the place from what I understand. There is a wider problem though.

What about (roughly speaking) using '_' instead of ':' and '<*>' for Dot (because <x|y> is actually another way of writing the inner product of x and y and '*' has connotations of 'product'? It's very annoying that it seems like '|' is being reserved for something else in the future.

So, my take is to use

   _=  SetDelayed
   =!   Unset
   _>  RuleDelayed
   <*>    Dot

'officially' for the moment and I'll use

    x> Replace
    x>> ReplaceAll
    <_> Expand
    <<_>> ExpandAll
    ++<_> ComplexExpand
    >_< Simplify
    >>_<< FullSimplify

as my examples of extending the aliases. I actually like using '_' as a placeholder symbol: it's apt. I'll update the tutorial and commit.

Edit: I noticed by '*'s were being hidden in the display.

holyjak commented 3 months ago

That sounds good, thank you!

holyjak commented 3 months ago

@light-matters this is now fixed, no?

light-matters commented 2 months ago

@holyjak Yep, I think so.