stz implicit first parameter

stz implicit first parameter
Photo by Dawid Zawiła / Unsplash

There has been, from the start, the idea of receiverless method calls where the receiver was bound to the current execution context. The 'self' variable, for want of a better name, didn't need to be written out.

adult := self age ≥ 18
adult := age ≥ 18

In the previous post I got stuck on the 'noise' being generated by block definitions which took one thing in and spat one thing out. We made the return value implicit but why not also make the input variable implicit?

[age ≥ 18]

In the above example the receiver is implicitly self but we never defined an parameters. We can implicitly expect one argument, at the bare minimum, because we send messages 'somewhere'. This would be aliased too to the name self.

This only works when there are no other parameters. The moment you have two parameters you cannot do this anymore. Either age comes from a captured variable outside this block or it is a message sent to the unnamed first parameter.

Type inferencing does the heavy lifting for us.

people select: [age ≥ 18]
         into: [stdout print: address]

The fully expanded version of this is:

people select: [self: person -> return: bool | return <- self age ≥ 18]
         into: [self: person -> ø | stdout print: self address]

We could potentially get fancy and allow auto-naming of self1, self2, self3 as you nest and equally return1, return2, return3... but if you start copying/pasting code about then those values would potentially change on you. It's better to require developers to be explicit when they're doing something fancy.

This is concise and clear. It also solves one problem I had. The implicit capture of a self variable across blocks would be problematic for execution speed - you'd be constantly creating closures that you didn't intend. Now self is local to the block, always.

It also encourages naming of things that actually matter to you so it's clear when you are passing a variable to a closure.

person: &person
person age ≥ 18 then: [stdout print: person address]