3 ms·
Some people believe the best place to handle this problem is the compiler or runtime themselves by generating non-cryptic error messages. I believe Raku takes t
by brudgers 5y ago
Some people believe the best place to handle this problem is the compiler or runtime themselves by generating non-cryptic error messages. I believe Raku takes this approach.
- mettamage 5y agoWow, it has quite some history behind it [1]. [1] https://en.wikipedia.org/wiki/Raku_(programming_language) https://en.wikipedia.org/wiki/Raku_(programming_language)
- b2gills 5y agoIt certainly does. (Or rather Rakudo the compiler for Raku does.) There are some for people coming from Perl. say $^V; ===SORRY!=== Error while compiling: Unsupported use of $^V variable; in Raku please use $*RAKU.version or $*RAKU.compiler.version ------> say $^V⏏<EOL> Some for simple typos. my $morning = DateTime.now.truncated-to('day').later( :9hours ); say $moroning; ===SORRY!=== Error while compiling: Variable '$moroning' is not declared. Did you mean '$morning'? ------> say ⏏$moroning; There are some errors that it can't find until it runs your code. say $var.length; No such method 'length' for invocant of type '...'. Did you mean any of these: 'elems', 'chars', 'codes'? (I omitted the type because it doesn't really matter.) The reason Raku doesn't use `length` is because of the common Perl error of calling `length` on an array. In Perl `length` is a string operation. It would turn your array into a number representing the number of elements, and get the count of characters in that. So it would give you a number representing the order of magnitude of an arrays length. In order to catch this error, and to reduce the number of times it happens, `chars`, `codes`, and `elems` were chosen instead. (Functions in Raku are intended to do a single operation on a single type. If the argument isn't that type it often coerces into that type. `elems` for example is a list operation, so something like `Str.elems()` always returns `1`.) Most exceptions are in https://github.com/rakudo/rakudo/blob/master/src/core.c/Exception.pm6 https://github.com/rakudo/rakudo/blob/master/src/core.c/Exce...