Functions vs. methods

Functional languages provide many benefits, but carry their own cons when it comes to things like I/O, which involve side effects.

Instead of being either strictly procedural or strictly functional, how about introducing functions into a procedural language? Functions are, fundamentally, procedures with several constraints placed upon them. Functions don't have side effects, and ideally their output should depend only on the input parameters.

So, I'm considering making the distinction in Cyan. Procedures are designated with the procedure or method keyword (still deciding which...), and functions by the function keyword.

Functions are given access only to other functions and the objects provided as parameters. They can do whatever they wish with their local variables, but may not call methods on any other variables. (It would be possible to produce side effects if the local variables' methods modified other objects, so perhaps local variables will be disallowed. Perhaps single-static assignment? would be better.)

With the guarantee that no side effects are produced, the compiler could perform optimizations not available in the general case.

Edit this page | 6 years, 11 months old