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
Message from discussion Autovivi
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
 
Nicholas Clark  
View profile  
 More options Aug 13 2002, 4:48 pm
Newsgroups: perl.perl6.language
From: n...@unfortu.net (Nicholas Clark)
Date: Tue, 13 Aug 2002 21:33:32 +0100
Local: Tues, Aug 13 2002 4:33 pm
Subject: Re: Autovivi

On Tue, Aug 13, 2002 at 03:06:40PM -0400, Deven T. Corzine wrote:
> The only accurate way to know if the code modifies the variables is to do
> some sort of dataflow analysis, and it can't be 100% accurate even then.  
> (Suppose a "shift" may or may not happen, depending on the parameters, then
> $_[2] is modified?)  Of course, it should often be possible (at least in
> principle) to determine that it's impossible for a particular parameter to
> be modified, and play it safe by assuming "is rw" for undeterminable cases.

Well, perl5 does already manage to avoid auto-vivifying hash keys when they
are used as subroutine arguments. It uses magic, rather than dataflow
analysis:

$ cat autovivi.pl
#!/usr/local/bin/perl -w
use strict;
use Devel::Peek;

sub rval {
  my $a = $_[0];

}

sub lval {
  $_[0] = undef;

}

sub dumpit {
  Dump ($_[0]);

}

my %a = (camel => 2);

rval ($a{llama});

print "rval: @{[keys %a]}\n";

lval ($a{alpaca});

print "lval: @{[keys %a]}\n\n";

dumpit ($a{dromedary});

__END__
$ ./autovivi.pl
rval: camel
lval: camel alpaca

SV = PVLV(0x1134d8) at 0xf4368
  REFCNT = 1
  FLAGS = (GMG,SMG)
  IV = 0
  NV = 0
  PV = 0
  MAGIC = 0x113420
    MG_VIRTUAL = &PL_vtbl_defelem
    MG_TYPE = PERL_MAGIC_defelem(y)
    MG_FLAGS = 0x02
      REFCOUNTED
    MG_OBJ = 0xf43a4
    SV = PVIV(0xf4990) at 0xf43a4
      REFCNT = 1
      FLAGS = (POK,pPOK)
      IV = 0
      PV = 0x1138a0 "dromedary"\0
      CUR = 9
      LEN = 10
  TYPE = y
  TARGOFF = 0
  TARGLEN = 1
  TARG = 0x1329ec
SV = PVHV(0x114820) at 0x1329ec
  REFCNT = 2
  FLAGS = (PADBUSY,PADMY,SHAREKEYS)
  IV = 2
  NV = 0
  ARRAY = 0x1133f8  (0:6, 1:2)
  hash quality = 125.0%
  KEYS = 2
  FILL = 2
  MAX = 7
  RITER = -1
  EITER = 0x0
  Elt "camel" HASH = 0x787f96b8
  SV = IV(0x112ee4) at 0xf4284
    REFCNT = 1
    FLAGS = (IOK,pIOK)
    IV = 2
  Elt "alpaca" HASH = 0x5af8b041
  SV = PVNV(0x12a6d8) at 0x111b40
    REFCNT = 1
    FLAGS = ()
    IV = 0
    NV = 0
    PV = 0

As you can see, the ingredients for "magic" are quite cumbersome, but do get
the job done.

Nicholas Clark
--
Even better than the real thing:        http://nms-cgi.sourceforge.net/


 
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.