Chapter 1: Getting Started

Where you will learn how to set up a development environment for Lux.


Before any coding can happen, it is necessary to set-up everything you need to become a productive Lux programmer.

Question #1: How do I write Lux code?

Text editor support is a fundamental thing for any language, and Lux already covers some of that. The catch is that there's only support for Emacs at the moment.

The plugin is called lux-mode, and you can obtain it from this website: https://github.com/LuxLang/lux/tree/master/lux-mode.

The instructions for how to install it are at the link and it won't take much time.

Question #2: How do I build Lux programs?

Currently, Lux doesn't have a build tool of its own.

Instead, we're going to piggy-back on Leiningen, a build tool originally meant for Clojure, but that can be customized for our purposes.

Note #1: For the moment, you'll have to use Leiningen 2.7.1 instead of later versions, due to backwards incompatible changes in the latest Leiningen releases.

Note #2: Lux has not yet been updated to work with the latest versions of Java, so you'll need to have Java 8 installed on your machine to use it.

Question #3: How do I use Leiningen for Lux?

To find out, let's create a sample project that will have everything we need.

These are the steps:

  1. Create a directory called my_project.
  2. Create a new project file at my_project/project.clj.
  3. Add this to the project file:

    (defproject my_project "0.1.0-SNAPSHOT"
      :plugins [[com.github.luxlang/lein-luxc "0.5.0"]]
      :dependencies []
      :lux {:program "main"}
      :source-paths ["source"]
     )
    

    This will fetch the Lux plugin for Leiningen, alongside the Lux standard library.

    It also tells the plugin that we'll be using the my_project/source directory for our source code, instead of Leiningen's default src directory.

    The file containing our program will be my_project/source/main.lux.

  4. Create source/main.lux and add this code to it:

    (;module: {#;doc "This will be our program's main module."}
      lux
      (lux (codata io)
           [cli #+ program:]))
    
    (program: args
      (io (log! "Hello, world!")))
    

    As you can see, this is nothing more than a very simple "Hello, world!" program to test things out.

    Everything will be explained later in the rest of the book.

  5. In your terminal, go to my_project, and execute lein lux build.
    When it's done, you should see a message like this:

    ...
    Compilation complete!
    "Elapsed time: 13022.487488 msecs"
    [COMPILATION END]
    

    A directory named target will have been created, containing everything that was compiled, alongside an executable JAR file.

  6. Run the program with this: java -jar target/jvm/program.jar

  7. Smile :)

Question #4: Where can I find documentation for Lux?

A specially useful source of information is the documentation for the standard library.

You can also explore the Lux repository on GitHub for more information.

Question #5: Bro, do you even REPL?

REPL support for Lux is still work in progress, but you can play around with it.

There is the lein lux repl command, but for reasons I can't explain right now, that won't actually run the REPL, but instead it will spit out a command that will run it for you.

If you just want to run the REPL, you can get the job done with this command:

eval "$(lein lux repl)"

You can play with it for a while and type exit when you're done.

Question #6: Where do I talk about Lux?

The place to talk about Lux is at the Lux forum.


We can proceed to the actual teaching of the language!

See you in the next chapter!

results matching ""

    No results matching ""