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

support function syntax #14

Open
christianparpart opened this issue Dec 18, 2023 · 1 comment
Open

support function syntax #14

christianparpart opened this issue Dec 18, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@christianparpart
Copy link
Member

Now it's getting interesting. Because we first need to figure out how we want to be able to declare a function.

I've let go of the idea to be bash-compatible, i.e. I do understand why fish shell decided to deviate here and there.

I very much like the way of how F# declares a function as well as strong typing. I think it might make sense to embrace strong typing in a shell as well. Even bash kind-of(?) does know about whether it deals with ints (for arithmetic) for example. Going explicit with types should improve readability and maintainability of scripts as well.

Syntax proposal by example:

// Define function f, receiving 3 string parameters, and returning one string
let f (a, b, c): str =
    echo "a: $a, b: $b, c: $c"
    return "($a,$b,$c)"

let y = f "foo" 3.1415 $VAR      // prints and returns something into $y
echo $y                          // prints "(foo,3.1415,VALUE)"

let g a b: str =
    echo "a is: $a, and b is: $b"
    if a = b then
        return "same"
    else
        return "not same"

let has_var name: bool =
    return (getenv $name) != ""

// single-line function definition
let has_var name: bool = (getenv $name) != ""
@Yaraslaut
Copy link
Member

Also, nice addition would be to have creation in-place for example during piping, something like
find -name "*.cpp" | cat $1 cp $1 path/$1 would cat files and copy them

@christianparpart christianparpart added the enhancement New feature or request label Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants