oursh icon indicating copy to clipboard operation
oursh copied to clipboard

Functions

Open nixpulvis opened this issue 6 years ago • 1 comments

POSIX shell language defines functions like foo() { ... }. We must support them.

  • [ ] #54
  • [ ] #55

Related to #27.

nixpulvis avatar Oct 26 '18 20:10 nixpulvis

Can be used with #! blocks.

fib() {#!/usr/bin/env elixir
    defmodule Math do
      def fibfast(n) do fib_acc(1, 0, n) end
      def fib_acc(a, b, 0) do a + b end
      def fib_acc(a, b, n) do fib_acc(b, a+b, n-1) end

      def fibslow(0) do 1 end
      def fibslow(1) do 1 end
      def fibslow(n) do fibslow(n-1) + fibslow(n-2) end
    end

    print_fib = fn(n) ->
      n |> Math.fibfast() |> IO.puts()
    end

    print_fib.($1)
}

fib 10

nixpulvis avatar Mar 18 '19 23:03 nixpulvis