check if an input is lambda in Tcl

76 views Asked by At

I get an argument in Tcl. How can I tell if it's a lambda function, other than using
catch {apply $arg}
?
Thanks

2

There are 2 answers

2
AudioBubble On BEST ANSWER

Tcl does not have a built-in type for lambda functions. catch {apply $arg} is the only option available. Any other thing that is out there will only be using some form of the catch {apply $arg}.

2
Donal Fellows On

Lambdas are syntactically lists where the first element is a well-informed list of lists (usual rules for formal arguments to proc), the second element is a script (with a very wide rangle of syntax possible) and the third element (if supplied) is a namespace name (it defaults to ::).

I'd check if you have a list of 2 or 3 elements where the first element is also a list (possibly empty). That should cover almost everything you'll ever see in practice.