Reflection/Get source: Difference between revisions

implement in nim lang
(implement in nim lang)
Line 334:
<lang nanoquery>import Nanoquery.IO
println new(File, __file__).readAll()</lang>
 
=={{header|Nim}}==
<lang nim>import macros, strformat
proc f(arg: int): int = arg+1
 
macro getSource(source: static[string]) =
let module = parseStmt(source)
for node in module.children:
if node.kind == nnkProcDef:
echo(&"source of procedure {node.name} is:\n{toStrLit(node).strVal}")
 
proc g(arg: float): float = arg*arg
 
getSource(staticRead(currentSourcePath()))</lang>
{{out}}
<pre>source of procedure f is:
proc f(arg: int): int =
arg + 1
 
source of procedure g is:
proc g(arg: float): float =
arg * arg
 
</pre>
 
=={{header|Phix}}==