Skip to content

Commit

Permalink
Shell highlighting, MD Table support, Crash Course Tables converted a…
Browse files Browse the repository at this point in the history
…nd improvments
  • Loading branch information
eksperimental committed Feb 6, 2015
1 parent 51aab10 commit b0248e8
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 159 deletions.
24 changes: 14 additions & 10 deletions README.md
Expand Up @@ -4,7 +4,7 @@ It is automatically transformed by [Jekyll](http://github.com/mojombo/jekyll) in

### Contributing to the blog

Create a new file inside `_posts/YYYY-MM-DD-post-title.markdown` following the template:
Create a new file inside `_posts/YYYY-MM-DD-post-title.markdown` following the template:

---
layout: post
Expand All @@ -16,24 +16,28 @@ It is automatically transformed by [Jekyll](http://github.com/mojombo/jekyll) in

Body text goes here...

Or use `_bin/newpost` to bootstrap a new post file:
Or use `_bin/newpost` to bootstrap a new post file:

export EDITOR=vim; _bin/newpost 'Post title'
```bash
export EDITOR=vim; _bin/newpost 'Post title'
```

### Contributing improvements or bug fixes

1. Fork elixir-lang.github.com
1. [Fork elixir-lang.github.com](https://github.com/elixir-lang/elixir-lang.github.com/fork).

2. Make your changes
2. Make your changes.

3. Test it locally, you need to install the gems `jekyll` and `redcarpet`:

```shell
$ gem install jekyll redcarpet
$ jekyll serve # check localhost:4000
```
```bash
$ gem install jekyll redcarpet
$ jekyll serve # check localhost:4000
```

4. Send a pull-request for your changes
4. Push to your forked repository.

5. Submit a pull-request for your changes.

`jekyll` requires a javascript processor to be available too. Many OS provide such functionality but others do not. If you have an error related to ExecJS, you can work around it by either running `gem install therubyracer` or by ensuring node.js is available in your path.

Expand Down
2 changes: 1 addition & 1 deletion _config.yml
Expand Up @@ -2,6 +2,6 @@ markdown: redcarpet
highlighter: pygments
permalink: /blog/:year/:month/:day/:title/
redcarpet:
extensions: ['with_toc_data']
extensions: ['with_toc_data', 'tables']
gems:
- jekyll-redirect-from
2 changes: 1 addition & 1 deletion _includes/bottom.html
Expand Up @@ -3,7 +3,7 @@
<div class="clear"></div>

<div id="copyright">
&copy; 2012-2014 <a href="http://plataformatec.com.br/">Plataformatec</a>. All rights reserved.
&copy; 2012-2015 <a href="http://plataformatec.com.br/">Plataformatec</a>. All rights reserved.
</div>
</div><!-- .wrap -->
</div><!-- #container -->
Expand Down
4 changes: 3 additions & 1 deletion _posts/2013-05-23-elixir-v0-9-0-released.markdown
Expand Up @@ -36,7 +36,9 @@ As a project grows, it is recommended to break it apart into smaller, isolated a

Elixir v0.9.0 now supports umbrella projects which can work with many applications at the same time. You can create a new umbrella project with:

$ mix new my_project --umbrella
```bash
$ mix new my_project --umbrella
```

The generated project will have the following structure:

Expand Down
2 changes: 1 addition & 1 deletion _posts/2014-04-21-elixir-v0-13-0-released.markdown
Expand Up @@ -241,7 +241,7 @@ The last big change we want to discuss in this release are the improvements done

In previous releases, Mix was used to download and compile dependencies per environment. That meant the usual workflow was less than ideal: every time a dependency was updated, developers had to explicitly fetch and compile the dependencies for each environment. The workflow would be something like:

```
```bash
$ mix deps.get
$ mix compile
$ MIX_ENV=test mix deps.get
Expand Down
79 changes: 31 additions & 48 deletions crash-course.markdown
Expand Up @@ -8,20 +8,10 @@ layout: default

This is a quick introduction to the Elixir syntax for Erlang developers and vice-versa. It is the absolute minimum amount of knowledge you need in order to understand Elixir/Erlang code, support interoperability, read the docs, sample code, etc.

This page is divided into sections:
<div class="toc"></div>

1. [Running Code](#running_code)
2. [Notable Differences](#notable_differences)
3. [Data Types](#data_types)
4. [Modules](#modules)
5. [Function Syntax](#function_syntax)
6. [Control Flow](#control_flow)
7. [Adding Elixir to existing Erlang programs](#interop)
8. [Further reading](#further_reading)

<div id="running_code"></div>

## 1 Running Code
## Running code

### Erlang

Expand Down Expand Up @@ -82,26 +72,25 @@ defmodule MyModule do
end
```

<div id="notable_differences"></div>

## 2 Notable Differences
## Notable differences

This section goes over some of the syntactic differences between the two languages.

### Operator Names
### Operator names

Some operators are spelled differently.

| Erlang | Elixir | Meaning |
-----------------------------------------------------------------------------
| and | NOT AVAILABLE | Logical 'and', evaluates both arguments |
| andalso | and | Logical 'and', short-circuits |
| or | NOT AVAILABLE | Logical 'or', evaluates both arguments |
| orelse | or | Logical 'or', short-circuits |
| =:= | === | A match operator |
| =/= | !== | A negative match |
| /= | != | Not equals |
| =< | <= | Less than or equals |
| Erlang | Elixir | Meaning |
|----------------|----------------|-----------------------------------------|
| and | NOT AVAILABLE | Logical 'and', evaluates both arguments |
| andalso | and | Logical 'and', short-circuits |
| or | NOT AVAILABLE | Logical 'or', evaluates both arguments |
| orelse | or | Logical 'or', short-circuits |
| =:= | === | A match operator |
| =/= | !== | A negative match |
| /= | != | Not equals |
| =< | <= | Less than or equals |


### Delimiters
Expand All @@ -122,7 +111,7 @@ x = 2; y = 3
x + y
```

### Variable Names
### Variable names

Variables in Erlang can only be assigned once. The Erlang shell provides a special command `f` that allows you to erase the binding of a variable or all variables at once.

Expand Down Expand Up @@ -161,14 +150,14 @@ iex> ^a = 3
** (MatchError) no match of right hand side value: 3
```

### Calling Functions
### Calling functions

Elixir allows you to omit parentheses in function calls, Erlang does not.

| Erlang | Elixir |
--------------------------------------
| some_function(). | some_function |
| sum(A, B) | sum a, b |
| Erlang | Elixir |
|-------------------|----------------|
| some_function(). | some_function |
| sum(A, B) | sum a, b |

Invoking a function from a module uses different syntax. In Erlang, you would write

Expand All @@ -190,9 +179,8 @@ Kernel.self

All of the Erlang built-ins reside in the `:erlang` module.

<div id="data_types"></div>

## 3 Data Types
## Data types

Erlang and Elixir have the same data types for the most part, but there are a number of differences.

Expand Down Expand Up @@ -264,7 +252,7 @@ elem({ :a, :b, :c }, 0) #=> :a
put_elem({ :a, :b, :c }, 0, :d) #=> { :d, :b, :c }
```

### Lists and Binaries
### Lists and binaries

Elixir has a shortcut syntax for binaries:

Expand Down Expand Up @@ -374,9 +362,8 @@ lines.
"""
```

<div id="modules"></div>

## 4 Modules
## Modules

Each Erlang module lives in its own file which has the following structure:

Expand Down Expand Up @@ -452,15 +439,14 @@ HelloModule.Utils.priv
#=> ** (UndefinedFunctionError) undefined function: HelloModule.Utils.priv/0
```

<div id="function_syntax"></div>

## 5 Function Syntax
## Function syntax

[This chapter][3] from the Erlang book provides a detailed description of pattern matching and function syntax in Erlang. Here, I'm briefly covering the main points and provide sample code both in Erlang and Elixir.

[3]: http://learnyousomeerlang.com/syntax-in-functions

### Pattern Matching
### Pattern matching

Pattern matching in Elixir is based on Erlang's implementation and in general is very similar:

Expand Down Expand Up @@ -574,7 +560,7 @@ mul_by 4, 3 #=> 12
mul_by 4 #=> 8
```

### Anonymous Functions
### Anonymous functions

Anonymous functions are defined in the following way:

Expand Down Expand Up @@ -637,7 +623,7 @@ f.({:a, :b})
#=> "All your {:a,:b} are belong to us"
```

### First-Class Functions
### First-class functions

Anonymous functions are first-class values, so they can be passed as arguments to other functions and also can serve as a return value. There is a special syntax to allow named functions be treated in the same manner.

Expand Down Expand Up @@ -692,9 +678,8 @@ Enum.map [1,2,3], &Math.square/1
#=> [1, 4, 9]
```

<div id="control_flow"></div>

## 6 Control Flow
## Control flow

The constructs `if` and `case` are actually expressions in both Erlang and Elixir, but may be used for control flow as in imperative languages.

Expand Down Expand Up @@ -791,7 +776,7 @@ else
end
```

### Sending and Receiving Messages
### Sending and receiving messages

The syntax for sending and receiving differs only slightly between Erlang and Elixir.

Expand Down Expand Up @@ -825,9 +810,8 @@ after
end
```

<div id="interop"></div>

## 7 Adding Elixir to existing Erlang programs
## Adding Elixir to existing Erlang programs

Elixir compiles into BEAM byte code (via Erlang Abstract Format). This means that Elixir code can be called from Erlang and vice versa, without the need to write any bindings. All Elixir modules start with the `Elixir.` prefix followed by the regular Elixir name. For example, here is how to use the utf-8 aware `String` downcase from Elixir in Erlang:

Expand Down Expand Up @@ -859,9 +843,8 @@ This should be enough to invoke Elixir functions straight from your Erlang code.

If you are not using rebar, the easiest approach to use Elixir in your existing Erlang software is to install Elixir using one of the different ways specified in the [Getting Started guide](/getting-started/introduction.html) and add the `lib` directory in your checkout to `ERL_LIBS`.

<div id="further_reading"></div>

## 8 Further Reading
## Further reading

Erlang's official documentation site has a nice [collection][4] of programming examples. It can be a good exercise to translate them into Elixir. [Erlang cookbook][5] offers even more useful code examples.

Expand Down
27 changes: 27 additions & 0 deletions css/style.css
Expand Up @@ -161,6 +161,15 @@ ol ol ol { list-style: lower-roman }
ol ol ol ol { list-style: upper-alpha }
ol ol ol ol ol { list-style: lower-alpha }
ul ul, ol ol, ul ol, ol ul { margin-bottom:0 }

.toc ol { counter-reset: item; }
.toc ol li { display: block }
.toc ol li:before {
content: counters(item, ".") " ";
counter-increment: item;
}


dl { margin: 0 0 1.692307em 5px }
dt {
font-weight: bold;
Expand Down Expand Up @@ -305,6 +314,24 @@ td {
border-bottom: 1px solid #e7e7e7;
}

#content table {
margin-left: 1.692307em;
width: auto;
width: 85%;
}
#content table caption { color: #555; }
#content table th {
font-weight: bold;
padding: 10px 4%;
border-bottom: 3px solid #E6DFD5;
background-color:#FFFAF3;
}
#content td {
padding: 0.8125em 4%;
border-bottom: 1px solid #E6DFD5;
background-color:#FFFAF3;
}

/* Lists
-------------------------------------------------------------- */
ul li, ol li { line-height: 2.1em; }
Expand Down
4 changes: 3 additions & 1 deletion getting-started/meta/macros.markdown
Expand Up @@ -34,7 +34,9 @@ The function receives the arguments and passes them to `if`. However, as we lear

Let's start `iex` with the module above:

$ iex macros.exs
```bash
$ iex macros.exs
```

And play with those definitions:

Expand Down
4 changes: 3 additions & 1 deletion getting-started/mix-otp/agent.markdown
Expand Up @@ -32,7 +32,9 @@ We will explore all of these abstractions in this guide. Keep in mind that they

[Agents](/docs/stable/elixir/Agent.html) are simple wrappers around state. If all you want from a process is to keep state, agents are a great fit. Let's start an `iex` session inside the project with:

$ iex -S mix
```bash
$ iex -S mix
```

And play a bit with agents:

Expand Down

0 comments on commit b0248e8

Please sign in to comment.