ID:1011755
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Is such thing trivial? I have ran into a lot of situations where I wished DM had such support for something of that nature. The purpose of inline functions(it wouldn't exactly be an inline function since the design is somewhat different, but the concept is quite similar) would be so that developers can rapidly prototype functions that only return single expressions. Here is an example:

mob
verb
Test()
var add = (x, y) -> return x + y

src << add(5, 5)


It's not the best example, but hopefully I got my point across so that it can at least be considered. Another example, which is actually the above snippet just extended, could look like this:
mob
verb
Test()
var add = proc(x, y) \
return x + y

src << add(4, 5)


That one might be a bit tedious to implement, considering DM's code layout, and might look a bit ugly as well if you're working in a large project, but I'd really like to see something like this added.
I think this would be pretty useful.
It's essentially an anonymous procedure, called via call() under the hood at runtime. The biggest implementation issue I'd see is making the compiler pick up the procedure in the first instance, just as the lexer/parser is apparently quite monolithic at present.

I suspect; although do take this with a grain of salt, that it'd be non-trivial to implement for that reason.
When you define prototypes in procs, all goes well until you try to define a proc. That specific compiler error, "can't define procs in procs" breaks it, and makes me think that anonymous functions were specifically avoided for whatever reason.
In response to Kaiochao
Kaiochao wrote:
When you define prototypes in procs, all goes well until you try to define a proc. That specific compiler error, "can't define procs in procs" breaks it, and makes me think that anonymous functions were specifically avoided for whatever reason.
They're doing it just to mess with us.