bleed
KeywordThe bleed
keyword is a new concept of NAL which has the following semantic:
A symbol declared/defined with bleed
automatically becomes visible in the scope directly outside of the one it is defined in.
This has two main applications: Control structure scope and function scope.
bleed
again upon declaration/definition.In the following simple example, the index used inside of the for loop becomes visible outside of the loop.
NAL:
for (bleed i in myArray) {
if (myArray[i] == nullptr) break;
}
printf("The resulting index is %i", i);
C:
size_t _i;
for (; _i < _nalArraySize(myArray); ++_i) {
if (myArray[_i] == nullptr) break;
}
printf("The resulting index is %d", (int)_i);
_
in C is sufficient.mutable
keyword makes it mutable in the outer scope: for (mutable bleed i in myArray) { ...
find_if
. The same example as above would be written like this in C++:
auto it = std::find_if(myArray.begin(), myArray.end(), [=](const auto& elem){return elem == nullptr;});
size_t index = it - myArray.begin();
In the following simple example, the variable used inside of the function becomes accessible to the calling scope as optional return value.
NAL:
getSum(myArray array) f32 {
bleed size = myArray.size();
sum = f32(0.);
for (i in myArray) { sum += myArray[i]; }
return sum;
}
{
theSum, size: theSize = getSum(myArray);
printf("Average: %f", theSum / mySize);
}
C:
float getSum(_NALArray myArray, i32* _size) {
_nal_bleeding_size = _nalGetArraySize(myArray);
float sum = 0.;
for (size_t i = 0; i < _nal_bleeding_size; ++i) { sum += myArray[i]; }
_size = _nal_bleeding_size;
return sum;
}
{
i32* _nal_bleeded_size;
float theSum = getSum(myArray, _nal_bleeded_size);
const i32* theSize = _nal_bleeded_size;
printf("Average: %f", theSum / theSize.toF32());
}
Other posibility:
NAL:
getSum(myArray array) f32{
bleed size = myArray.size();
sum = f32(0.);
for (i in myArray) { sum += myArray[i]; }
return sum; // will be bleeded as sum:
}
{
sum: theSum, size: theSize = getSum(myArray);
printf("Average: %f", theSum / mySize);
}
C:
float getSum(_NALArray myArray, i32* _size) {
_nal_bleeding_size = _nalGetArraySize(myArray);
float sum = 0.;
for (size_t i = 0; i < _nal_bleeding_size; ++i) { sum += myArray[i]; }
_size = _nal_bleeding_size;
return sum;
}
{
i32* _nal_bleeded_size;
float theSum = getSum(myArray, _nal_bleeded_size);
const i32* theSize = _nal_bleeded_size;
printf("Average: %f", theSum / theSize.toF32());
}
If someone is not interested in the optional size
return value, one simply writes the following. The variable _nal_devnull
is a variable where anything can be written to but it will be completely ignored.
NAL:
{
theSum = getSum(myArray);
}
C:
{
float theSum = getSum(myArray, _nal_devnull);
}