~cloutier/principia

Free and open source implementation of the Wolfram language.

bcfb6fa Converted parsing from String to &str

1 year, 2 months ago

c39f613 work on SocketOpen

1 year, 5 months ago

#principia

Free and open source implementation of the Wolfram language.

builds.sr.ht status

#Exemples

Take[TextWords[ WikipediaData["Moon"] ], 8]

will yield {"The", "Moon", "is", "an", "astronomical", "body", "orbiting", "Earth"}.

EntityValue[
        LanguageIdentify["Oh, comme ce language est beau!"],
        EntityProperty["Language", "Codes"]
]

will yield {"fr"}.

#How to contribute

#Write Wolfram code

We thrive to implement Principia with as much Wolfram code as possible, because it makes maintaining the code base so much easier. Wolfram code is 10x smaller than the equivalent Rust code, which at the scale we hope to acheive with the whole language implemented, is going to make a huge difference in lines of code. It also allows us to make deep refactoring of the core of the interpreter without having to touch any of the Wolfram code.

Implementing in Wolfram is perfect for sugar such as First:

First[l_List] = Part[l, 1]

Implementing in Wolfram is also perfect for IO bound functions, such as the ones getting Entity information from Wikidata.

#Data sources

We need free (as in beer and speech) data sources that are also reliable to implement some functions. Here are some data sources that we use:

  • Wikidata (for all the Entity functions currently)
  • OpenStreetMaps
  • Ethereum (for all FinancialData currently)

#Write Rust code

If for some reason you can't write in Wolfram the function that you want, you can write it in src/builtin.rs .

Each item in the list of native Rust fonction as a lambda called should_evalutate, that if it returns true, will use the other lambda to evaluate the tree.

If you have a Rust library ready to use, writing in Rust is great. Look at LanguageIdentify for an exemple of that.

If you have to do native interop, you have to use Rust. Look at URLRead for an exemple.

When in doubt, write your code in Wolfram.

#General wrangling

There are many other important area in the interpreter, but those are much less recommended as a first contribution, as they require a deep understanding of the code base.

We do parsing in src/parse.rs using Nom.

We have the core eval loop in src/eval.rs.

We have various utility functions to transforms evaluation trees in differents ways in src/ast.rs

#Using it

#As a scripting language

Clone this repo and install it. You will need rustup.

cargo install
mv ~/.cargo/bin/principia /usr/local/bin/

#Emacs' Org-mode

Do the steps above and add this to your .emacs:

(defun org-babel-execute:wolfram (body params)
  "Execute a block of wolfram code with org-babel."
  (message "executing Wolfram source code block")
  (org-babel-eval "principia" body))

#Licence

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.