Skip to content

Methods

Devlish supports class-style programs with named methods. A class file declares a module and class on its first line, then defines methods with parameters and return values.

The first non-comment line declares the module and class:

Finance's Payroll Calculator:

Optionally inherit from a parent class:

Finance's Senior Payroll Calculator based on Finance's Payroll Calculator:

Methods are defined with a name, parameters, and an indented body. They end with respond with to return a value.

Finance's Payroll Calculator:
calculate wages using hours worked and hourly rate:
gross pay equals hours_worked times hourly_rate
tax equals gross_pay times 0.22
net pay equals gross_pay minus tax
respond with net_pay
calculate overtime using hours worked and hourly rate:
overtime hours equals hours_worked minus 40
overtime rate equals hourly_rate times 1.5
overtime pay equals overtime_hours times overtime_rate
respond with overtime_pay

Parameters are listed after using, separated by and. Multi-word parameter names are normalized to snake_case inside the method body.

calculate exposure using contract value and risk score:
total exposure equals contract_value times risk_score
respond with total_exposure

Prefix with privately to mark a method as internal. Private methods are not exposed as tool entry points.

privately validate cap:
cap must be at most 1000000
respond with true

Every method returns a value using respond with. This is the method’s output.

format summary using project name and total value:
summary equals record with project_name as name and total_value as value
respond with summary

From the CLI, specify which method to invoke:

Terminal window
devlish run payroll.dvl --method calculate_wages --input '{"hours_worked": 40, "hourly_rate": 25}'

From compiled bytecode:

Terminal window
devlish compile payroll.dvl --output payroll.dvlc.json
devlish run payroll.dvlc.json --method calculate_wages --input '{"hours_worked": 40, "hourly_rate": 25}'
Compliance's Risk Assessor:
assess risk using deal value and jurisdiction and credit type:
base score equals 50
If deal_value > 10000000:
base_score equals base_score plus 20
If jurisdiction equals "international":
base_score equals base_score plus 15
risk level equals "low"
If base_score > 70:
risk_level equals "high"
result equals record with base_score as score and risk_level as level
respond with result
privately calculate threshold using credit type:
If credit_type equals "ITC":
respond with 5000000
respond with 1000000