### Wiki Diff forum-msg-id-137740-edit, revision #3 to tip

Original date:2023-03-17 11:13:15
Original date:2023-03-17 10:35:30
Edited by: petelomax
Subject: Re: Introspection?

In Phix:
<eucode>
function me(integer rid)
return get_routine_info(rid)[4]
end function

procedure Hello(sequence place)
puts(1, me(Hello) & ", " & place & "!\n")
end procedure

Hello("World")
</eucode>
or
<eucode>
function me()
integer rid
#ilASM{
[32]
mov eax,[ebp+20] -- prev_ebp
mov eax,[eax+8] -- rtn_id
mov [rid],eax
[64]
mov rax,[rbp+40] -- prev_rbp
mov rax,[rax+16] -- rtn_id
mov [rid],rax
}
return get_routine_info(rid)[4]
end function

procedure Hello(sequence place)
puts(1, me() & ", " & place & "!\n")
end procedure

Hello("World")
</eucode>
If there is a real use for it, I could easily make get_routine_info(0) yield {...,"me"}, and get_routine_info(-1) yield {...,"Hello"}, ie get a rid<=0 from the call stack.\\
Heck, why not just do that anyway:
<eucode>
requires("1.0.3")
function me()
return get_routine_info(-1)[4]
end function

procedure Hello(sequence place)
puts(1, me() & ", " & place & "!\n")
end procedure

Hello("World")
</eucode>

PS: My {{{JavaScript}}} implementation of get_routine_info() was this:
{{{
function get_routine_info(fn) {
return ["sequence",fn.length,0,"",fn.name];
}
}}}
Which means:\\
"sequence": ignore this / 1-based indexes,\\
fn.length: the max number of arguments,\\
0: there is no min "" in js,\\
"": there is no function signature in a typeless language,\\
fn.name is probably a bit better than what you were using?
</eucode>

Not signed in.