3 ms·
I think the common argument against try is that it was a macro in a language without macros. That’s pretty confusing behavior and you can’t expect anyone to und
by sosodev 7y ago
I think the common argument against try is that it was a macro in a language without macros. That’s pretty confusing behavior and you can’t expect anyone to understand that without reading the specification.
- mseepgood 7y agoYou mean a builtin, like panic().
- morelisp 7y agoPanic is a special form (a “keyword”); it is implemented by the compiler and not implementable within the language itself. Try was defined as a syntax transform. Calling it a macro seems reasonable.
- mseepgood 7y agopanic is a built-in and so was try: https://golang.org/pkg/builtin/#panic https://golang.org/pkg/builtin/#panic "The panic built-in function stops normal execution of the current goroutine. [...]" It's not among the list of keywords: https://golang.org/ref/spec#Keywords https://golang.org/ref/spec#Keywords "Q: Why is try a built-in? A: By making try a built-in, there is no need for a new keyword or operator in Go. Introducing a new keyword is not a backward-compatible language change because the keyword may conflict with identifiers in existing programs. Introducing a new operator requires new syntax, and the choice of a suitable operator, which we would like to avoid. Using ordinary function call syntax has also advantages as explained in the section on Properties of the proposed design. And try can not be an ordinary function, because the number and types of its results depend on its input" https://github.com/golang/proposal/blob/master/design/32437-try-builtin.md https://github.com/golang/proposal/blob/master/design/32437-...
- morelisp 7y agoThe Go documentation refers to panic as a "built-in function" but this is a white lie in the documentation. It is not a function; this will not compile: var _ func(interface{}) = panic It is a special form that happens to be spelled like a function. The distinction the Go documentation is drawing between "keyword" and "built-in" is largely about Go's internal parsing mechanism (i.e. can you have a variable named try, or panic, which you can). When Go says "keyword" they mean what would be more formally a "reserved word". Hence my preference for "special form", but this is not well-known outside the Lisp community.