LWN: Comments on "The Periodic table of Perl operators" https://lwn.net/Articles/319642/ This is a special feed containing comments posted to the individual LWN article titled "The Periodic table of Perl operators". en-us Wed, 10 Sep 2025 19:44:51 +0000 Wed, 10 Sep 2025 19:44:51 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net The Periodic table of Perl operators https://lwn.net/Articles/320226/ https://lwn.net/Articles/320226/ akulkis <div class="FormattedComment"> "Note that a recursive factorial definition can be given in just a few<br> characters:<br> <br> executing 1:`(]*$:@&lt;:) @. * "0 i. 6<br> yields 1 1 2 6 24 120"<br> <p> You write that as if you mistakenly believe that's a good thing.<br> It's not.<br> <p> Read Wirth, and his comments on the unnamed language (obviously a <br> reference to APL) and the cult of developing "one liner" source code<br> which is properly spread across several lines of code (cf "German: A <br> language which crams into one word what is properly stated in a sentance")<br> <p> Nor forget the line from the list of things "Real Programmers(tm)" don't <br> do:<br> <p> Real Programmers don't program in APL because ANYBODY can be obscure in <br> APL.<br> <p> J is nothing more than an even more obfuscated variant of APL.<br> </div> Sat, 21 Feb 2009 13:36:17 +0000 How to short-circuit XOR; gotcha https://lwn.net/Articles/320019/ https://lwn.net/Articles/320019/ Max.Hyre Thanks, both you and <a href="http://lwn.net/Articles/319960/"><b>im14u2c</b></a>. Sure, short-circuiting logical xor is a snap. <p>I, however, was thinking of bitwise xor, hence my confusion. Thu, 19 Feb 2009 16:42:42 +0000 The Periodic table of Perl operators https://lwn.net/Articles/320012/ https://lwn.net/Articles/320012/ jzbiciak <P>I guess <A HREF="http://en.wikipedia.org/wiki/Zipf%27s_Law">Zipf's Law</A> applies to some extent--some things are waaaay more common than others--and it's useful to provide a Huffman-like coding to make common things more efficient. That is, give common tokens compact representations, and uncommon tokens much more verbose representations. (This has the added benefit of introducing folks gently to stuff they may not see very often if the verbose representation is also self-explaining.)</P> <P>For example, one of the things I prefer about C over Pascal is that blocks begin and end with "{" and "}", where in Pascal it's the much more verbose "BEGIN" and "END" keywords. Their information content is low due to their high frequency, so their size should be small. Only early beginners need the concept of "beginning and ending of block" explained. In contrast, it's probably better to name the function "defenestrate_obfuscation()" verbosely, rather than as something compact like "defOb()", since it's unlikely to be encountered often, and the later is impenetrable.</P> <P>One of the things I don't like about some of the more recent programming traditions, such as iterators in C++, is that the code gets very verbose when expressing what ought to be very compact topics. Why spell the start of a list ".begin()" and the end of the list ".end()" if you're going to be using it regularly? It begs for something more compact.</P> <P>Perl 6 (we were talking about Perl 6, right?) has perhaps gone too far in this direction, though. We'll see.</P> Thu, 19 Feb 2009 15:57:56 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319979/ https://lwn.net/Articles/319979/ chromatic <div class="FormattedComment"> I have the opposite preference. I like being able to see the structure of a program -- its parts of speech, if you will. The use of symbols such as sigils and non-word operators gives subtle cues. When I read Lisp or Scheme, I feel like I have to keep a mental stack of operations and their order of execution to understand what's happening.<br> <p> I'm not sure if there's any way to measure this, but I feel like such a language taxes my short term memory more heavily, where an operator- and symbol-rich language such as Perl draws from long term memory and clumping of symbols. (I'm sure experience and preference have great effect here too.)<br> </div> Thu, 19 Feb 2009 09:03:50 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319971/ https://lwn.net/Articles/319971/ eru <i>Tell that to mathematicians.</i> <p> I suspect the reason for their tradition is to make it easier to write mathematics by hand. <p> <i>Naming your index variable "index" is overkill when "i" is widely understood to mean "index,</i> <p> I believe the important consideration is locality, and the frequency of the identifier use. It is OK to give terse names to local temporary variables, but not to a global function, unless the function is very commonly used (like the standard library functions of C). Of course following convention matters also. Using "+" instead of asking the programmer to spell "plus" improves clarity, but not when you then allow the programmer to redefine "+" to mean something different. Thu, 19 Feb 2009 08:00:21 +0000 How do you short-circuit XOR? https://lwn.net/Articles/319960/ https://lwn.net/Articles/319960/ jzbiciak <P>I do believe it's a bug in the chart. <A HREF="http://www.programmersheaven.com/2/Perl6-FAQ-Operators">This page</A> shows the logical XOR operator (^^), but omits "(short circuit)" after it.</P> <P>My first guess is that it's equivalent to the C incantation:</P> <PRE>#define XOR(a,b) ((!!(a)) != (!!(b)))</PRE> <P>That is, the<TT> !!(a) </TT>and<TT> !!(b) </TT>coerce 'a' and 'b' to be boolean values, and then XOR returns "true" when they are unequal.</P> <P>And for the optimization freaks out there, I realize that you don't need the double-not in this case. You could write it as:</P> <PRE>#define XOR(a,b) ((!(a)) != (!(b)))</PRE> <P> So, all the lazy-eval hocus pocus aside, I don't think it's intended to be short-circuit at all. I think it's just meant to be a version of<TT> != </TT>that coerces its arguments to boolean predicates first.</P> <P>Or maybe I'm just projecting something I've wanted several times in C onto what I see in this Perl 6 description. :-)</P> Thu, 19 Feb 2009 06:07:10 +0000 How do you short-circuit XOR? https://lwn.net/Articles/319956/ https://lwn.net/Articles/319956/ jimparis <div class="FormattedComment"> I know little about Perl 6, but I imagine that if you have<br> lazy evaluation, then an implementation of xor like:<br> if (not A) return B;<br> if (not B) return A;<br> return 0;<br> would be short-circuiting because you might only have to evaluate<br> one argument (assuming, again, that you have lazy eval. and returning<br> B doesn't require evaluating B)<br> </div> Thu, 19 Feb 2009 05:24:42 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319951/ https://lwn.net/Articles/319951/ flewellyn <div class="FormattedComment"> Too much syntax in Perl. Too many punctuation marks.<br> <p> I would much rather have things spelled out. I know what "CALL-NEXT-METHOD" means a lot more easily than .* or something.<br> </div> Thu, 19 Feb 2009 03:05:02 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319948/ https://lwn.net/Articles/319948/ quotemstr <div class="FormattedComment"> Let's not forget LISP. Depending on how you look at it, either nothing is an operation, or everything is. :-)<br> </div> Thu, 19 Feb 2009 02:50:33 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319935/ https://lwn.net/Articles/319935/ chromatic <div class="FormattedComment"> Some people complain about Lisp's homoiconicity making the language pretty and every program written in the language ugly. At least with Perl, any ugliness that people see isn't the result of homoiconicity.<br> </div> Thu, 19 Feb 2009 02:04:34 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319922/ https://lwn.net/Articles/319922/ chromatic <div class="FormattedComment"> Perl 6 will have the same. (Rakudo doesn't support that just yet.)<br> </div> Thu, 19 Feb 2009 00:00:31 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319919/ https://lwn.net/Articles/319919/ donbarry <div class="FormattedComment"> Well in APL (and particularly in J) it's not "overloading", it's merely having a rich set of primitives, which can be combined in an extraordinary number of ways, and as in mathematics, few of these are anticipated <br> directly by the authors. J in particular takes this further by <br> building aspects of dynamic metaprogramming into the language -- <br> functions can be composed, mapped across datasets, adjusted with <br> adverbs which affect the rank of data decomposition into the functional<br> maw, even composed into a "gerund" (a functional array) which can be <br> indexed dynamically as it is mapped onto a dataset. <br> <p> Terse? yes. Unreadable? (can be, though putting one trick per line and<br> commenting it gets around this). Powerful? Indescribably so.<br> <p> Unfortunately, the authors of most of these languages' implementations never fell into the free software movement. There are poor APL <br> implementations (and one great implementation of a weakened but sped up<br> APL, A+) and only the single proprietary (but free as beer) J interpreter.<br> <p> </div> Wed, 18 Feb 2009 23:20:53 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319918/ https://lwn.net/Articles/319918/ flewellyn <div class="FormattedComment"> GAH. And people say Lisp is horrible? That hurts my eyes right there!<br> <p> </div> Wed, 18 Feb 2009 23:11:14 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319812/ https://lwn.net/Articles/319812/ jzbiciak <P>Tell that to mathematicians. It seems like the further you go in mathematics, the fewer actual words there are and the more dense the symbology gets. Programming languages like APL seem to come straight from a higher-level mathematics textbook. If your target audience is mathematicians, then allowing them to write in their "native" language can be a plus, not a minus. It might leave the rest of us behind, though. </P><P> Personally, I don't mind single-letter variable names and terse symbols if it doesn't get in the way of clarity. Naming your index variable "index" is overkill when "i" is widely understood to mean "index," and most programmers would have encountered that usage in their early teens in an algebra class. Again, a terse usage first encountered in mathematics, but in this case, widely enough encountered that we should all be familiar with it. </P> Wed, 18 Feb 2009 15:27:15 +0000 How do you short-circuit XOR? https://lwn.net/Articles/319810/ https://lwn.net/Articles/319810/ Max.Hyre I've been away from Perl for a while (to put it kindly). Maybe it's a concept that's been floating around for a while, and I missed it. <p>In column 23 there's a list operator ``xor'' which short circuits. What is the condition for short-circuiting XOR?? Wed, 18 Feb 2009 13:40:18 +0000 Wow! I am overwhelmed https://lwn.net/Articles/319807/ https://lwn.net/Articles/319807/ ctg <div class="FormattedComment"> I think a singularity has been reached; this is both completely whimsical and yet deeply useful. Sublime and ridiculous.<br> <p> </div> Wed, 18 Feb 2009 12:49:23 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319796/ https://lwn.net/Articles/319796/ epa <div class="FormattedComment"> The cool thing about Haskell is that you can define your own operators with pretty much any punctuation characters you want. (I think Perl 6 will have the same but I'm not sure.)<br> </div> Wed, 18 Feb 2009 10:16:35 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319795/ https://lwn.net/Articles/319795/ epa <div class="FormattedComment"> Do remember that this is for Perl 6, which is still in development and not ready for production use yet. Although Perl 5 is not exactly short of operators either...<br> </div> Wed, 18 Feb 2009 10:15:16 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319741/ https://lwn.net/Articles/319741/ eru I have always wondered about this enthusiasm in some languages to overload operator symbols. I think it is equivalent to promoting the use of one-letter function and variable names... Tue, 17 Feb 2009 22:30:02 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319684/ https://lwn.net/Articles/319684/ joey <div class="FormattedComment"> Haskell is also no slouch in the operators department. Even leaving aside that `func` can be used to turn any function into an infix operator. All the custom monadic operators are particularly "fun".<br> </div> Tue, 17 Feb 2009 17:58:04 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319655/ https://lwn.net/Articles/319655/ donbarry <div class="FormattedComment"> You ain't seen nothing yet.. The "quick reference card" for J (a dialect<br> of the grand old language APL, but using the ASCII character set instead<br> of the special greek-laden APL character set) shows its unique look:<br> <a rel="nofollow" href="http://www.jsoftware.com/jwiki/HenryRich?action=AttachFile&amp;do=get&amp;target=J602_RefCard_color_letter_current.pdf">http://www.jsoftware.com/jwiki/HenryRich?action=AttachFil...</a><br> <p> Note that a recursive factorial definition can be given in just a few<br> characters:<br> <p> executing 1:`(]*$:@&lt;:) @. * "0 i. 6<br> yields 1 1 2 6 24 120<br> <p> Perl is positively verbose in comparison.<br> </div> Tue, 17 Feb 2009 16:07:29 +0000 The Periodic table of Perl operators https://lwn.net/Articles/319646/ https://lwn.net/Articles/319646/ asamardzic <div class="FormattedComment"> Amazing... It came to me recently that Mathematica may fare well against Perl with regards to the number of so-called "special syntax" operators available, but after looking into this piece of art - I'd say no way anything (out of more widely used programming systems) could come even close to Perl here :-)<br> </div> Tue, 17 Feb 2009 15:17:14 +0000