On 05/03/2025 21:10, Edmond Dantes wrote:
Essentially, this is Kotlin, but it should also resemble Python. However, unlike Kotlin, there are no special language constructs here—code blocks naturally serve that role. Of course, syntactic sugar can be added later for better readability.


To pick up on this point: PHP doesn't have any generalised notion of "code blocks", only Closures, and those have a "weight" which is more fundamental than syntax: creating the Closure object, copying or referencing captured variables, creating a new execution stack frame, and arranging for parameters to be passed in and a return value passed out.

Perhaps more importantly, there's a reason most languages don't represent flow control purely in terms of functions and objects: it's generally far simpler to define "this is the semantics of a while loop" and implement it in the compiler or VM, than "these building blocks are sufficient that any kind of loop can be built in userland without explicit compiler support".

Defining new syntax would encourage us to define a minimum top-level behaviour, such as "inside an async{} block, these things are possible, and these things are guaranteed to be true". Then we simply make that true by having the compiler inject whatever actions it needs before, during, and after that block. Any additional keywords, functions, or objects, are then ways for the user to vary or make use of that flow, rather than ways to define the flow itself.

This is roughly what happened with Closures themselves in PHP: first, decide that "$foo = function(){};" will be valid syntax, and define Closure as the type of $foo; then over time, add additional behaviour to the Closure class, the ability to add __invoke() hooks on other classes, etc

Regards,

--
Rowan Tommins
[IMSoP]

Reply via email to