<-- back

bleed Keyword

The 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.

Discussion

Control Structure Scope

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);

Discussion

Function Scope

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); }