This PR implements smart subtask name handling in the ThinkPy interpreter, allowing users to define subtasks with readable names (spaces and proper capitalization) while calling them using standard programming conventions (lowercase with underscores).
Changes
Updated execute_function_call in interpreter.py:
def execute_function_call(self, func_call):
"""Execute a function call"""
func_name = func_call['name']
args = [self.evaluate_expression(arg) for arg in func_call['arguments']]
# Check for built-in functions
if func_name in self.builtins:
return self.builtins[func_name](*args)
# Try exact match first
if func_name in self.subtasks:
return self.execute_subtask(func_name)
# Try converting the function name to possible subtask names
converted_name = func_name.replace('_', ' ').title()
if converted_name in self.subtasks:
return self.execute_subtask(converted_name)
raise RuntimeError(f"Unknown function: {func_name}")
Testing
Example program that now works:
objective "Test subtask naming"
task "Test" {
subtask "Calculate Total" {
return 42
}
step "Use It" {
result = calculate_total() # Works now!
print(result)
}
}
run "Test"
Related Issues
Closes #123
Documentation Updates
Will need to update the documentation to explain:
Users can define subtasks with spaces and proper capitalization
Function calls should use lowercase with underscores
Both formats are automatically matched
Screenshots
Before:
ThinkPy Error: Unknown function: calculate_total
After:
[OUTPUT] 42
Testing Instructions
Run the example program above
Try variations of subtask names:
"Calculate Total" -> calculate_total()
"Process Data" -> process_data()
"Validate Input" -> validate_input()
Verify that exact matches still work
Verify helpful error messages for truly unknown functions
Description
This PR implements smart subtask name handling in the ThinkPy interpreter, allowing users to define subtasks with readable names (spaces and proper capitalization) while calling them using standard programming conventions (lowercase with underscores).
Changes
Updated
execute_function_call
in interpreter.py:Testing
Example program that now works:
Related Issues
Closes #123
Documentation Updates
Will need to update the documentation to explain:
Screenshots
Before:
After:
Testing Instructions
Checklist