Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
turning off warnings for a function's params?
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
  5 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
 
David Storrs  
View profile  
 More options Apr 24 2005, 10:50 pm
Newsgroups: perl.perl6.language
From: dsto...@dstorrs.com (David Storrs)
Date: Sun, 24 Apr 2005 19:50:01 -0700
Local: Sun, Apr 24 2005 10:50 pm
Subject: turning off warnings for a function's params?
I image we've all written logging code that looks something like this
(Perl5 syntax):

  sub foo {
      my ($x,$y) = @_;
      note("Entering frobnitz().  params: '$x', '$y'");
      ...
  }

This, of course, throws an 'uninitialized value in concatenation or
string' warning when your test suite does this:

  is( foo(undef, undef), undef, "foo(undef, undef) gives undef" );

In a testing environment, I don't want to see this warning.  In a
production environment, I do.  Furthermore, when I want it gone, I
want it gone from every instance of C<note>, without having to change
something in every location.  I suppose I could change all my logging
calls to look like this:

  {
    if ( $DEBUG ) { no warnings 'uninitialized'; note("...."); }
    else { note("...."); }
  }

But that's really ugly, takes up a lot of space, is confusing, and is
redundant.

How would I best solve this problem in Perl6?

--Dks

--
dsto...@dstorrs.com


    Reply to author    Forward  
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 Apr 25 2005, 7:18 am
Newsgroups: perl.perl6.language
From: l...@luqui.org (Luke Palmer)
Date: Mon, 25 Apr 2005 05:18:11 -0600
Local: Mon, Apr 25 2005 7:18 am
Subject: Re: turning off warnings for a function's params?

Of course, no ordinary definition of a note() sub will work, since the
concatenation happens before note is even touched.  However, a macro
could do it.  It might go something like this:

    macro note(Perl::Expression $expr)
        is parsed(/$<expr> := <Perl.arglist(:(Str))>/)
    {
        $expr.compile(:warnings(0));
    }

Luke


    Reply to author    Forward  
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 Storrs  
View profile  
 More options Apr 25 2005, 1:00 pm
Newsgroups: perl.perl6.language
From: dsto...@dstorrs.com (David Storrs)
Date: Mon, 25 Apr 2005 10:00:16 -0700
Local: Mon, Apr 25 2005 1:00 pm
Subject: Re: turning off warnings for a function's params?

On Mon, Apr 25, 2005 at 05:18:11AM -0600, Luke Palmer wrote:
> David Storrs writes:
> >   sub foo {
> >       my ($x,$y) = @_;
> >       note("Entering frobnitz().  params: '$x', '$y'");
> >       ...
> >   }
> > This, of course, throws an 'uninitialized value in concatenation or
> > string' warning when your test suite does this:
> >   is( foo(undef, undef), undef, "foo(undef, undef) gives undef" );
> > How would I best solve this problem in Perl6?

> Of course, no ordinary definition of a note() sub will work, since the
> concatenation happens before note is even touched.  

Exactly; that's why I asked "how would I solve this", instead of "how
would I write note()".

> However, a macro could do it.  It might go something like this:

>     macro note(Perl::Expression $expr)
>         is parsed(/$<expr> := <Perl.arglist(:(Str))>/)
>     {
>         $expr.compile(:warnings(0));
>     }

> Luke

Cool.  But that seems to turn off all warnings during the compilation
of the expression--I only want to get rid of the (expected)
'uninitialized' warning.  Will there be a way to do finer-grained
control?

--Dks
--
dsto...@dstorrs.com


    Reply to author    Forward  
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.
Juerd  
View profile  
 More options Apr 25 2005, 1:10 pm
Newsgroups: perl.perl6.language
From: ju...@convolution.nl (Juerd)
Date: Mon, 25 Apr 2005 19:10:49 +0200
Local: Mon, Apr 25 2005 1:10 pm
Subject: Re: turning off warnings for a function's params?
David Storrs skribis 2005-04-25 10:00 (-0700):

> Cool.  But that seems to turn off all warnings during the compilation
> of the expression--I only want to get rid of the (expected)
> 'uninitialized' warning.  Will there be a way to do finer-grained
> control?

    compile("no warnings :undef; $expr").

Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html


    Reply to author    Forward  
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 Apr 27 2005, 5:39 pm
Newsgroups: perl.perl6.language
From: pdcaw...@bofh.org.uk (Piers Cawley)
Date: Wed, 27 Apr 2005 22:39:43 +0100
Local: Wed, Apr 27 2005 5:39 pm
Subject: Re: turning off warnings for a function's params?

Write an appropriate macro:

    warns(is( foo(undef, undef), undef, "foo(undef, undef) gives undef"),
          "uninitialized value in concatenation or string");

That way you get to ensure that the warning gets thrown correctly if undef is
passed, but you don't get the warning mucking up your test output.


    Reply to author    Forward  
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 »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google