April 20, 2014

Developed by Robbie Lynch

Supervised by Paul Barry

Institute of Technology, Carlow, Ireland.


Download

Download the IErlang Kernel for IPython at http://github.com/robbielynch/ierlang


Data Types

In [1]:
AnInt = 1234.
Out[1]:
1234
In [2]:
AFloat = 55 / 3.
Out[2]:
18.333333333333332
In [3]:
AString = "Awesome!".
Out[3]:
"Awesome!"
In [4]:
AnAtom = 'This is an atom with spaces'.
Out[4]:
'This is an atom with spaces'
In [5]:
atom_with_no_spaces.
Out[5]:
atom_with_no_spaces
In [6]:
{this, is, a, tuple_of_atoms}.
Out[6]:
{this,is,a,tuple_of_atoms}
In [7]:
AList = [1,2,3,4,5].
Out[7]:
[1,2,3,4,5]

Variable Bindings

i.e. Referring to previously assigned variables.

In [8]:
AVariable = 100.
Out[8]:
100
In [9]:
AnotherVar = 77.
Out[9]:
77
In [10]:
AVariable + AnotherVar.
Out[10]:
177
In [11]:
NedStark = [[]|[AnotherVar + AVariable]].
Out[11]:
[[],177]
In [12]:
NedStark.
Out[12]:
[[],177]

Built in Functions

In [13]:
lists:sort([10,9,8,3,5,4,6,1,7,2]).
Out[13]:
[1,2,3,4,5,6,7,8,9,10]
In [14]:
io:format("hello").
Out[14]:
ok
In [15]:
is_integer(4325345).
Out[15]:
true
In [16]:
os:cmd("pwd").
Out[16]:
"/home/robbie/dev/ierlang/src
"
In [17]:
is_binary(<<"Hello">>).
Out[17]:
true

Expressions

In [18]:
9283479238472398472398472394872398 * 28347632847623847623847623847623847623847632874623864.
Out[18]:
263164661000754185502995313263072243291280523500406936157710040110469708162166525705872
In [19]:
99 div 5. %%Integer division
Out[19]:
19
In [20]:
99 / 5.
Out[20]:
19.8
In [21]:
893475 - 98234798432579348753.
Out[21]:
-98234798432578455278

Errors

In [22]:
this will throw an error
Out[22]:
{badmatch,{error,{1,erl_parse,["syntax error before: ","will"]}}}
In [23]:
lists:flatten(notalist).
Out[23]:
function_clause
In [24]:
55 div 44.3.
Out[24]:
badarith

Terminal Commands

To make interacion with the terminal quicker and easier, you can run terminal commands

by pre-pending ;; before the command. For example:

In [25]:
;;pwd
Out[25]:
"/home/robbie/dev/ierlang/src
"
In [26]:
;;date
Out[26]:
"Sun Apr 20 16:56:04 BST 2014
"
In [27]:
;;whereis ipython
Out[27]:
"ipython: /usr/bin/ipython2.7 /usr/bin/X11/ipython2.7 /usr/local/bin/ipython /usr/share/man/man1/ipython.1.gz
"
In [28]:
;;ping -c 5 google.com
Out[28]:
"PING google.com (74.125.24.101) 56(84) bytes of data.
64 bytes from de-in-f101.1e100.net (74.125.24.101): icmp_req=1 ttl=44 time=60.0 ms
64 bytes from de-in-f101.1e100.net (74.125.24.101): icmp_req=2 ttl=44 time=68.5 ms
64 bytes from de-in-f101.1e100.net (74.125.24.101): icmp_req=3 ttl=44 time=47.4 ms
64 bytes from de-in-f101.1e100.net (74.125.24.101): icmp_req=4 ttl=44 time=67.1 ms
64 bytes from de-in-f101.1e100.net (74.125.24.101): icmp_req=5 ttl=44 time=45.8 ms

--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4004ms
rtt min/avg/max/mdev = 45.816/57.810/68.506/9.563 ms
"
In [29]:
;;ls mochi*
Out[29]:
"mochijson2.beam
mochijson2.erl
mochinum.beam
mochinum.erl
"

We can even compile erlang via the terminal commands

In [30]:
;;erlc mochijson2.erl
Out[30]:
[]

It's possible to start the original IPython Notebook with the command

;;ipython notebook

Although, it does kill our kernel :(

Modules

We can create, save and compile erlang modules

And if we deliberatly leave an error on line 4... it will tell us....

In [31]:
-module(super_awesome_module). %%First line must begin with -module().
-export([my_favorite_numbers/0, unlucky_number/0]).

my_favorite_numbers()- %%<---------------------This is where the error is%%
[1, 2, 3, 4, 5].

unlucky_number()->
((278346287 * 98324928374) - (829437 * 3476) - (27368378729560724309 + (2 * 2))).
Out[31]:
super_awesome_module.erl:4: syntax error before: '-'
super_awesome_module.erl:2: function my_favorite_numbers/0 undefined

It also tells us when things work...

In [32]:
-module(super_awesome_module). %%First line must begin with -module().
-export([my_favorite_numbers/0, unlucky_number/0]).

my_favorite_numbers()->
[1, 2, 3, 4, 5].

unlucky_number()->
((278346287 * 98324928374) - (829437 * 3476) - (27368378729560724309 + (2 * 2))).
Out[32]:
Successfully Compiled

Now for the cool part

We can reference the exported functions from our compiled modules

In [33]:
super_awesome_module:my_favorite_numbers().
Out[33]:
[1,2,3,4,5]
In [34]:
lists:reverse(super_awesome_module:my_favorite_numbers()).
Out[34]:
[5,4,3,2,1]
In [35]:
super_awesome_module:unlucky_number().
Out[35]:
13
In [36]:
MyPid = spawn(super_awesome_module, unlucky_number, []).
Out[36]:
<0.49.0>
In [37]:
MyPid.
Out[37]:
<0.49.0>

Some Problems

as of April 16, 2014

  • Encoding tuples inside other data structures
  • Encoding floats inside other data structures
  • ERROR MESSAGES - They do not appear (Something to do with pyerr on ierlang side)
  • Cannot create notebooks outside ierlang/src directory
  • Horrible installation and setup
  • Having to edit the IPython code in order to parse erlang strings (lists of ints)
    • Note that the editing of the IPython code does not affect the normal IPython in any way.
  • No Variable bindings (yet)
  • Tuples are converted to lists when encoding
  • Project structure - it's a mess
  • Not handling all of IPython's messages (yet)

Thanks for the help

Find me on Twitter