Bend
Bend copied to clipboard
fork(x-1) leads to error Unbound variable 'x-1'. But fork(x+(-1)) works
Description
fork(x-1) leads to error Unbound variable 'x-1'.. But fork(x+(-1)) works.
To Reproduce
def pow_down(number, power):
bend x=power:
when x>1:
mult = number * fork(x-1)
else:
mult = number
return mult
def main:
return pow_down(2, 10)
Returns:
Errors:
In definition 'pow_down':
Unbound variable 'x-1'.
Expected behavior
This piece of code works and outputs 1024, I would expect both to work or both to throw an error:
def pow_down(number, power):
bend x=power:
when x>1:
mult = number * fork(x+(-1))
else:
mult = number
return mult
Desktop
- OS: WSL (Ubuntu 22.04)
- CPU: Intel i5-12600K
- GPU: GTX 1080Ti
- Cuda Version 12.3
Additional context
Please ignore my shitty sequential code.
Bend variable names follow this regular expression: [A-Za-z0-9_.-/]+. If you type x - 1 the code will work as expected.
A var_name-num is actually a special variable that is used to access a predecessor of the matching number in the last case of a switch case:
def main:
switch num = 4:
case 0:
return 0
case 1:
return 1
case 2:
return num-2
Oh yes sorry I just read this part of the doc because this error came up again: https://github.com/HigherOrderCO/Bend/blob/main/docs/syntax.md#variables . 10 minute after after opening the issue, I noticed that it was a dumb question ...
Anyway, thanks a lot for taking your time to explain!
I'll improve the error message since this is a very common situation