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

[Feature] Succeeded keyword #287

Open
Sod-Almighty opened this issue Jul 7, 2024 · 8 comments
Open

[Feature] Succeeded keyword #287

Sod-Almighty opened this issue Jul 7, 2024 · 8 comments
Labels
compiler enhancement New feature or request feature proposal help wanted Extra attention is needed

Comments

@Sod-Almighty
Copy link

In the examples on the website, I notice unsafe is being used in situations where a Bash command succeeding should cause a bailout condition. For example:

silent unsafe $ iwgetid -r | grep -E '(OEBB|WESTlan)' $
if status == 0 {
  echo "Skipping updates because of slow Wifi"
  exit(0)
}

When a failure should cause a bailout, you just use the failed keyword like this:

$mv file.txt dest.txt$ failed {
  echo "It seems that the file.txt does not exist"
}

There are only two script examples on the website, and both of them use unsafe to get around a limitation in Amber. If "failure is success and success is failure" situations are that common, why not have a keyword for it?

$ iwgetid -r | grep -E '(OEBB|WESTlan)' $ succeeded {
  echo "Skipping updates because of slow Wifi"
  exit(0)
}
@Sod-Almighty Sod-Almighty added the enhancement New feature or request label Jul 7, 2024
@Sod-Almighty Sod-Almighty changed the title [Feature] Success keyword [Feature] Succeeded keyword Jul 7, 2024
@Sod-Almighty
Copy link
Author

Perhaps also introduce a !? operator to complement the ? operator...

@b1ek
Copy link
Member

b1ek commented Jul 8, 2024

i think we should get rid of the failed and use if for consistency in non-assignment situations

like this:


if $do_stuff$ {
    // succeeded
} else {
    // failed
}

if $do_stuff$ { // error!! no unsafe keyword or else block

}

let a = silent $get_a$ failed {
    0
}

@b1ek b1ek added help wanted Extra attention is needed feature proposal labels Jul 8, 2024
@Ph0enixKM
Copy link
Member

i think we should get rid of the failed and use if for consistency in non-assignment situations

like this:


if $do_stuff$ {
    // succeeded
} else {
    // failed
}

if $do_stuff$ { // error!! no unsafe keyword or else block

}

I’m afraid that this would introduce disambiguation for the if statement as the command evaluates to Text.

I like the succeeded but I’d go even further and introduce a match block that will match success, error or any custom code

@b1ek
Copy link
Member

b1ek commented Jul 9, 2024

match block that will match success, error or any custom code

it would also be useful to work with variables, like to match different string constants. it probably could also be compiled to readable case ... esac

@Ph0enixKM
Copy link
Member

it would also be useful to work with variables, like to match different string constants. it probably could also be compiled to readable case ... esac

Yes. That would be an interesting feature to add.

@Ph0enixKM
Copy link
Member

If we do this - we could rewrite unsafe and silent command modifiers to be blocks:

block unsafe(command: Text) {
    ${command}$ failed {}
}

block silent(command: Text) {
    ${command} > /dev/null 2>&1$?
}

@Sod-Almighty
Copy link
Author

Sod-Almighty commented Jul 9, 2024

Was this response intended to be posted on the "block" issue?

But yes....if we allow blocks to be invoked like modifiers:

pub block sudo(...) {
}

sudo $ thing $            // modifier syntax
sudo {
   $ thing $                  // block syntax
}

You mentioned macros.....would it be better for block functions to take an array of tokens instead of one big string?

pub block sudo(args: string array) {
   echo args[1]          // "mv"
   echo args[2]         // "thing"
}

pub fun move(file1, file2) {
  $ mv {file1} {file2} $
}

sudo move "thing" "otherthing"

@Ph0enixKM
Copy link
Member

Yes it was. Sorry for the lack of context. I’ll think about it also from the compiler stand point and propose the ultimate solution to this. I like what you have shown better. The macros kind of syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler enhancement New feature or request feature proposal help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants