Beef icon indicating copy to clipboard operation
Beef copied to clipboard

[Enhancement] Explicit parameter shadowing

Open Igoorx opened this issue 4 years ago • 1 comments

It would be very useful to have some way to "redefine" a parameter in one line, in beef you can't redefine parameters because everything is passed as an in parameter, this makes it impossible to do the following: image

So, currently the only way to do this would be to do a shadow declaration of the value with the var param syntax and then redeclare the value, but this is two lines:

var str;
str = scope ParamType(str);

I don't think the above way to do it is good because it adds one extra unnecessary line that ends up polluting the code, so I propose some way to do this in one line, as discussed in the discord, the best way may be to use a special keyword to make an explicit shadow of the parameter, so here is an example of what it could be:

shadow str = scope String(str);

Igoorx avatar Jan 18 '21 18:01 Igoorx

Hm. I think we could reuse new here, actually, in the similar sense to how it's used in inheritance to allow you to have fields of the same name as a base type.

new var str = scope String(str);...

bfiete avatar Feb 12 '22 15:02 bfiete