Lcl · Core · Packages · Libraries
ProcProc reflection
The core exposes its name, its parameters, its body text, and where
it was constructed. proc, lambda and
macro all return the value they build, so a definition can
be passed on directly.
Examples:
>> proc add {a b (c 0)} { + $a $b $c }
>> Proc::params add
("a" "b" "?c")
>> Proc::name [lambda {x} { $x }]
""Proc::name pThe name a proc was defined with.
"" for a lambda. A C proc answers its registered name.
The name is the one given at proc/macro time
and does not follow rebinding: let g $f still names
f.
Examples:
>> proc greet {who} { "hi $who" }
>> Proc::name greet
"greet"
>> let g $greet
>> Proc::name $g
"greet"
>> Proc::name {+}
"+"
>> Proc::name [lambda {} { 1 }]
""Proc::params pParameter names in order, as a flat list with markers.
Required parameters are bare, optional ones carry a leading
?, a rest parameter a leading * (its native
spelling). () for a C proc, whose arity is not
declared.
Examples:
>> proc f {a b (c 3) *rest} { $a }
>> Proc::params f
("a" "b" "?c" "*rest")
>> Proc::params {+}
()
>> Proc::params 42
!! expected procProc::body pThe body text exactly as written at proc,
lambda or macro time: the contents of the
braces, comments included. "" for a C proc.
This is source for display and editing, not the closure: re-evaluating it captures whatever is in scope at that point.
Examples:
>> proc sq {x} { * $x $x }
>> Proc::body sq
" * \$x \$x "
>> Proc::body [lambda {y} {+ $y 1}]
"+ \$y 1"
>> Proc::body {+}
""Proc::origin pWhere the proc was constructed: #{file F line L}.
The file and line of the proc, lambda or
macro command that built the value. This is a source
location, not an identity: it follows the value rather than the
name, and every closure a factory returns shares one. Text evaluated
with eval reports the eval’s own name
(<eval at game.lcl:40>) with lines relative to that
text; a host evaluating a buffer names it via
lcl_eval_string_file. #{} for a C proc.
Examples:
>> proc mk {n} { lambda {x} { + $x $n } }
>> == [Proc::origin [mk 1]] [Proc::origin [mk 2]]
1
>> let o [Proc::origin mk]
>> type [get $o line]
"int"
>> Proc::origin {+}
#{}