Log In  

no, I'm not referring to giving the do in for loops and while loops a free pass. rather, I'm referring to the rarely-used naked do block. the primary function of the do block by itself is to arbitrarily introduce a new scope. for example, a code snippet I just wrote:

 local yclp=127-17*pizzapower

this makes it clear to the reader that I do not intend to use yclp at any other point in the program. In this case, it becomes fairly obvious that I lifted an inline expression to its own line for clarity's sake. however, the do construct here eats up a token, making using it disadvantageous. considering that the do block's only real use has to do with usage of local variables, and the local keyword already has its cost annulled to encourage its use, I think it would make sense if there was a similar exception for the by-itself do block. what do all of you think?

P#82897 2020-10-13 20:54 ( Edited 2020-10-13 20:56)

:: Felice

You could say the same about parentheses. They're really both just hints to the parser about what goes where and what's associated with what. Nevertheless, even if they don't really have a runtime functionality once parsed, they're still a part of your cart, since the parsing happens at runtime. So, even though I'm usually one for reducing unnecessary token costs, I'm not sure I can get behind this one.

P#82899 2020-10-13 21:06 ( Edited 2020-10-13 21:07)
:: sol

@Felice the difference is that parens have a lot of uses and as such you can't really avoid using them. plus, changing the cost of parens would have a lot of knock-on effects since they are used in so many constructs anyway, so that's a much more complicated subject.

naked do blocks on the other hand are completely avoidable-- if they have a cost, almost nobody will use them. it's the same reason the local keyword has no cost to it.

P#82901 2020-10-13 21:15 ( Edited 2020-10-13 21:16)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-10-25 23:22 | 0.014s | 4194k | Q:17