Add elixir step0
authorekmartin <mail@ekmartin.no>
Fri, 28 Aug 2015 22:15:46 +0000 (00:15 +0200)
committerekmartin <mail@ekmartin.no>
Wed, 2 Sep 2015 22:08:25 +0000 (00:08 +0200)
.gitignore
Makefile
elixir/config/config.exs [new file with mode: 0644]
elixir/lib/mal.ex [new file with mode: 0644]
elixir/lib/mix/tasks/step0_repl.ex [new file with mode: 0644]
elixir/mix.exs [new file with mode: 0644]
elixir/step0_repl.ex [new file with mode: 0644]

index 66fa371..7e334f9 100644 (file)
@@ -60,3 +60,8 @@ nim/nimcache
 groovy/*.class
 .crystal
 es6/build
+elixir/_build
+elixir/deps
+elixir/erl_crash.dump
+elixir/*.ez
+
index d46faf7..ec125c3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ PYTHON = python
 # Settings
 #
 
-IMPLS = awk bash c clojure coffee cpp crystal cs erlang es6 factor forth fsharp go groovy \
+IMPLS = awk bash c clojure coffee cpp crystal cs erlang elixir es6 factor forth fsharp go groovy \
        haskell java julia js lua make mal ocaml matlab miniMAL nim \
        perl php ps python r racket rpython ruby rust scala swift vb guile
 
@@ -63,6 +63,7 @@ coffee_STEP_TO_PROG =  coffee/$($(1)).coffee
 cpp_STEP_TO_PROG =     cpp/$($(1))
 crystal_STEP_TO_PROG = crystal/$($(1))
 cs_STEP_TO_PROG =      cs/$($(1)).exe
+elixir_STEP_TO_PROG =  elixir/lib/mix/tasks/$($(1)).ex
 erlang_STEP_TO_PROG =  erlang/$($(1))
 es6_STEP_TO_PROG =     es6/build/$($(1)).js
 factor_STEP_TO_PROG =  factor/src/$($(1))/$($(1)).factor
@@ -109,6 +110,7 @@ coffee_RUNSTEP =  coffee ../$(2) $(3)
 cpp_RUNSTEP =     ../$(2) $(3)
 crystal_RUNSTEP = ../$(2) $(3)
 cs_RUNSTEP =      mono ../$(2) --raw $(3)
+elixir_RUNSTEP =  mix $($(1))
 erlang_RUNSTEP =  ../$(2) $(3)
 es6_RUNSTEP =     node ../$(2) $(3)
 factor_RUNSTEP =  factor ../$(2) $(3)
diff --git a/elixir/config/config.exs b/elixir/config/config.exs
new file mode 100644 (file)
index 0000000..6dfa82f
--- /dev/null
@@ -0,0 +1,24 @@
+# This file is responsible for configuring your application
+# and its dependencies with the aid of the Mix.Config module.
+use Mix.Config
+
+# This configuration is loaded before any dependency and is restricted
+# to this project. If another project depends on this project, this
+# file won't be loaded nor affect the parent project. For this reason,
+# if you want to provide default values for your application for third-
+# party users, it should be done in your mix.exs file.
+
+# Sample configuration:
+#
+#     config :logger, :console,
+#       level: :info,
+#       format: "$date $time [$level] $metadata$message\n",
+#       metadata: [:user_id]
+
+# It is also possible to import configuration files, relative to this
+# directory. For example, you can emulate configuration per environment
+# by uncommenting the line below and defining dev.exs, test.exs and such.
+# Configuration from the imported file will override the ones defined
+# here (which is why it is important to import them last).
+#
+#     import_config "#{Mix.env}.exs"
diff --git a/elixir/lib/mal.ex b/elixir/lib/mal.ex
new file mode 100644 (file)
index 0000000..5ad079b
--- /dev/null
@@ -0,0 +1,2 @@
+defmodule Mal do
+end
diff --git a/elixir/lib/mix/tasks/step0_repl.ex b/elixir/lib/mix/tasks/step0_repl.ex
new file mode 100644 (file)
index 0000000..7c26269
--- /dev/null
@@ -0,0 +1,34 @@
+defmodule Mix.Tasks.Step0Repl do
+  def run(_), do: main
+
+  def main do
+    IO.write(:stdio, "user> ")
+    IO.read(:stdio, :line)
+      |> handle_line
+
+    main
+  end
+
+  defp handle_line(:eof), do: exit(0)
+  defp handle_line(line) do
+    IO.write(:stdio, read_eval_print(line))
+  end
+
+  def read(input) do
+    input
+  end
+
+  def eval(input) do
+    input
+  end
+
+  def print(input) do
+    input
+  end
+
+  def read_eval_print(line) do
+    read(line)
+      |> eval
+      |> print
+  end
+end
diff --git a/elixir/mix.exs b/elixir/mix.exs
new file mode 100644 (file)
index 0000000..9a10b87
--- /dev/null
@@ -0,0 +1,32 @@
+defmodule Mal.Mixfile do
+  use Mix.Project
+
+  def project do
+    [app: :mal,
+     version: "0.0.1",
+     elixir: "~> 1.0",
+     build_embedded: Mix.env == :prod,
+     start_permanent: Mix.env == :prod,
+     deps: deps]
+  end
+
+  # Configuration for the OTP application
+  #
+  # Type `mix help compile.app` for more information
+  def application do
+    [applications: [:logger]]
+  end
+
+  # Dependencies can be Hex packages:
+  #
+  #   {:mydep, "~> 0.3.0"}
+  #
+  # Or git/path repositories:
+  #
+  #   {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
+  #
+  # Type `mix help deps` for more examples and options
+  defp deps do
+    []
+  end
+end
diff --git a/elixir/step0_repl.ex b/elixir/step0_repl.ex
new file mode 100644 (file)
index 0000000..742c5f5
--- /dev/null
@@ -0,0 +1,34 @@
+defmodule Step0Repl do
+  def main do
+    IO.write(:stdio, "user> ")
+    IO.read(:stdio, :line)
+      |> handle_line
+      
+    main
+  end
+
+  defp handle_line(:eof), do: exit(0)
+  defp handle_line(line) do
+    IO.write(:stdio, read_eval_print(line))
+  end
+
+  def read(input) do
+    input
+  end
+
+  def eval(input) do
+    input
+  end
+
+  def print(input) do
+    input
+  end
+
+  def read_eval_print(line) do
+    read(line)
+      |> eval
+      |> print
+  end
+end
+
+Step0Repl.main