ID:2062619
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Astonishingly enough, there doesn't seem to be a feature request for this.

Is there any way that static methods could be added to DM? For the long integer library I'm messing with, I have a function defined as follows:
pif_LongInt/UnsignedDouble/proc
Highest()
// Largest unsigned integer representable for an unsigned double-precision integer.
return new /pif_LongInt/UnsignedDouble(0xFFFF, 0xFFFF)

As it stands, this is kind of useless because in order to actually use it, you need to do something like
var/pif_LongInt/UnsignedDouble/i = new
i = i.Highest()

or something similar. There are ways around this, such as defining global variables or a global function that handles it. Unfortunately, the latter completely breaks any notion is being extensible in a nice way, while the former is extremely ugly and requires an object to be defined at runtime for each class. Furthermore, because they are already out there, they could be reassigned or otherwise screwed around with and suddenly the semantics of the code don't align with what's actually going on.

With static methods, I could just do,
pif_LongInt/UnsignedDouble/proc/static
Highest()
return new /pif_LongInt/UnsignedDouble(0xFFFF, 0xFFFF)

var/pif_LongInt/UnsignedDouble/int = /pif_LongInt/UnsignedDouble.Highest()

and all would be nice in the world.
I support.
this would be great, but I doubt it's feasible.
Static methods might be doable. A syntax like /pif_LongInt/UnsignedDouble.Highest() wouldn't work, however, because . in this context is a path operator, and : is too.
You can tell a path . from a static function because of the closing (). Just by disallowing () in paths except in function paths, there are no longer any ambiguous cases. I can understand not wanting to muck with the lexer like this though.

I would certainly hope static vars would be usable in static functions. Should non-static object vars in a static function fail to compile or just use the initial value?
In response to MisterPerson
MisterPerson wrote:
You can tell a path . from a static function because of the closing (). Just by disallowing () in paths except in function paths, there are no longer any ambiguous cases. I can understand not wanting to muck with the lexer like this though.

As in many languages, BYOND does not use "look-ahead" behavior for parsing purposes, so doing as you suggest would be utterly impossible without a major overhaul to the parser.

I would certainly hope static vars would be usable in static functions. Should non-static object vars in a static function fail to compile or just use the initial value?

A first-pass implementation would probably simply let it compile, which would mean that any attempt to access src.var would result in a runtime error because of src being null.

A later, more sophisticated implementation would probably attempt to catch this case in the proc code as it compiles, preventing src.var from being used without throwing a compile-time error.
i think there could be some merit in letting src be set to a static instance that just has inital() vars and static vars, and only have it runtime if you attempt to assign to a non-static var.

i used call()() to imitate static procedures when i used to program in dm
mega-bump

turns out this is already possible with call()

test
proc/test()
world << "calling /test/proc/test"

if(!src)
world << "src is null!"

return 1

client/verb/do_test()
src << call(/test/proc/test)()


output:
calling /test/proc/test
src is null!
1
So, doable with macro hell?
This would be awesome if possible. Another benefit is it'd finally let us sort global procs. You could make static methods using datums as pseudo namespaces. Geometry.EuclidianDistance(A, B), etc