Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
"Disappearing" code
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  16 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Siracusa  
View profile  
 More options Jan 9 2003, 8:00 pm
Newsgroups: perl.perl6.language
From: sirac...@mindspring.com (John Siracusa)
Date: Thu, 09 Jan 2003 19:55:20 -0500
Local: Thurs, Jan 9 2003 7:55 pm
Subject: "Disappearing" code
Has there been any discussion of how to create code in Perl 6 that's there
under some conditions, but not there under others?  I'm thinking of the
spiritual equivalent of #ifdef, only Perlish.

In Perl 5, there were many attempts to use such a feature for debugging and
assertions.  What everyone wanted to do was write code like this:

    debug("Doing foo with $bar and $baz");
    foo($bar, $baz);

And then have the entire call to debug() just plain disappear when the
program was run with a certain flag, or when a particular constant was set,
or whatever.  The closest we got in Perl 5, AFAIK, was stuff this:

    use constant DEBUG => 0;
    ...
    debug("Doing foo with $bar and $baz") if DEBUG;
    foo($bar, $baz);

But all those "if DEBUG"s or "DEBUG &&"s were a pain.  So I'm wondering what
the solution will be in Perl 6.

-John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Luke Palmer  
View profile  
 More options Jan 9 2003, 9:48 pm
Newsgroups: perl.perl6.language
From: fibon...@babylonia.flatirons.org (Luke Palmer)
Date: Thu, 9 Jan 2003 19:01:04 -0700 (MST)
Local: Thurs, Jan 9 2003 9:01 pm
Subject: Re: "Disappearing" code

Well, I just do:

  sub debug {
    print STDERR shift, "\n" if DEBUG;
  }

And hopefully (I don't know P5 internals so well) that optimizes to a
no-op so there's not even a function call there.  But it's a
negligible overhead anyway.

> But all those "if DEBUG"s or "DEBUG &&"s were a pain.  So I'm wondering what
> the solution will be in Perl 6.

Not that C code is devoid of C<#ifdef>s everywhere there's conditional
code....

I don't see how you could do much without actually labeling what you
wanted to disappear.  You could always use:

  sub debug(&code) {
    &code() if DEBUG;
  }

For a more versatile and readable solution.  I'm not sure what could
be more concise than that.

Luke


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Siracusa  
View profile  
 More options Jan 9 2003, 9:48 pm
Newsgroups: perl.perl6.language
From: sirac...@mindspring.com (John Siracusa)
Date: Thu, 09 Jan 2003 21:12:07 -0500
Local: Thurs, Jan 9 2003 9:12 pm
Subject: Re: "Disappearing" code
On 1/9/03 9:01 PM, Luke Palmer wrote:

> Well, I just do:

> sub debug {
>   print STDERR shift, "\n" if DEBUG;
> }

> And hopefully (I don't know P5 internals so well) that optimizes to a
> no-op so there's not even a function call there.

I don't know P5 internals so well either, but I'm guessing you'll still get
the function call to debug().

> But it's a negligible overhead anyway.

Hey, it adds up!  Okay, maybe it doesn't...but still, Perl 6 Should Be Able
To Do This! :)  And I'd also like inline constructs like:

    ASSERT $foo > 5 && is_happy(blah);

that may or may not be the same as the debug situation in Perl 6.

> I don't see how you could do much without actually labeling what you
> wanted to disappear.

I basically want a language-level guarantee that the call to debug()
disappears entirely under certain conditions.  I don't want to have to rely
on details of the optimizer or whatever.

-John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Siracusa  
View profile  
 More options Jan 9 2003, 11:48 pm
Newsgroups: perl.perl6.language
From: sirac...@mindspring.com (John Siracusa)
Date: Thu, 09 Jan 2003 23:15:49 -0500
Local: Thurs, Jan 9 2003 11:15 pm
Subject: Re: "Disappearing" code
On 1/9/03 10:10 PM, Michael G Schwern wrote:

> I would assume it to be a compiler hint via subroutine attribute.

>   sub debug ($msg) is off {
>     print STDERR $msg;
>   }

> some "this subroutine is a no-op if a flag is set" attribute.

Hm, not quite as convenient as setting a package global (constant)
somewhere.  Maybe that same "off" bit could be set "from a distance" at
compile time?

-John    


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael G Schwern  
View profile  
 More options Jan 10 2003, 8:49 am
Newsgroups: perl.perl6.language
From: schw...@pobox.com (Michael G Schwern)
Date: Thu, 9 Jan 2003 19:10:03 -0800
Local: Thurs, Jan 9 2003 10:10 pm
Subject: Re: "Disappearing" code

On Thu, Jan 09, 2003 at 07:55:20PM -0500, John Siracusa wrote:
> Has there been any discussion of how to create code in Perl 6 that's there
> under some conditions, but not there under others?  I'm thinking of the
> spiritual equivalent of #ifdef, only Perlish.

> In Perl 5, there were many attempts to use such a feature for debugging and
> assertions.  What everyone wanted to do was write code like this:

>     debug("Doing foo with $bar and $baz");
>     foo($bar, $baz);

I would assume it to be a compiler hint via subroutine attribute.

    sub debug ($msg) is off {
        print STDERR $msg;
    }

some "this subroutine is a no-op if a flag is set" attribute.

--

Michael G. Schwern   <schw...@pobox.com>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <perl...@perl.org>         Kwalitee Is Job One


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael G Schwern  
View profile  
 More options Jan 10 2003, 8:49 am
Newsgroups: perl.perl6.language
From: schw...@pobox.com (Michael G Schwern)
Date: Thu, 9 Jan 2003 20:27:40 -0800
Local: Thurs, Jan 9 2003 11:27 pm
Subject: Re: "Disappearing" code

On Thu, Jan 09, 2003 at 11:15:49PM -0500, John Siracusa wrote:
> On 1/9/03 10:10 PM, Michael G Schwern wrote:
> > I would assume it to be a compiler hint via subroutine attribute.

> >   sub debug ($msg) is off {
> >     print STDERR $msg;
> >   }

> > some "this subroutine is a no-op if a flag is set" attribute.

> Hm, not quite as convenient as setting a package global (constant)
> somewhere.  Maybe that same "off" bit could be set "from a distance" at
> compile time?

That would be the "if a flag is set" part.  Point is, its easily handled
by some sort of subroutine attribute which looks at some flag somewhere.

'off' was a bad name for it.

--

Michael G. Schwern   <schw...@pobox.com>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <perl...@perl.org>         Kwalitee Is Job One


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Siracusa  
View profile  
 More options Jan 10 2003, 9:48 am
Newsgroups: perl.perl6.language
From: sirac...@mindspring.com (John Siracusa)
Date: Fri, 10 Jan 2003 09:35:32 -0500
Local: Fri, Jan 10 2003 9:35 am
Subject: Re: "Disappearing" code
On 1/9/03 11:27 PM, Michael G Schwern wrote:

Well, er, don't we need to decide what the subroutine attribute is, so that
the compiler will know to honor it and make the code "disappear"?  It
doesn't seem like a feature that can be added from "userland" after the fact
(but maybe I'm wrong...)

-John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rafael Garcia-Suarez  
View profile  
 More options Jan 10 2003, 10:00 am
Newsgroups: perl.perl6.language
From: rgarciasua...@free.fr (Rafael Garcia-Suarez)
Date: Fri, 10 Jan 2003 15:56:03 +0100
Local: Fri, Jan 10 2003 9:56 am
Subject: Re: "Disappearing" code

John Siracusa <sirac...@mindspring.com> wrote:

> Well, er, don't we need to decide what the subroutine attribute is, so that
> the compiler will know to honor it and make the code "disappear"?  It
> doesn't seem like a feature that can be added from "userland" after the fact
> (but maybe I'm wrong...)

In Perl 5 that could be done from userland, as you say, by using an
optree manipulator (optimizer.pm for example). This could even be
lexically scoped. [Once the compiler hints are fixed.]

I expect Perl 6 to ship with (Parrot::* ?) modules that allow to examine and
to modify the compiled form of the programs. Something that probably Java 6
will not have...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Brook  
View profile  
 More options Jan 10 2003, 11:48 am
Newsgroups: perl.perl6.language
From: dbr...@easyspace.com (Dan Brook)
Date: Fri, 10 Jan 2003 16:11:39 +0000
Local: Fri, Jan 10 2003 11:11 am
Subject: Re: "Disappearing" code
On Thu, 09 Jan 2003 19:55:20 -0500

John Siracusa <sirac...@mindspring.com> wrote:
> Has there been any discussion of how to create code in Perl 6 that's
> there under some conditions, but not there under others?  I'm thinking
> of the spiritual equivalent of #ifdef, only Perlish.

If the perl6 command-line options are anything like perl5 then you
can just use the -P switch if preprocessor commands are your thing.

> In Perl 5, there were many attempts to use such a feature for
> debugging and assertions.

There has also been a proposal for patching perl5 to add assertions
which was recently discussed[1] on p5p, which if accepted has
implications for assertions in perl6 surely.

Dan

[1]
http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-11/msg003...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Siracusa  
View profile  
 More options Jan 10 2003, 12:48 pm
Newsgroups: perl.perl6.language
From: j...@palmdigitalmedia.com (John Siracusa)
Date: Fri, 10 Jan 2003 11:28:04 -0500
Local: Fri, Jan 10 2003 11:28 am
Subject: Re: "Disappearing" code
On 1/10/03 11:11 AM, Dan Brook wrote:

> On Thu, 09 Jan 2003 19:55:20 -0500
> John Siracusa <sirac...@mindspring.com> wrote:
>> Has there been any discussion of how to create code in Perl 6 that's
>> there under some conditions, but not there under others?  I'm thinking
>> of the spiritual equivalent of #ifdef, only Perlish.

> If the perl6 command-line options are anything like perl5 then you
> can just use the -P switch if preprocessor commands are your thing.

Source filtering is not exactly the solution I'm looking for... :)

-John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Damian Conway  
View profile  
 More options Jan 10 2003, 12:48 pm
Newsgroups: perl.perl6.language
From: dam...@conway.org (Damian Conway)
Date: Fri, 10 Jan 2003 09:24:15 -0800
Local: Fri, Jan 10 2003 12:24 pm
Subject: Re: "Disappearing" code
John Siracusa asked:

Something like this:

        module Debug;

        my $debugging = 1;

        method import ($debug) { $debguuging = $debug }

        sub debug is immediate is exported (@message) {
            return $debugging ?? { print $*STDERR: @message; } :: {;}
        }

then:

        use Debug;

        debug("Doing foo with $bar and $baz");

and to deactivate the debug statements:

        use Debug 0;

        debug("Doing foo with $bar and $baz");

"Immediate" subroutines are executed as soon as they are parsed (i.e. they're
like named BEGIN blocks).

Returning a closure/block from an immediate sub called in a void context
(as C<debug> is in the example above) causes the immediate sub call to be
replaced -- during compilation! --  by the returned closure/block.

Voila! Perl 6 is its own macro language.

Damian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Siracusa  
View profile  
 More options Jan 10 2003, 1:00 pm
Newsgroups: perl.perl6.language
From: sirac...@mindspring.com (John Siracusa)
Date: Fri, 10 Jan 2003 12:50:27 -0500
Local: Fri, Jan 10 2003 12:50 pm
Subject: Re: "Disappearing" code
On 1/10/03 12:24 PM, Damian Conway wrote:

> "Immediate" subroutines are executed as soon as they are parsed (i.e. they're
> like named BEGIN blocks).

> Returning a closure/block from an immediate sub called in a void context
> (as C<debug> is in the example above) causes the immediate sub call to be
> replaced -- during compilation! --  by the returned closure/block.

> Voila! Perl 6 is its own macro language.

Sweet :)

-John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Fox  
View profile  
 More options Jan 12 2003, 6:48 pm
Newsgroups: perl.perl6.language
From: k...@vulpes.com (Ken Fox)
Date: Sun, 12 Jan 2003 18:32:34 -0500
Local: Sun, Jan 12 2003 6:32 pm
Subject: Re: "Disappearing" code

Damian Conway wrote:
>     sub debug is immediate is exported (@message) {
>         return $debugging ?? { print $*STDERR: @message; } :: {;}
>     }

Won't @message need lazy evaluation? How will Perl know to
delay interpolation until the result of the "macro" is called
at run time?

- Ken


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Damian Conway  
View profile  
 More options Jan 12 2003, 7:48 pm
Newsgroups: perl.perl6.language
From: dam...@conway.org (Damian Conway)
Date: Sun, 12 Jan 2003 16:03:56 -0800
Local: Sun, Jan 12 2003 7:03 pm
Subject: Re: "Disappearing" code

Ken Fox wrote:
> Won't @message need lazy evaluation? How will Perl know to
> delay interpolation until the result of the "macro" is called
> at run time?

Good point. It would also need to be slurped.
So that's:

      sub debug is immediate is exported (*@message is lazy) {
           return $debugging ?? { print $*STDERR: @message; } :: {;}
      }

Damian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Piers Cawley  
View profile  
 More options Jan 14 2003, 8:49 am
Newsgroups: perl.perl6.language
From: pdcaw...@bofh.org.uk (Piers Cawley)
Date: Tue, 14 Jan 2003 10:56:38 +0000
Local: Tues, Jan 14 2003 5:56 am
Subject: Re: "Disappearing" code

So, one could implement 'assert' in the same package with something
like:

   sub assert is immediate is exported
             ( rx/<expr>/ &expr ; $message = "Assertion failed " )
   {
       return $debugging ?? { &expr() || die $message } :: { ; }
   }

For bonus points one could have the assertion die if it's called in a
non void context, but I'll leave that as an exercise for the
interested reader.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Formosa  
View profile  
 More options Aug 19 2005, 10:07 pm
Newsgroups: perl.perl6.language
From: dform...@dformosa.zeta.org.au (David Formosa)
Date: 20 Aug 2005 02:07:02 -0000
Local: Fri, Aug 19 2005 10:07 pm
Subject: Re: "Disappearing" code
On Thu, 09 Jan 2003 21:12:07 -0500, John Siracusa

<sirac...@mindspring.com> wrote:

[...]

> Hey, it adds up!  Okay, maybe it doesn't...but still, Perl 6 Should Be Able
> To Do This! :)  And I'd also like inline constructs like:

>     ASSERT $foo > 5 && is_happy(blah);

macro debug ($code) is parsed (/{Perl6::Block}/) {
  if ($debug) {
    $code
  } else {
     ""
  }

}

--
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »