3 ms·
I know, so far, only two languages that use defer: Go and Nim.
by archargelod 3y ago
I know, so far, only two languages that use defer: Go and Nim.
- commotionfever 3y agoand harelang.org
- wearhere 3y agoAlso Swift!
- Jtsummers 3y agoSwift, but it is bound to narrower scopes, not just the function scope like Go. How does Nim scope defer statements?
- archargelod 3y agoIn Nim, defer is a macro, that rewrites scope into "try: finally:" statement. 'finally' code block is always executed, even if there were any exceptions. https://nim-lang.org/docs/manual.html#exception-handling-defer-statement https://nim-lang.org/docs/manual.html#exception-handling-def...
- Jtsummers 3y agoYeah, my main question was about the scope of the defer but it appears that it's block scoped like Swift, not function scoped like Go.
- hiyer 3y agoZig has it too.
- loeg 3y agoC++ with folly's SCOPE_EXIT {} construct: https://github.com/facebook/folly/blob/main/folly/ScopeGuard.h#L310 https://github.com/facebook/folly/blob/main/folly/ScopeGuard...
- darrenf 3y agoPerl has experimental support for defer: https://perldoc.perl.org/perlsyn#defer-blocks https://perldoc.perl.org/perlsyn#defer-blocks