Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions #43

Open
2 tasks
nixpulvis opened this issue Oct 26, 2018 · 1 comment
Open
2 tasks

Functions #43

nixpulvis opened this issue Oct 26, 2018 · 1 comment
Labels
L1: enhancement New feature or request M: process Module: Process exec/fork and IO M: program Module: Oursh language(s) with lexers, parsers and evaluation runtimes. T: grammar Topic: Formal or informal grammar, realtes to lexing / parsing T: semantics Topic: Program evaluation issues or features
Milestone

Comments

@nixpulvis
Copy link
Owner

nixpulvis commented Oct 26, 2018

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

Related to #27.

@nixpulvis nixpulvis added L1: enhancement New feature or request T: grammar Topic: Formal or informal grammar, realtes to lexing / parsing T: semantics Topic: Program evaluation issues or features labels Oct 26, 2018
@nixpulvis nixpulvis added this to the POSIX milestone Oct 26, 2018
@nixpulvis
Copy link
Owner Author

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 nixpulvis added L1: enhancement New feature or request and removed L1: enhancement New feature or request labels Mar 19, 2019
@nixpulvis nixpulvis added M: process Module: Process exec/fork and IO M: program Module: Oursh language(s) with lexers, parsers and evaluation runtimes. labels Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L1: enhancement New feature or request M: process Module: Process exec/fork and IO M: program Module: Oursh language(s) with lexers, parsers and evaluation runtimes. T: grammar Topic: Formal or informal grammar, realtes to lexing / parsing T: semantics Topic: Program evaluation issues or features
Projects
None yet
Development

No branches or pull requests

1 participant