vlang/rfcs

[REJECTED] Inline Block => to simplify blocks with only 1 statament

Closed this issue · 2 comments

Inline Block => to simplify blocks with only 1 statament
useful in multiple nested blocks

// with {}
for nucleotide in dna {
  match nucleotide {
    `A` { rna.write_b(`U`) }
    `T` { rna.write_b(`A`) }
    `C` { rna.write_b(`G`) }
    `G` { rna.write_b(`C`) }
    else { rna.write_b(`?`) }
  }
}

// with =>
for nucleotide in dna =>
  match nucleotide =>
    `A` => rna.write_b(`U`)
    `T` => rna.write_b(`A`)
    `C` => rna.write_b(`G`)
    `G` => rna.write_b(`C`)
    else => rna.write_b(`?`)
// with {}
fn f() {
  println('void function')
}

// with =>
fn f() => println('void function')
// with {}
if false {
  println('if')
} else if true {
  println('else if')
} else {
  println('else')
}

// with =>
if false => println('if')
else if true => println('else if')
else => println('else')
bakul commented

Better would be if match can be an expression, just like if! Then you can do:

for nucleotide in dna {
 rna.write_b(match nucleotide {`A`{`U`}`T`{`A`}`C`{`G`}`G`{`C`}else{`?`}})
}

[Edit] Never mind! This already works.

Better would be if match can be an expression, just like if! Then you can do:

for nucleotide in dna {
 rna.write_b(match nucleotide {`A`{`U`}`T`{`A`}`C`{`G`}`G`{`C`}else{`?`}})
}

[Edit] Never mind! This already works.

the one above was only used for illustration

this RFC was rejected and just remains for discussion, comparisons with languages that have this feature and maybe, better proposals