BSLang / BS

Implementation of the BS language as created by Mark Rendle at BuildStuff.lt 2014. Refer to this repo for information and canonical list of language features
206 stars 10 forks source link

return statements #3

Open ProfessorTom opened 6 years ago

ProfessorTom commented 6 years ago

After watching the Skills Matter video a non-trivial number of times, I realized that returning values from functions was not addressed.

return is too easy.

I propose that a system similar to INTERCAL's politeness be used for returning values from functions vs. Scala's implied returns (although, implied returns means the return semantics are invisible–a highly desirable feature for BS.). To wit: the key phrase please give back in lieu of return but this must be balanced with the key phrasetake that or do the needful in lieu of return if the compiler detects too much politeness which will be determined by a PRNG-generated percent of correct politeness each time the compiler is invoked, thus causing additional source edits per compile.

MonstraG commented 3 years ago

Far easier solution, I think, is to return all undeleted variables in reverse (compared to declaration) order.

carlsonj commented 3 years ago

Better still, have only a "please take <variable> from <function>" used in the caller's context, with no indication in the called function about what is to be returned. That way, the called function becomes an open book. Any caller can specify which variable it would like to have. Just imagine the code-reuse possibilities.

barkermn01 commented 2 years ago

Better still, have only a "please take <variable> from <function>" used in the caller's context, with no indication in the called function about what is to be returned. That way, the called function becomes an open book. Any caller can specify which variable it would like to have. Just imagine the code-reuse possibilities.

but it messes with the Delete keyword you can't take a delete variable but you must delete all variables or you have one hell of a memory leak.

Argavyon commented 1 year ago

Better still, have only a "please take <variable> from <function>" used in the caller's context, with no indication in the called function about what is to be returned. That way, the called function becomes an open book. Any caller can specify which variable it would like to have. Just imagine the code-reuse possibilities.

but it messes with the Delete keyword you can't take a delete variable but you must delete all variables or you have one hell of a memory leak.

Using please take <variable> from <function> and clean up should easily handle deletion of the function's variables when expecting a returned value; all is fine but please clean up should handle deletion of the function's when no returned value is desired.