Hi Ivan.
I'll try to explain one thing, which will probably explain most of your questions.
Joxa is an extremely small language (which is one of its greatest strengths IMO). There are only very few special forms. They are documented here:
http://docs.joxa.org/en/latest/language.html. Note that even basic math operators are not built into the language. That means that in order to do something useful, you have to use functions that come along with Joxa's standard library (
http://docs.joxa.org/en/latest/standard-library.html) or with the Erlang distributions, or use whatever Erlang library you need. So, how can you use those?
Quite central to Joxa is the concept of namespaces. At runtime, any Joxa code is executed in some namespace. For example, when you start the Joxa shell, the default namespace is `joxa-is`. You can declare a new namespace with
(ns some-namespace-name). Erlang modules are treated as namespaces, i.e., the namespace name is equal to the module name name, however you can change those before using them, e.g. like this:
(require (error_logger :as logger)). In order to use functions from other namespaces you have to either use the `require` or the `use` special form. With e.g.
(require some-namespace) you just declare that you are going to invoke functions from `some-namespace`, whereas with e.g.
(use some-namespace) you import every exported functions function from `some-namespace` into your own current namespace.
Below are my quick answers to your questions.
> Two about the shell:
>
> 1. What is the correct way to quit from the shell? I have only found ctrl-c and ctrl-d.
You can use Erlang's `halt/0` function:
(use erlang)
(halt)or even shorter, Erlang's `q/0` function.
(use c)
(q)
> 2. Is there a way to (re-)compile and (re-)load a joxa file from the shell?
Hah, that question was actually a bit tricky. AFAIK there's no equivalent to Eralng's `c/1` function, which allows you to compile and reload a file from the shell. However you could use the reloader module from mochiweb:
https://github.com/mochi/mochiweb/blob/master/src/reloader.erlSupposed that you have the compiled reloader beam-file (it can be compiled with `erlc reloader.erl` from the shell) in your current directory and the compiled Joxa distribution in some other directory (e.g. '~/dev/joxa'), you can start the Joxa shell by first invoking the Erlang shell like this:
erl -pa ~/dev/joxa/ebin ~/dev/joxa/deps/*/ebin -s reloaderThen enter the following in order to actually start the Joxa shell:
'joxa-shell':start().Now the reloader will reload any Joxa or Erlang module in your current directory as soon as you have successfully compiled it. Btw., if you want this not only for your current directory but for another one as well, just add it to the '-pa' option when invoking `erl`. For example if you'd like to add the directory 'src', it'd look like this:
erl -pa ~/dev/joxa/ebin ~/dev/joxa/deps/*/ebin src -s reloader
> Two about the language:
>
> 3. Are car, cdr and cons defined in joxa?
Nope. However, there are equivalent `hd/1` and `tl/1` functions in joxa-lists. As Joxa has macros, it only takes a few lines of code to provide your version of `hd/1` and `tl/1` called `car/1` and `cdr/1`:
(ns my-joxa-lists
(require joxa-lists))
(defmacro+ car (l)
`(joxa-lists/hd ~l))
(defmacro+ cdr (l)
`(joxa-lists/tl ~l))
> 4. Is there a way to quote arbitrary stuff? On p. 4 of The Little Schemer there's a question:
>
> Is it true that this is a list?
>
> (atom turkey) or
Of course. Just like in most other Lisps, there's the special form `quote`. So, instead of
(atom turkey) you simply write
(quote turkey). There's are also two different syntaxes that can be used equivalently: `'turkey` and `:turkey`. In Joxa it's kind of a convention to use the quote symbol for lists, e.g.
'(foo bar baz), while the colon symbol is usually used for single atoms, e.g.
:turkey.
> If I've defined an is_list function (using erlang's is_list), is there a way to express that question in joxa?
>
> (is_list ...?
Of course, why not? You want a predicate function with a question mark? Nothing prevents you from creating e.g. a two-line macro like this:
(ns my-joxa-lists
(require erlang))
(defmacro+ list? (l)
`(erlang/is_list ~l))
> One last question about my setup:
>
> 5. I think I might have missed/messed something. The joxa documentation has examples like:
>
> joxa-is> (joxa-core/!= 1 2)
> :true
>
> joxa-is> (joxa-core/!= 1 1)
> :false
>
> But in my shell I get:
>
> joxa-is> (joxa-core/!= 1 2)
> :0:0 *error* invalid reference joxa-core/!=/2
> error
>
> joxa-is> (joxa-core/!= 1 1)
> :0:0 *error* invalid reference joxa-core/!=/2
> error
(require joxa-core) ;)
> Any help on any of the above much appreciated. When I finish chapter one, I'll write a blog post :D
Cool. Please tell us here when you've done so!
Cheers,
Klaus