Slashdot Mirror


Periodic Table of the Operators

mAsterdam writes "At his code blog Mark Lentcner writes: "A while back, I saw Larry Wall give a short talk about the current design of Perl 6. At some point he put up a list of all the operators - well over a hundred of them! I had a sudden inspiration, but it took a few months to get around to drawing it..." You might want to take a look at this and think about which operators are yet to be discovered."

34 of 323 comments (clear)

  1. the pdf file by eille-la · · Score: 3, Informative

    http://www.ozonehouse.com/mark/blog/code/PeriodicT able.pdf

    I the only one who saw the adobe acrobat plugin for firefox on his knees loading this?

    1. Re:the pdf file by maswan · · Score: 4, Informative
      I put up a mirror of that file here: PeriodicTable.pdf

      The current server seems a bit slow to respond, so..

      /Mattias Wadenstein

  2. Oh my sweet Jesus... by btlzu2 · · Score: 5, Interesting

    This cannot mean good things for Perl. Look at all of those operators!!!! Correct me if I'm wrong, but isn't that pretty onerous to have a huge chart of possible operators for a language? I'd quite prefer simplifying over adding multiple combinations of ways to doing things. That code is gonna be NASTY.

    All the more reason for me (IMO) to avoid Perl like the plague.

    --
    Zed's dead baby. Zed's dead.
    1. Re:Oh my sweet Jesus... by BokLM · · Score: 4, Insightful

      If you don't want more than one way to do it, then Perl is not for you ...

    2. Re:Oh my sweet Jesus... by mcc · · Score: 4, Insightful

      come on.. different types of compare operators that work on regular variables (one for numbers, one for strings)? Can't the interpreter just say "Oh, one of these is a string, internally.

      This duality is already a feature of Perl and it actually is a necessity. The reason is that string compare and numeric compare are different desired operations.

      Let us say that perl used == for both string and numeric compare. Now let us say that someone wrote the following statement in a perl program: "3.0" == "3". Does this return true or not? If we perform a numeric compare, then yes. If we perform a string compare, then no. Now, you can point at my example and say that since 3 and 3.0 were both quoted here, clearly the programmer intended for 3 and 3.0 to be treated as strings. However, if rather than literals those had been variables-- maybe taken from user input-- that would have been no such indicators. The language has no way to tell what to do.

      This really so much isn't about types as it is about the fact perl will autobox numbers in and out of strings for you. I'll give you Perl has many features that just make one's head hurt, but this isn't one of them.

    3. Re:Oh my sweet Jesus... by HeghmoH · · Score: 3, Insightful

      That's all fine and good until you have to read or modify somebody else's code. Then you're in for a world of trouble, because the operators you like to use and the operators he likes to use will not be the same, and you'll have to look them up.

      If you never get beyond hobby programming, of course, then this is almost never an issue.

      --
      Mod down posts with a "Free Mac Mini/iPod" sig, they're spam!
    4. Re:Oh my sweet Jesus... by Jerf · · Score: 4, Insightful

      However, if rather than literals those had been variables-- maybe taken from user input-- that would have been no such indicators.

      Here is where your argument falls down. Proof by construction: There are a large number of languages of every variety that still manage to have types for that input.

      Your argument is more accurately described as:

      "Perl actively tries to avoid giving types to strings and numbers, and as a result of this desire to not distinguish between the two, the onus is on the programmer to do so. That's how the language solves this problem that other languages solve through stronger typing."

      At this point, one can then go on and debate whether or not this is a good thing, but don't pretend that Perl has no choice. It had all kinds of choice and deliberately chose this system, most likely for backwards programmer compatibility with awk and its other predecessors.

      Perl isn't "autoboxing"; that's a technical term that means that you take simple C++ or Java style scalars and automatically wrap them in an object. Perl is dynamically "looking at" the object as either a number or a string, depending on context; thus, to the programmer, every string is also a number (albiet usually 0) and every number is also a string.

    5. Re:Oh my sweet Jesus... by imroy · · Score: 4, Informative

      You're thinking about strongly typed languages e.g C, C++, Java, C#. In those language variables are only ever of one type. When copying from one type to another, or comparing different types, there are strict rules of "promotion" (i.e we always promote to higher-precision types).

      Perl is a weakly typed language. There's three main variable types: scalar, list (array), and hash (associative array). Scalars can be both numerical and text strings at the same time. This is the reason that Perl has different equality tests for numbers and strings. The run-time has to to be explicitly told which comparison to use. For an example of how not to handle this situation, just look at the way PHP does it. When a language is weakly typed, the interpreter/run-time loses information about how certain things are to be done with variables. That information loss must be made up somwhere. In this case, it's the operators.

    6. Re:Oh my sweet Jesus... by mcc · · Score: 5, Insightful

      "Perl actively tries to avoid giving types to strings and numbers, and as a result of this desire to not distinguish between the two, the onus is on the programmer to do so. That's how the language solves this problem that other languages solve through stronger typing."

      Stronger typing does not automatically solve this particular issue. Look at, for example, C. It uses == for numeric compare and strcmp() for string compare. Strong typing does not help here; ==, as in perl, means only one thing, and that one thing is "compare two numbers".

      Now, you *can* in C++ overload the == operator on a string class you create-- or in Java the equals() method-- to do custom comparisons on specific types. However this then brings up the question of what happens if for some reason you want to do a numeric compare between two string objects. You have to somehow do a conversion to a different object type. Perhaps this is a bit clumsy. So yes, certain applications of strong typing lead to a potential way to trick the language into allowing you to perform the two different operations of string and numeric comparison with only a single operator. However you have unfortunately in doing so introduced ambiguity into your definition of equality. This does not necessarily seem like a win to me.

      It is worth noting that Perl 6 offers the opportunity to strongly type your variables, and this includes numeric types. However it still uses the separate == and eq operators for numeric and string compare even when this strong typing is effect, simply as a design choice. I think this is a good one: there are already far too many situations where an operator or function in Perl behaves in different ways depending on minor details of the context, we do not need another. Again, I assure you, you are better off going to find some other grounds on which to attack Perl. You will not have to look long.

      Incidentally, I used the term "autoboxing" in the sense that Perl is automatically converting data entities from string to numeric types (yes, the variables may not be "typed", but the data certainly can be said to be). I was not aware the term "autobox" referred only to conversions between object and non-object types. Oops.

  3. Undiscovered: the /. operator by thomasdelbert · · Score: 4, Funny

    The /. operator is the one that causes your system to grind to a halt.

    - Thomas;

    --
    ___ This sig is in boldface to emphasize its importance!
  4. PDF mirror by Cond0r · · Score: 5, Informative

    A mirror location for the PDF of the periodic table: http://condor.madoka.be/various/PeriodicTable.pdf

  5. I looked all over. by Phidoux · · Score: 5, Funny

    Where is the WTF operator?

    1. Re:I looked all over. by thomasdelbert · · Score: 3, Funny
      Where is the WTF operator?
      Here:

      ($p?(/.{70}\|$/):(/^\|/))||(&{$\[3]}<$/[0])?($p=!$ p):&{$\[$p]}||die("$d");

      - Thomas;
      --
      ___ This sig is in boldface to emphasize its importance!
    2. Re:I looked all over. by Temporal · · Score: 3, Funny

      Man... someday someone is going to write an obfusicated perl version of "rm -rf *" and post it on slashdot, and everyone is going to fall for it.

  6. Some of these have a halflife of a few nanoseconds by JCCyC · · Score: 5, Funny

    Code written with them becomes illegible after that.

  7. Perl 6 by Anonymous Coward · · Score: 5, Funny

    Perl 6 is going to be the best thing that ever happened to Python.

    1. Re:Perl 6 by aurelien · · Score: 3, Insightful

      http://www.underlevel.net/jordan/erik-perl.txt

      it stands for itself...

      * ; ; ; h e l m e r . . .
      | I have been slowly learning lisp over the past year and have had someone
      | mention to me that I should learn perl, for jobs etc.

      the unemployed programmer had a problem. "I know", said the programmer,
      "I'll just learn perl." the unemployed programmer now had two problems.

      having a job is not unimportant, but if knowing perl is a requirement for
      a particular job, consider another one before taking that one. this is
      true even if you know perl very well. life is too long to be an expert
      at harmful things, including such evilness as C++ and perl.

      I once studied perl enough to read perl code and spot bugs in other
      people's programs (but later gained the wisdom that this was not an
      accomplishment -- spotting a bug in a perl program is like spotting the
      dog that brought the fleas), but I don't write in it and I don't ever
      plan to use it for anything (part of my new position is quality assurance
      for the systems I'm inheriting responsibility for, and part of any
      serious QA is removing perl code the same way you go over a dilapidated
      building you inherit to remove chewing gum and duct tape and fix whatever
      was kept together for real). also, very much unlike any other language I
      have ever studied, perl has failed to stick to memory, a phenomenon that
      has actually puzzled me, but I guess there are some things that are so
      gross you just have to forget, or it'll destroy something with you. perl
      is the first such thing I have known.

      this is your brain. this is perl. this is your brain on perl. any
      questions?

      | If I learn lisp well will I be able to do what people do with perl[?]

      no, you won't. however, there is a very important clue to be had from
      this: what people do with perl is wrong. perl makes a whole lot of tasks
      easy to do, but if you look closely, you will see that those tasks are
      fundamentally braindamaged, and should never have been initiated. perl
      is perhaps the best example I can think of for a theory I have on the
      ills of optimization and the design choices people make. most people,
      when faced with a problem, will not investigate the cause of the problem,
      but will instead want to solve it because the problem is actually in the
      way of something more important than figuring out why something suddenly
      got in their way out of nowhere. if you are a programmer, you may reach
      for perl at this point, and perl can remove your problem. happy, you go
      on, but find another problem blocking your way, requiring more perl --
      the perl programmer who veers off the road into the forest will get out
      of his car and cut down each and every tree that blocks his progress,
      then drive a few meters and repeat the whole process. whether he gets
      where he wanted to go or not is immaterial -- a perl programmer will
      happily keep moving forward and look busy. getting a perl programmer
      back on the road is a managerial responsibility, and it can be very hard:
      the perl programmer is very good at solving his own problems and assure
      you that he's on the right track -- he looks like any other programmer
      who is stuck, and this happens to all of us, but the perl programmer is
      very different in one crucial capacity: the tool is causing the problems,
      and unlike other programmers who discover the cause of the problem sooner
      or later and try something else, perl is rewarding the programmer with a
      very strong sense of control and accomplishment that a perl programmer
      does _not_ try something else.

      it's not that perl programmers are idiots, it's that the language rewards
      idiotic behavior in a way that no other language or tool has ever done,
      and on top of it, it punishes conscientiousness and quality

      --
      aurelien
  8. The Elements - Tom Lehrer by Richard_L_James · · Score: 3, Funny
    which operators are yet to be discovered.

    The sentance reminded me of the Elements song.... No doubt someone has already started rewriting it for Perl !

  9. Relevant excerpt from the INTERCAL language manual by mcc · · Score: 4, Funny

    TONSIL A (1)

    The Official INTERCAL Character Set

    Tabulated on page XX are all the characters used in INTERCAL, excepting
    letters and digits, along with their names and interpretations. Also
    included are several characters not used in INTERCAL, which are presented
    for completeness and to allow for future expansion.

    Character Name Use (if any)

    . spot identify 16-bit variable
    : two-spot identify 32-bit variable
    , tail identify 16-bit array
    ; hybrid identify 32-bit array
    # mesh identify constant
    = half-mesh
    ' spark grouper
    ` backspark
    ! wow equivalent to spark-spot
    ? what unary exlusive OR (ASCII)
    " rabbit-ears grouper
    ". rabbit equivalent to ears-spot
    | spike
    % double-oh-seven percentage qualifier
    - worm used with angles
    < angle used with worms
    > right angle
    ( wax precedes line label
    ) wane follows line label
    [ U turn
    ] U turn back
    { embrace
    } bracelet
    * splat flags invalid statements
    & ampersand[5] unary logical AND
    V V unary logical OR
    (or book)
    V- bookworm unary exclusive OR
    (or universal qualifier)
    $ big money unary exclusive OR (ASCII)
    c| change binary mingle
    ~ sqiggle binary select
    _ flat worm
    overline indicates "times 1000"
    + intersection separates list items
    / slat
    \ backslat
    @ whirlpool
    -' hookworm
    ^ shark
    (or simply sharkfin)
    #|[] blotch

    Table 2 (top view). INTERCAL character set.

    (1) Since all other reference manuals have Appendices, it was decided that
    the INTERCAL manual should contain some other type of removable organ.

    (2) This footnote intentionally unreferenced.

  10. PDF Mirror by technix4beos · · Score: 3, Informative

    I'm also hosting the PDF directly, here:

    PeriodicTable.pdf

    --
    user@host$ diff /dev/urandom /dev/uspto
  11. Awful! XD by Apage43 · · Score: 4, Insightful

    Take a look at this, then take a look at a real periodic table. Yup, that's right, a list of the operators of perl are more complicated than a list of all the atoms that make up everything around you. Mirror (Bittorrent so I wont get myself /. ed) http://www.raiden.se/download/1541/PeriodicTable.p df.torrent

  12. Can't seem to find it... by mcc · · Score: 4, Funny

    We may have to wait for Perl 7 for that one. However, if you look under "Quasi Variables/Templars", you will find there is a "yadda, yadda, yadda" operator.

  13. Operators considered optional. by mcc · · Score: 5, Insightful

    One of the underlying philosophies about perl is to give the user as many options for doing things as is concievably possible. However, there's certainly no reason you have to take these options or, generally, to know those options are there. I repeat: you do not have to know these operators to use perl 6. There is almost nothing on this entire graph for which you could not get the same functionality in a more clean and readable manner by just doing it a different way.

    There is no doubt that a cleaner and more consistent language would arise from putting all the language functionality into clear and well-organized paths that everyone would use and recognize in exactly the same way. However the thing is, that is not what many people want. And I would posit that the popularity of perl proves that that is not what people want. While this chart may horrify many programmers, the simple fact is that one of the main reasons for the popularity of perl is the freedom offered by all of its shortcuts and bizarre little unnecessary operatorss. Someone programming in, say, Java, will find themselves often having to stop, scratch their heads, and try to remember or look up the method or class in the standard library used to do some trivial thing, or write a trivial function to do it themselves. While the perl programmer just scribbles out &$g =~ /(.)/g or the first thing that comes to their mind and moves on.

    Perl 6's one big problem, from my perspective, is that the language is *so* big that it's unlikely or impossible any one person will be familiar with all of its features. However one of these features-- which is either horrible or very attractive depending on how you look at it-- is that it offers you the opportunity to redefine the syntax. My personal theory is that many organizations which decide to adopt perl 6 internally will use this to just cut out large swaths of the language, cutting perl 6 down to something more streamlined and manageable. That is, in order to ensure everyone can read each other's code, they will be able to just set certain coding standards-- for example, "don't use hyper operators" or "don't alter the perl grammar"-- and then enforce this by requiring everyone to include a lib that simply removes these features from the language. Do something like this, and you're left with a language which is readable yet still perfectly functional and still more attractive in many ways than many other languages.

    This doesn't help though with the reason this is a big problem, though: code reuse. Perl 6 offers so many options that code written by another person or another organization, when it falls in your hands may sometimes appear to have been written in a different language than the one you are used to. And if people have been taking advantage of the syntax-redefinition features, it will literally be in a different language. However, I suspect this will not be an intractable problem for one reason. Perl 6 offers a very robust object system; it is likely that most of the code reuse in perl 6 will be done through modularity and incorporation of objects, rather than simple cut and paste code reuse. This is in fact generally the way that things work in perl 5; people just modularize everything, and learn not to poke too closely at the internals of any class they're given to work with, looking only at the perldocs. Weirdly, despite the illegible code (or perhaps because of it), the perl culture, or at least the perl module community, seems to have developed a tendency to write very exhaustive documentation. Anyhow, we shall see what happens.

    One last thing. This chart is not as bad as it seems. Most of the size of this chart stems from the explosion of "operators" caused by the addition into perl 6 of APL-style "adverbial operators". (I believe the user may define their own adverbs, but I am not sure.) This means that many of the operators on this list are actually compound operators-- for example, the "add the contents of two lists" oper

  14. Re:Some of these have a halflife of a few nanoseco by BerntB · · Score: 3, Insightful
    Oh, get real. Many of them should IMHO not be operators; the file tests ('-r', etc) are probably there because of compatibility w Perl 5.

    But most stuff are quite logical and easy to pick up for a Perl 5 programmer like
    boolean operators, ... (yada yada yada), etc.

    Lots are straight Perl 5, like
    eq, ne, ( .. list ..), { }-use, []-use, \, etc.

    quite a few are pure C (and Perl 5), like
    --, ++, +=, ==, !=, &&, ||, |=, [array access], etc.

    In short, it's not that different from Perl 5. An indication on the periodic table for what is different from Perl 5 would have been very useful.

    Author, please?

    --
    Karma: Excellent (My Karma? I wish...:-( )
  15. Re:Brace yourself... by Dr.+Zowie · · Score: 4, Informative

    Why is "?:" spelled "??::" ?
    Because "?:" is a logical (short-circuit; control flow) operator. The newer spelling makes it look more like "&&" and "||".
    Why is "&&" different from "and"? Ditto for "||" and "or", etc.
    Precedence, my friend, precedence. That already exists in perl 5. The spelled-out operators have much lower precedence than && and friends -- so you can say
    if( $a = shift and $a=~m/foo/ ) { ... }
    conveniently. ($a gets the shifted value, not the boolean AND of the shifted value and the match).
    "." is now "~"?
    Well, three good ones out of four ain't bad... IMHO this is dumb. The reason is that "->" is now "." (saving some keystrokes, I suppose) -- but I'd rather leave both operators as-is.
    Charwise operators?
    Yes, excellent stuff! I believe that this is actually driven by the PDL application -- there, you have large arrays (e.g. several million entries) and want to do vast vectorized operations on them. Currently PDL uses the perl 5 bitwise operators for vectorized ops -- but that's not a perfect fit, since sometimes you do actually want bitwise operations.

  16. If you think this is scary... by dexter+riley · · Score: 3, Funny

    ...remember that unlike Perl operators, you can't overload the chemical elements. Imagine if He meant helium, unless some chemist changed its definition to mean Mercury, or Ununtrium, or anything else!

    Mmm, a bottle of good old H2O! Glug glug. What's this small print? "The oxygen in this molecule has been overloaded to be radioactive, caustic, and-" ack!
    Thud.

    1. Re:If you think this is scary... by pjt33 · · Score: 3, Funny

      Dexter used to drink a lot, but now he drinks no more:
      For what he thought was H2O was H2SO4.

  17. Re:Brace yourself... by This+Is+Ridiculous · · Score: 3, Insightful
    Why is "?:" spelled "??::"?
    Larry Wall felt that inline if wasn't a common enough operation to lose both question mark and colon to. He also likes to point out that, like || and &&, ??:: is a short-circuiting logical operator.
    Why is "&&" different from "and"? Ditto for "||" and "or", etc.
    Different precedence levels. This already exists in Perl 5.
    "." is now "~"?
    Yes. Larry wanted dot to be used for method calls, since objects are becoming much more prevalent in Perl 6. The tilde wasn't being used for anything terribly important (1's complement), so he stole it and made something else do 1's complement; it's supposed to remind you of a little piece of string.
    Charwise operators?
    Allow you to treat a string as a bit vector and perform bitwise operations on it. You can already do this in Perl 5 with the normal bitwise ops--Larry just split them out into separate operators for Perl 6.
    And just to be pedantic, shouldn't all the "op=" operators be described as molecules formed from "op" and "="?
    Yes, as should the bool/int/bitstring ops, and a lot of other things. That, IMHO, is the main flaw of this table, although I don't really know how to do it better.
    --
    Hey, you try to find an open nick these days!
  18. huh? by gumbi+west · · Score: 3, Insightful
    Okay, can someone explain to me what it means to be to the right or left of another opperator? What is periodic about this table?

    The amazing properties of the periodic table was that you could predict properties of elements that had not yet been discovered, and this amazing property is of use today. For example, we can predict that, chemically, strontium makes a good calcium analog because they are in the same column, and we are right! Strontium is often found in bones where calcium normally is. (this was important when there was a lot of radioactive strontium in fallout and when it decayed it didn't hold the bone together as well.)

    Anyway way, for other properties, next-to relationships are importantand also allows for predictions to be made.

  19. This is a beautiful diagram by dozer · · Score: 4, Interesting

    Excellent antialiasing, excellent fonts with good kerning, great drop shadows, lots of repititive work assembled pretty much flawlessly... This chart gets an A+ for style (which is pretty rare in the non-Mac Unix world).

    Does anybody know the tool Mark Lentcner used to make it? Illustrator? Could I be so bold as to hope that Sodipodi or Inkscape are now capable of something like this?

    1. Re:This is a beautiful diagram by MtnViewMark · · Score: 3, Informative

      Thank you for the kind comments.

      I used Omnigraffle 3 (standard edition) running on Mac OS X (10.3).

      - Mark

    2. Re:This is a beautiful diagram by toby · · Score: 3, Interesting
      lots of repititive work assembled pretty much flawlessly
      Except for the odd typo (e.g. in junctive elements) - not to disparage a neat, humorously executed piece of work and a clever idea.
      Could I be so bold as to hope that Sodipodi or Inkscape are now capable of something like this
      Hand-coded PostScript is quite capable of this :-) Certainly the PS greybeards pulled off even fancier things that way - 3D with hidden surface removal, etc.

      --
      you had me at #!
  20. unfortunately, you still have to READ others' Perl by mkcmkc · · Score: 5, Insightful
    you do not have to know these operators to use perl 6

    Unfortunately, you still have know these operators in order to READ Perl code written by other programmers.

    Perl 5 is already conceptually too large to use. Perl 6 just takes things completely over the top.

    Mike

    --
    "Not an actor, but he plays one on TV."