4 ms·
cuz the language is cryptic as fuck, using every symbol there is; code is like my a = fn { local $v= _[0] %~=-> possibly a time investment trade off, focu
by misccodework 10y ago
cuz the language is cryptic as fuck, using every symbol there is; code is like
my a = fn { local $v= _[0] %~=->
possibly a time investment trade off, focusing on another C-style lang is not as big as a time investment, and translates better to C and C-lang derivites
- yolesaber 10y agoYour example is problematic because it's not even perl code. Perl 6 code is actually pretty nifty for 'dict.txt'.IO.words -> $word { say "$word probably rhymes with Perl" if $word ~~ /[ea?|u|i] rl $/; say "$word is a palindrome" if $word eq $word.flip; }
- saberworks 10y agoI'm not convinced that your example is more readable than a typical program in perl5 without all the magic. To read this code you have to know that appending '.IO.words' to a string will magically cause the file name referenced in the string to be read and then split into words. I would find it much more readable to just say: open the file, loop over the lines, split them into words. Maybe it's one of those conventions I'd get used to over time but right now it just leaves me scratching my head. What if dict.txt doesn't exist? What if it's there but unreadable? What if it's there but a directory? Where is the error checking? Is this going to crash or throw an exception if an error occurs? How does it determine what a word is? I can't even find it in the IO documentation (https://docs.perl6.org/type/IO https://docs.perl6.org/type/IO). So yeah, it's nifty, sort of. It seems more like a snippet to show how nifty itself is rather than something useful.
- PeCaN 10y ago…Just curious, have you ever used any of Perl(5), Python, or Ruby before? If I had to guess, ‘foo.IO.words’ probably turns ‘foo’ into an IO object of some sort and then reads words. (Whether it reads the whole file into a string and splits that into words, or if it just reads the next word generator/iterator-style is not especially relevant.) An error throws an exception, like it would in Python or Ruby ‘open('dict.txt')’. Also I kinda doubt that ‘loop over lines and split them into words’ is more readable than ‘.words’ which presumably does exactly what it says on the tin. A word is probably defined by either \b or UAX #29. (And since IIRC one of the goals of Perl6 is good support for Unicode, \b hopefully uses the word boundary algorithm in that appendix.)
- Ulti 10y agoIf you come from only a Perl 5 background this is the issue. None of that is obvious. It is to someone who's seen OO languages that are a bit functional with good exception handling. In Perl 5 you would probably add to the top of the file: use warnings; use autodie; To get similar functionality as the implicit Perl 6 IO error system.
- markrushing 10y agoWell, Perl 6 throws defined exceptions by default for most stuff like this, and would be very explicit as to why it couldn't open a file. Tests are part of the IO stuff too, to see if it exists beforehand if you like, or check permissions. Also, if you like you can do all the steps of using a normal file open and iterate over each line and split the words yourself if you want to. Your choice. ;)
- gfldex 10y agohttps://docs.perl6.org/type/Str#(Cool)_method_IO https://docs.perl6.org/type/Str#(Cool)_method_IO leads you to: https://docs.perl6.org/type/IO$COLON$COLONPath https://docs.perl6.org/type/IO$COLON$COLONPath leads you to: https://docs.perl6.org/type/IO$COLON$COLONPath#(Cool)_method_words https://docs.perl6.org/type/IO$COLON$COLONPath#(Cool)_method... It's a bit of a trap, I agree and we should fix it. Having all exceptions listed is on the list and will add another few hundred man hours to the nearly 5000 we invested in the docs so far. If you really want to be verbose you can always write `open('foo.txt', :r).Str.split(/\W/)`. If you learn a new language there will be buildins that are well tested and may be more efficient then your solution (it isn't right now for your example. Rakudo does it exactly your way). It can be worth your time to learn what the standard library provides you with -- in any language that is.
- gfldex 10y agofixed with https://github.com/perl6/doc/commit/d1fe150239 https://github.com/perl6/doc/commit/d1fe150239 The lack of feedback from actual language users did slow down Perl 6 development and esp. getting all the holes in the docs plugged.
- harryf 10y agoThe potential to be cryptic argument could easily be applied to Scala but that hasn't stopped it gaining popularity ( http://appliedscala.com/blog/2016/scala-popularity/ http://appliedscala.com/blog/2016/scala-popularity/ )
- tech2 10y agoYou haven't looked at a non-ASCII based APL I gather? :)
- SwellJoe 10y agomy a = fn { local $v= _[0] %~=-> What is that? It certainly isn't Perl (5 or 6).