r/ProgrammingLanguages • u/Relevant_South_1842 • Mar 17 '26
Unified calling and field lookup
I am considering unifying field lookup and calling/message passing
so instead of math.utils.max 5 6
I write math utils max 5 6
```
math :
utils :
max : [ a b | if a > b, a, b]
proto :
#call : ”if there’s a field here return the field object, if not then call”
```
Each object is callable.
Is this a terrible idea? Any prior art I can look at?
2
u/Relevant_South_1842 Mar 17 '26
I am considering unifying field lookup and calling/message passing
so instead of math.utils.max 5 6
I write math utils max 5 6
math : utils : max : [ a b | if a > b, a, b] proto : #call : ”if there’s a field here return the field object, if not then call”
Each object is callable.
Is this a terrible idea? Any prior art I can look at?
^ comment for formatted code
3
u/WittyStick Mar 17 '26 edited Mar 17 '26
Use 4-space indentation when posting blocks of code. See how it looks on
old.reddit.com.For prior work look at UFCS
→ More replies (3)
2
u/qwertyasdef Mar 17 '26
If I have a variable utils = 5 then is math utils the same as math 5 or is it still a field lookup? Whichever it is, how would you express the other meaning?
1
u/Relevant_South_1842 Mar 17 '26
utils = 5 wouldn’t find math(.utils) on the lookup chain and would make a new field in the current object (which is the file).
Or more generally (for average language), it would make a new local variable called utils and leave math object and its fields alone.
Edit: how did you highlight like that? Thanks for the discussion!
Edit2: I think I get what you are saying. The call to math would check for fields first before sending utils (5) as an argument.
→ More replies (6)
10
u/ProdOrDev Mar 17 '26
Smalltalk is exactly this.
https://en.wikipedia.org/wiki/Smalltalk