ID:2131440
 
Applies to:Dream Maker
Status: Open

Issue hasn't been assigned a status value.
I'd like to be able to make procs like locate() which have access to the declared type of the variable currently being assigned to the return value of the proc.
// Like this:
var obj/poop/poop = locate() // locates a /obj/poop in the world

// But for custom procs; instead of this:
var component/my_custom_player_controller
controller = entity.GetComponent(/component/my_custom_player_controller)

// We can do this:
var component/my_custom_player_controller/controller = entity.GetComponent()

// Example syntax:
entity/proc/GetComponent(ComponentType = vartype)
// from above, vartype == /component/my_custom_player_controller
return locate(ComponentType) in _all_components

Now, I know that since GetComponent() uses locate(), I could write a hacky macro that takes advantage of how private variables aren't a thing (_all_components is kind of meant to be private):
#define GET_COMPONENT(ENTITY) locate() in ENTITY._all_components

// ...
var component/camera/camera = GET_COMPONENT(entity)
That'd be interesting. I wonder if it'd make more sense to be like that partially-functioning "expanding" hidden arg, or a proc var.
ya, I was thinking about this the other day.

Something to just know the vartype of the left hand var would be helpful, a easier syntax would maybe be something like a var that defaults to null. Or give .. a value and fix that crash report bug as well in one go.

Actually, the best way would be to be able to see how a var is typed using some instruction, any var, and just make vartype(.) return the type of the land hand var.

The issue is, i don't honestly think this is done at runtime, and for userland code, it would have to be. (at least, for my idea).

So how lummox might have to do it, to allow this to be resolved at compile time, is a special arg.

/proc/dothings(TheType=vartype(), ...)

Then at compile time, it just injects an arg into the actual proc call, with the type.

Give istype functionality by allowing it to reference earlier args:

/proc/dothings(TheThing, TheType=vartype(TheThing))
This is very similar to the issue of operator overloading. Built-in procs like new(), locate(), output(), input(), and call()() are all given special treatment that allows them to access things outside of their parentheses.

We cannot currently define our own procs with such unique syntactic structures. DM would become a lot more modular if this were made possible. These procs are basically telling us to do as they say, but not as they do.

Programming languages flow better when they have less unique syntax structures for us to worry about. If such structures are normalized and blended throughout the language, they become easier to remember, and have less of an impact on the learning curve. It would let developers ask, "How does that work?", instead of, "What does this do?".
This would have to be setup compiler-side. I like the idea, although I'm not sure how I'd get the special arg thing to work. (I agree that it's probably the only approach that would do, however.)