7 ms·
> Only if your language is really awful. A good language shouldn't even let you run "5 < x" when x is a list, but even a mediocre one would surely at least make
by hahainternet 11y ago
> Only if your language is really awful. A good language shouldn't even let you run "5 < x" when x is a list, but even a mediocre one would surely at least make that error out at runtime rather than giving a nonsense answer.
It depends what you consider "Nonsense". Python for example has no reliable way to differentiate between a string and a list. Strings are iterable, but lists can't be compared with the < syntax for example.
My point is simply that $x very clearly says (in Perl 6) "A single value called x" wheras @x is "A list of values called x". In python, "x" is indeterminate even at runtime.
Oh, and you can declare barewords with \x for example, if you really want to, it is Perl after all.
- DonHopkins 11y agoWhat version of Python can't differentiate between a string and a list, or compare lists? Python 2.7.10 (default, Jun 10 2015, 19:42:47) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> type([1]) <type 'list'> >>> type('1') <type 'str'> >>> type(1) == type('1') False >>> [1] < [2] True >>> [2] < [1] False >>> I consider it "Nonsense" to abuse overloaded context sensitive strings of punctuation with arbitrary rules of precedence and associativity, instead of English words correctly spelled out of letters that people can look up alphabetically in a reference manual and google for tutorials to find out what they mean.
- hahainternet 11y agoSorry I should have made things more clear. I am talking about in things like function signatures. Doing something like isinstance(x, str) is discouraged and considered non-pythonic, and recently hasattr() has also been talked about. However, both strings and lists can be iterated, so assuming that this will fail is incorrect: x = "Hello" for y in x: print("{} is {}".format(y, type(y))) I asked on IRC and ultimately the only answer I got was that the most pythonic way to do things was to name functions whatever_str and whatever_list. edit: I also should have said above "lists can't be compared with strings using <". I was trying to point out Python did things potentially correctly there, but I see now it's ambiguous.
- DonHopkins 11y agoIf it's so important to decorate variables with unique punctuation to visually distinguish between two particular kinds of many possible types, then why don't you also decorate function calls according to whether they return lists or scalars? How should you decorate functions that return different types depending on what context they're used in? http://perlmaven.com/wantarray http://perlmaven.com/wantarray If it's so important to visually distinguish the names of scalars and arrays, then shouldn't you also be able to distinguish a string from an int, like BASIC's a$ -vs- i%? So why just distinguish lists and scalars? Why not go all the way to Hungarian Punctuation and use Unicode and Emoji characters to uniquely decorate variables for every other possible built-in and user defined type? https://en.wikipedia.org/wiki/Hungarian_notation#Relation_to_sigils https://en.wikipedia.org/wiki/Hungarian_notation#Relation_to...
- hahainternet 11y agoYou might be a little confused, I'm pretty sure that wantarray and the concept of functions caring about context is entirely gone in Perl 6. Now you are expected to return objects which 'do the right thing'. However, if you really want to do some of the other things you've listed they are possible to do. Perl 6's syntax can be augmented by the programs being executed. I'm honestly interested though, was I ultimately wrong above? Is there a smart way to define a function in python that can take both a single item and a list of items? In Perl 6 I'd just define a multi sub where the list form applies the single item sub for each item in the list.
- DonHopkins 11y agoIt might be gone from Perl 6, but the idea of dividing all possible types into two different classes, and then using punctuation to distinguish variables holding those two classes, is from Perl 5, just like the idea of functions caring about the context of their return value. If Perl 6 is an entirely new language, then why is it riddled with so many bad ideas from another language that only coincidentally shares the first 4 alphabetic characters of its name? Why the artificial scalar/array dichotomy? What is it that is so important about being able to distinguish variables holding scalar-like values and array-like values by punctuation, but it doesn't matter that you can't distinguish variables holding strings and integers by their punctuation? And how can you be consistent about types that act like both scalars and arrays, like strings? Or user defined types that might behave like scalars or arrays but are represented by objects? Are those treated as arrays? Or are they references, treated as scalars? Scalar -vs- array is a false dichotomy that's deeply and unnecessarily embedded in the very syntax of the language.