10 ms·
Perl 6 feels a bit "ad hoc" to me... It looks like it has very interesting features but it lacks the uniformity present in most languages...
by rs86 8y ago
Perl 6 feels a bit "ad hoc" to me... It looks like it has very interesting features but it lacks the uniformity present in most languages...
- nine_k 8y agoPerl has never been about uniformity. Perl is a great experiment in language design, or, rather, a battery of experiments. It's the opposite of a cleanly designed language.
- herrosheep 8y agoI do agree that Perl (6) is not a cleanly designed language.
- lizmat 8y agoWould you care to elaborate on the non-clean parts in your opinion?
- herrosheep 8y agoThings like this seem like odd design choices: my @menu = <hamburger fries milkshake>; say @menu.contains('hamburger'); # True say @menu.contains('hot dog'); # False say @menu.contains('milk'); # True! say @menu.contains('er fr'); # True! say @menu.contains(<es mi>); # True!
- raiph 8y agoEnglish contains ambiguous words. What does "contains" mean in the previous sentence? In P6 it means searching a string for a substring. Your code asks P6 to treat @menu as a string. If you want to treat it as a list and grep that list then use grep: my @menu = <hamburger fries milkshake>; say so @menu.grep('hamburger'); # True say so @menu.grep('hot dog'); # False say so @menu.grep('milk'); # False say so @menu.grep('er fr'); # False say so @menu.grep(<es mi>); # False
- xisukar 8y agoFrom https://docs.perl6.org/routine/contains https://docs.perl6.org/routine/contains, `contains` coerces its invocant to a string and searches for a substring starting from a certain position (index 0 by default): # Let's drop `<>` (quote-words constructor) and # use a more familiar array of strings: my @menu = 'hamburger', 'fries', 'milkshake'; # Let's look at the definition of the `Str` method in # the `List` class from which the `Array` class inherits: #`{ method Str(List:D: --> Str:D) Stringifies the elements of the list and joins them with spaces (same as .join(' ')). } # Thus, after being stringfied, @menu is treated as # the string 'hamburger fries milkshake' # With this is in hand, we can gauge the possible # result of the following statements: say @menu.contains('hamburger'); # True say @menu.contains('hot dog'); # False say @menu.contains('milk'); # True say @menu.contains('er fr'); # True say @menu.contains(<es mi>); # True If you'd like instead to search the array for words as elements, we could use Perl 6's set functions. However, I don't know if they're as performant as regular string searches: say 'hamburger' (<=) @menu; # True say 'fries' (<=) @menu; # True say 'hot dog' ∈ @menu; # False say 'milk' ∈ @menu; # False say 'er fr' ∈ @menu; # False `∈` is the unicode equivalent of `(<=)`. --- I'm not sure if I'm missing something in the "odd design choices" in this specific case so it'd be great if you could elaborate a little bit further here.
- b2gills 8y agoYou are sort-of right. It should have used a different word. A similar example would be the word `length`. There is no `length` in Perl 6 because it is ambiguous. Instead there is `.elems` and `.chars`. It is perhaps even a worse because there are other languages which use `contains` to see if the container has a given element.
- AnimalMuppet 8y agoNo, it's designed. It's just not designed the way everyone expects a computer language to be designed. It was designed by a linguist. He produced a language with some of the flexibility (and messiness) of human languages, which is completely foreign as a goal to other languages. One of the places this shows up to me is being able to say "it" (in essence). That is, we humans, when talking to each other, we say things like "Read in a line of input. If it looks like an XML tag, pass it to the XML handler function". But you can't talk to a computer that way. The computer says, in effect, "Read in a line of input from where? And put it where? And what do you mean 'if it ends in a newline'? If what ends in a newline?" But in Perl, you can write it just like the humans say it, and Perl says, "Well, you didn't say where to read the input from, so I assume I should read it from the standard place (which is perfectly well defined in Perl). You didn't say where to put the line of input, so I'll put it in the default variable. You didn't say what to check to see if it looks like an XML tag, so I will check the default variable." The default variable, essentially, plays the role of "it" in human language. And the whole language is like that. There are shortcuts that work most of the time, and precise ways of saying things that work when the shortcut isn't what you want. And what the shortcut does is well defined (in the docs; it can be very opaque in code). None of this makes Perl an ideal language. But it has a perspective on language that is (as far as I can tell) unique among programming languages. It is only fair to judge the coherence of the design within the framework of what Perl is trying to be.
- ricardobeat 8y agoExcept the resulting code will look nothing like “the humans say it”, and instead will be a cryptic charade requiring a ton of knowledge to decipher - ending up being neither natural language nor machine code.
- labster 8y agoWhy would Perl repeat the same mistake as others, of trying to treat a programming language too much like a natural language? It's optimized to be read as a programming language, not anything else. Also, "cryptic charade" could be a good name for what all non-Perl 6 languages call "regular expressions". It would make an even better name for a prog rock band.
- slobotron 8y agoInstead of "ad hoc", think of it as a multi-paradigm language. From that viewpoint, I think there is a fair bit of beauty in being able to pick and choose your approach based on the problem at hand without worrying if that is an idiomatic choice dictated by language designers. P6 goes to great lengths to give you all the expressiveness you could hope for, regardless if you are doing functional, OOP, or dealing with concurrency etc...