lambda(3tcl)
β¨ NAME β¨
lambda β utility commands for anonymous procedures π
okay so this one lives in the tcllib collection, manual section 3tcl, and it's literally the glow-up that makes anonymous procedures stop being ugly. π¦
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require lambda ?1.1?
::lambda arguments body ?arg...?
::lambda@ namespace arguments body ?arg...?
like, yes bestie, Tcl 8.5 and 9 β the package requirement lists both, no cap. π
π DESCRIPTION π
So this package hands you two convenience commands whose whole job is making the writing of anonymous procedures (aka lambdas) way more proc-like. β¨ Because ngl, the old way was giving "deep nesting of braces" energy and we were NOT okay with it. π
Instead of writing something like this:
set f {::apply {{x} {
....
}}}
β¦where the braces just keep going and going like a group chat you forgot to mute π, or writing this:
set f [list ::apply {{x y} {
....
}} $value_for_x]
β¦where you need a list command to insert some of the arguments for a partial application (so extra, so unnecessary), you can just write this instead:
set f [lambda {x} {
....
}]
and this:
set f [lambda {x y} {
....
} $value_for_x]
see how much cleaner that is?? the way that we simply β¨declutteredβ¨ the braces. iconic. periodt. π
π COMMANDS π
π ::lambda arguments body ?arg...?
The command constructs an anonymous procedure from the list of arguments, the body script and the (optional) predefined argument values, and it returns a command prefix representing this anonymous procedure. π«Ά
When it gets invoked, the body is run in a new procedure scope sitting just underneath the global scope, with the arguments set to the values supplied at both construction time and invokation time. β
π¦ ::lambda@ namespace arguments body ?arg...?
The command constructs an anonymous procedure from the namespace name, the list of arguments, the body script and the (optional) predefined argument values, and returns a command prefix representing this anonymous procedure. π«Ά
When it gets invoked, the body is run in a new procedure scope in the namespace, with the arguments set to the values supplied at both construction time and invokation time. β
lowkey the difference between these two is just where the scope lands: one under the global scope, one inside the namespace you named. that's the whole vibe check. π
π AUTHORS π
Andreas Kupries β the icon who did this. π
π BUGS, IDEAS, FEEDBACK π
This document, and the package it describes, will undoubtedly contain bugs and other problems. π not me being honest about it, but fr fr. Please report such in the category lambda of the Tcllib Trackers: http://core.tcl.tk/tcllib/reportlist. Please also report any ideas for enhancements you may have for either the package and/or the documentation β we want the ideas too, bestie, not just the bugs. π
When proposing code changes, please provide unified diffs, i.e. the output of diff -u. π§
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. π
π SEE ALSO π
π KEYWORDS π
anonymous procedure, callback, command prefix, currying, lambda, partial application, proc
β CATEGORY β
Utility
πΈ COPYRIGHT πΈ
Copyright (c) 2011 Andreas Kupries, BSD licensed
and that's the whole page, bestie π«Ά this was tcllib version 1.1, signed off with love and way too many emoji. mwah π β¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2011 Andreas Kupries, BSD licensed
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms