Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Apocalypse 3

by Masem (Monsignor)
on Oct 04, 2001 at 02:00 UTC ( #116581=perlmeditation: print w/replies, xml ) Need Help??

Larry's Apocalypse 3 is now available. 'Nuf said :-)

(Actually, a lot of odds and ends, many dealing with the 'appearence' of the language rather than mechanics).

Dr. Michael K. Neylon - || "You've left the lens cap of your mind on again, Pinky" - The Brain
It's not what you know, but knowing how to find it if you don't know that's important

Replies are listed 'Best First'.
Re: Apocalypse 3
by blakem (Monsignor) on Oct 04, 2001 at 02:14 UTC
    I grepped it for the forbidden information that put my life in jeopardy a few days ago:

      Binary //
      A binary // operator is the defaulting operator. That is:

      $a // $b
      is short for:

      defined($a) ?? $a :: $b # [note: this is the new ?: -- bla +kem]
      except that the left side is evaluated only once. It will work on arrays and hashes as well as scalars. It also has a corresponding assignment operator, which only does the assignment if the left side is undefined:
      $pi //= 3;
    That's actually quite cool... currently when people use $a ||= b they often times really mean $a = defined ($a) ? $a : $b and now we'll have an easy way to do it..

    //= gets a ++ in my book


      So we finally get the hook operator as debated on p5p a long while ago. Thank you Larry :-)

      Blessed Be
      The Pixel

      What if you want to divide by a regex? That could also have two slashes after a term.
        Perl might try to correct the parsing of:
        $x = $y //foo/;
        $x = $y // foo/;
        $x = $y / /foo/;

        Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
        s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

        /// or // should be more like s/// or m//

        but what is $foo // or $brr /// (nothing if i remember correctly)

         $foo // expr has nothing to do with regex

        oh "divide" by a regex, mmmkay, maybe something like

        $_ = "2k4"; print ( 49 / /\d/); #?

        (i can't see how what you're suggesting can occur, or i'm misunderstanding)

        Can you give one example where dividing by a regexp is not hopelessly obfuscatory? If I saw someone trying to do that in production code, I would hesitate between shooting them first and then throwing them out the window, or doing it the other way around :)

        Although I would be slightly more worried about the ambiguity between // "that unless defined this" and // "rematch according to the last successfully compiled regexp" (although maybe that's going away in Perl 6, I've lost track). And anyway, I'll let Larry and Damian worry about that for the time being.

        g r i n d e r
Re (tilly) 1: Apocalypse 3
by tilly (Archbishop) on Oct 04, 2001 at 16:32 UTC

    :=, laziness, he is thinking big. I hope he thinks through the consequences. Otherwise he may just find me submitting a bug report about the following code:

    $x := $y + 5; $y := $x -3; print "Answer: ($x, $y)\n";
    Unless, of course, it works. In which case I shall probably sacrifice burnt offerings at TheDamian's altar. (And then try to break it with a non-linear system of equations.)

    In a similar and more reasonable vein, I hope that his thinking about laziness, :=, and slice mechanics goes far enough that you can readily (for instance) define the Fibonacci sequence as a lazy list and have it work right...

      I'm afraid := isn't the fully fledged unification operator you're hoping for. As I'll explain in Exegesis 3, it's really just an aliasing mechanism.

      So your declarative emergent $x and $y values aren't actually being declared, or emerging either. :-(

      In fact, you'd just get $x aliased to the (constant) result of $y+5 (which will be 5 if there's no prior assignment to $y), and then $y aliased to the (constant) result of $x-3 (which will be 2 under the previous assumption).

      However, as a consolation prize for having suggested human sacrifice to me (you did intend it to be a human burnt offering, didn't you???), I have now added a Data::Unification module to my ToDo list. ;-)


        Hi Damian,

        In the Section "Applied Laziness 101" of the third Exegesis, you wrote:
        Of course, if we'd written:

        my ($name, $vers, $status, $costs, @and_the_rest) = <fh>;

        The the entire file would have been read
        Did you mean:

        my ($name, $vers, $status, $costs, *@and_the_rest) = <fh>;

        or will array assignment work differently on the diamond operator?

        Simon Flack ($code or die)
        $,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
        =~y'_"' ';eval"die";print $_,lc substr$@,0,3;
Re: Apocalypse 3
by chipmunk (Parson) on Oct 06, 2001 at 19:15 UTC
    Maybe I just haven't gotten my head around these new semantics for colons, but I can't resolve the described uses of colon with a function call, both for following an indirect object and for preceding an adverb.

    First, Damian explains that colon is used to mark the indirect object for print: print $filehandle : $text_to_print; Later, Damian explains that colon is used to mark the adverb for a function: print sum @numbers_to_sum : $filter; In the first case, the syntax is function indirect-object : direct-object, and in the second case function direct-object : adverb. How is this apparent ambiguity resolved?

      ...colon is used to mark the indirect object...colon is used to mark the adverb...How is this apparent ambiguity resolved?

      Is a pebble on the road
      To enlightenment.

      There is no "adverb",
      Nor an indirect object,
      Nor direct objects.

      There's only colon --
      With arguments before it
      And others after.

      What we call those args --
      "Indirect", "adverb", "direct" --
      Is pure convention.

      It's up to each sub
      To decide how arguments
      Are interpreted.

      print may choose to treat
      Pre-colon as filehandle,
      Post-colon as list.

      On the other hand,
      sum might choose: Pre-colon -- list,
      Post-colon -- adverb.

      It's like the story
      Of two monks and Hui-neng
      Discussing a flag:

      "The flag is moving?"
      "Or is it the wind moving?"
      "It's your mind that moves!"

      Now we have the tale
      Of Chipmunk-san and Con Wei
      Discussing colons:

      "Colons mean 'adverb'?"
      "Colons mean 'indirectly'?"
      "Colons mean...colon!"

      It's how you use them
      In your sub that determines
      What purpose they serve.

        O Con Wei sama
        your noble way of speaking
        how did you learn it?

Re: Apocalypse 3
by petral (Curate) on Oct 05, 2001 at 23:07 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://116581]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2021-12-07 00:22 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (33 votes). Check out past polls.