ID:1884131
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
(not to be confused with "anonymous function")

Ability to define inline functions that work similar to the #define preprocessor but belong to classes.
// They're defined pretty much exactly how procs are. 

inline/do_stuff(foo) world << foo
// equivalent to #define do_stuff(foo) world << foo

mob/inline/DoStuff() world << src

The body of the function replaces the invocation at compile-time after the accessor (dot) is type-checked. Any use of src in the inline is replaced by the accessed object.
var mob/m = new
m.DoStuff()

// translates to
var mob/m = new
world << m

// whereas
var obj/o = new
o.DoStuff()
// gives a compile-time error.

Because the body of the inline function replaces the call at compile-time, local variables can be accessed. This means the definition of the body won't be checked for errors unless it's invoked, just like #defines.
mob/inline/check_foo()
// there's no 'foo' variable defined here
// but that's perfectly fine.
// 'src' is replaced with the accessed object.
src << foo

mob/Login()
var foo = 123
check_foo() // replaced with src << foo, so it outputs 123

var mob/m = new
m.check_foo() // replaced with m << foo

This should offer efficiency boosts similar to using #defines due to the lack of procs being called. It would be nice to keep the global scope clear of this stuff.

Another example:
mob/inline/finish_up()
foo += 456
return foo

mob/proc/DoThing()
var foo = 123
finish_up()
del world // doesn't occur; proc returned in the line above


"Real-world example":
atom/movable
inline
Px() ((x-1)*TILE_WIDTH + bound_x + step_x)
Py() ((y-1)*TILE_HEIGHT + bound_y + step_y)

Faster as a #define, but only relevant to movable atoms.
You can do multiline defines already using \ at the end of a line, and simply pass the mob or atom as an argument. Therefore:

#define Px(A) ((A.x-1)*TILE_WIDTH  + A.bound_x + A.step_x)
#define Py(A) ((A.y-1)*TILE_HEIGHT + A.bound_y + A.step_y)
In response to Lummox JR
I guess the key here is that it's not defined in the global scope, so it wouldn't cause naming conflicts and such.
In response to Kaiochao
Well, there's always #undef.