ID:2024670
 
Not Feasible
Applies to:DM Language
Status: Not Feasible

Implementing this feature is not possible now or in the foreseeable future
Add a default datum proc, /datum/proc/Exec(). Variables called like a function implicitly call Exec():
/var/V = new /datum
V(1,2,list()) // V:Exec(1,2,list())


This would be useful for objects that act primarily as a wrapper for some function, or in general objects that have some function which is normally called Execute() or Start() or Run() or anything similar; for example, a pathfinding algorithm that stores the results in an object.

list/Exec() in this context would pass the call on to its contents, either skipping or throwing an error on non-datum entries:
/mob/list/error_handlers = newlist(/datum/logger, /datum/admin_notifier)
/mob/proc/test()
// for datum d in error_handlers:
// d.Exec()
error_handlers()


If you are going this far you might as well add function delegates but that's up to you. It would be nice to be able to have first-class function delegates, eg,
/mob/proc/test()
var/delegate/D = src.Login // standard mob proc
D()

The only other typesafe way to add delegates would use a full proc typepath:
    var/delegate/D = delegate(src,/mob/proc/Login) // standard mob proc


The two are equivalent but it is difficult to read and write long typepaths repeatedly.
Lummox JR resolved issue (Not Feasible)
It's possible for vars and procs to share names, e.g. view and view(), in some cases, so this wouldn't be workable.
Would it be feasible to only allow the syntax on typed variables in scope, eg, not allowing it to be used on untyped vars or :, but allowing it on any var/datum? Obviously it would also need to not overlap with builtin functions eg var/list/list could never be Exec()ed with this syntax.

If you limit it to typed variables then you can object at compile time to namespace collisions, eg, a mob with proc job() could not also have a datum job (although now that I write that it sounds stupid, it would hinder people's ability to name things)

I guess I am entirely okay with the answer no I just wish I had the ability to do it. Mostly I would only use it to create delegates, which you said a while ago you had no interest in doing, but it would be useful in a few other cases as well