Method syntax #60
Labels
experimental
Purely experimental ideas (for now)
feature
New feature or request
language
Language features/requests
Milestone
Placeholder, but also an initial idea:
Instead of adding a dedicated token to emulate method syntax (e.g. Lua's
f:read()
==read(f)
), overload.
without removing the syntactic sugar for table lookups with string keys.For example, in the expression
x.y(...)
:x
is a table, attempt the lookup ofy
in tablex
a. If
y
exists and is a function, invoke the function with the arguments untouchedb. If
y
does not exist (or is not a function?), goto step 2.x
is not a table, attempt a local/global lookup for the variabley
a. If
y
exists in scope and is a function, invokey(x, ...)
Unknown: emitting code to handle local scope, i.e.
x.y()
andy
exists in a local lexical scope. This is an issue at runtime since local identifiers are essentially thrown away after compilation. PerhapsSIDX[AV]
can be compiled with an optional stack slot if the identifier exists in a local scope. Or a new opcode that falls back to a local vs a global.This is definitely a lazy way to implement this kind of syntax, but it doesn't require the full implementation of objects or defining "metamethods" for various data types. The obvious motivation here is to allow the ability to clean up nested function calls with chained method-style calls. E.g.
split(read(f, 'a'), /\n/)
->f.read('a').split(/\n/)
.The text was updated successfully, but these errors were encountered: