[28022] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9386 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 26 18:05:46 2006

Date: Mon, 26 Jun 2006 15:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 26 Jun 2006     Volume: 10 Number: 9386

Today's topics:
    Re: Cron Job through Perl <tzz@lifelogs.com>
    Re: FAQ 4.30 How do I capitalize all the words on one l <thundergnat@hotmail.com>
    Re: How to read from a file with both text and binary <1usa@llenroc.ude.invalid>
    Re: Making the simple impossible and the impossible unt xfx.publishing@gmail.com
    Re: Making the simple impossible and the impossible unt xfx.publishing@gmail.com
    Re: Need Search::Binary examples <1usa@llenroc.ude.invalid>
    Re: Need Search::Binary examples <tadmc@augustmail.com>
    Re: Need Search::Binary examples <nomail@sorry.com>
    Re: Please help Perl Newbie understand this statement <tadmc@augustmail.com>
    Re: Please help Perl Newbie understand this statement jm-1@remotekontrol.com
    Re: Problem with Multi- threaded Server <tzz@lifelogs.com>
    Re: Regexp problem <1usa@llenroc.ude.invalid>
    Re: regular expression again <ced@blv-sam-01.ca.boeing.com>
    Re: Regular Expression Generator <tzz@lifelogs.com>
    Re: Regular Expression Generator <rvtol+news@isolution.nl>
    Re: What is a type error? <cdsmith@twu.net>
    Re: What is Expressiveness in a Computer Language <gneuner2/@comcast.net>
    Re: What is Expressiveness in a Computer Language <cdsmith@twu.net>
    Re: What is Expressiveness in a Computer Language <jo@durchholz.org>
    Re: What is Expressiveness in a Computer Language <jo@durchholz.org>
    Re: What is Expressiveness in a Computer Language <jo@durchholz.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 26 Jun 2006 15:03:29 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Cron Job through Perl
Message-Id: <g69d5cvloxq.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 26 Jun 2006, bob@tclaboratories.com wrote:

> I am looking to try to add, edit, and view cron jobs through a perl
> script. does anyone have a way to do so. I looked at Schedule::Cron but
> it seems like it is more for setting up crons in specific sub routines
> in itself instead of setting up actual cron jobs. (unless i
> misunderstood it) in which case if anyone had previous experience in
> Schedule::Cron then could they give me an example of how to
> add/edit/view through that script.

I don't know Schedule::Cron myself, but take a look at cfperl
http://lifelogs.com/cfperl/ - it implements a Parse::RecDescent parser
to intrepret words such as "monthly" as cron entries.  Here's an
example:

  weekly on Monday,Tuesday at 2; on Tuesday,Friday at 8,3; on Thursday at 20,22 do as cftest  /usr/bin/checkquotas

Hope this helps
Ted


------------------------------

Date: Mon, 26 Jun 2006 16:14:46 -0400
From: thundergnat <thundergnat@hotmail.com>
Subject: Re: FAQ 4.30 How do I capitalize all the words on one line?
Message-Id: <sPadnTkXT7ul3T3ZnZ2dnUVZ_oudnZ2d@rcn.net>

brian d foy wrote:
> In article <1qWdnZHvJPl-bQbZnZ2dnUVZ_qqdnZ2d@rcn.net>, thundergnat
> <thundergnat@hotmail.com> wrote:
> 
>> PerlFAQ Server wrote:
> 
>>>             $string =~ s/ (
>>>                                      (^\w)    #at the beginning of the line
>>>                                        |      # or
>>>                                      (\s\w)   #preceded by whitespace
>>>                                        )
>>>                                     /\U$1/xg;
> 
>> Misses words with leading punctuation. e.g. "this", 'that' & (other)
> 
> No solution is perfect, and even your solutions have problems.
> 
> You can't just use a word boundary, either, for the reasons listed in
> the answer. 
> 
> Any answer that tries to do it in a single substitution is probably
> going to be inadequate.
> 

Can't really quibble with that. Any solution will need to be tailored to
the situation.



My original point was that there is a syntax error in the FAQ.

The line:

 > $string =~ /([\w']+)/\u\L$1/g;

is missing the s.


------------------------------

Date: Mon, 26 Jun 2006 18:10:51 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: How to read from a file with both text and binary
Message-Id: <Xns97EE905A5808Aasu1cornelledu@127.0.0.1>

"tuser" <tuser3@gmail.com> wrote in
news:1151341935.963512.13840@i40g2000cwc.googlegroups.com: 

> Brian wrote:
>> I am processing print job files.

 ...

>> Here is an example of part of a print job file containing PCL data:
>>
>> * PRINT TIME:    13:30:38
>> *
>> * PRINT DATE:    23 JUN 2006
>> *
>> * PRINT NAME:    TA104002
>> *
>> * SYSTEM:        MVSA
>> *
>> *
>> *
>>**START*****START*****START*****START*****START*****START*****START***
>> **START**
>> ^[E^[&u300D^[*v1O^[*v0N^[*c00001D^[)s64W@^B)$7^A^^¦^U^BÿªÃðÄ

 ...

> However, I suspect that the 2-character sequence "^[" is not to be
> taken literally, but really stands for one single control character
> (possibly an octal "\033").
> 
> You could try the following instead:
> if ( $_ =~ /\033E\033/ )

You are most likely correct that ^[ stands for the escape character. In 
that case, you can also use \e instead of the octal code.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 26 Jun 2006 12:28:37 -0700
From: xfx.publishing@gmail.com
Subject: Re: Making the simple impossible and the impossible unthinkable...
Message-Id: <1151350117.312483.123540@i40g2000cwc.googlegroups.com>


krakle@visto.com wrote:
> xfx.publishing@gmail.com wrote:
> > It's asinine to do so much stupid crap
> > just to set up login validation.
>
> Isnt that the point? And isnt that the reason you cannot access their
> site with a script?

I rather got the impression it was a side-effect, not the reason.
Thanks.



------------------------------

Date: 26 Jun 2006 12:34:02 -0700
From: xfx.publishing@gmail.com
Subject: Re: Making the simple impossible and the impossible unthinkable...
Message-Id: <1151350442.246641.246490@r2g2000cwb.googlegroups.com>

Tad McClellan wrote:
> Please put the subject of your article in the Subject of your article.
>
> Folks that are interested in web scraping will read articles whose
> subject mentions web scraping.
>
> They are likely to skip reading articles whose subject cannot be
> determined by the Subject.

Well, potentially in my defence, the article is also abut stupidity,
and the subject is, in fact, stupid!

> > I'm trying to get a Perl script with LWP to get information from AOL
> > profiles.
>
>    Web Scraping Proxy

Thank you. And Ironic that I work for them and yet would have never
known about that internally.

Okay no, that's not that ironic.

>       http://www.research.att.com/~hpk/wsp/
>
> It is an AOL site.
> 
> The sun rises in the East.
> 
> So what's new?  :-)

Point.



------------------------------

Date: Mon, 26 Jun 2006 18:14:42 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Need Search::Binary examples
Message-Id: <Xns97EE910107DACasu1cornelledu@127.0.0.1>

Arvin Portlock <nomail@sorry.com> wrote in
news:44A02083.2090206@sorry.com: 

>> You should *ALWAYS* verify that the file opened correctly.
> 
>> Even though the
>> stat() showed that the file exists that does not mean that you would 
>> be able
>> to open it.  You should also include the $! and/or $^E variables to 
>> indicate
>> exactly why the file could not be opened.
>>
>> Also, the string '0' is false so if you had a file named '0' you
>> would not find it.  Use the defined() function to properly test
>> whether a variable contains a value.
>>
>> if ( defined $textfile ) {
>>     if ( open STATFILE, '<', $textfile ) {
>>
> Thanks for the feedback. I do have a bad habit of not
> checking the status of a file open. Mostly because I
> just don't like programs dieing on my users.

You, as the progammer, can handle the failure in another way than just 
invoking die. However, I cannot see the point of carrying on, as if 
nothing is wrong, after a call to open fails. What you do is up to you, 
but you *must* do something.

Sinan











 I know about
> $! but $^E is new to me. I'll check it out. Thanks also
> for pointing out the string '0' bug. For some reason I
> have had problems with defined() working as advertised so
> typically shy away from it aside from checking for the
> existence of hash keys. Don't ask me what the problem
> was exactly, I simply remember having problems with it.
> When it's critical I actually resort to something like:
> if ($var or $var eq '0'). An ugly personal idiom that
> I'd just as soon drop. I'll try and use defined () from
> now on and possibly post here someday if I have problems
> with it that I can't figure out.
> 
> I'm also going through and doing a few more optimizations
> as they occur to me. For example I believe I don't gain
> anything by sorting my random numbers. Hmm, there was one
> other that I thought of but has gone out of my mind now.
> 
> Arvin
> 
> 



-- 
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: Mon, 26 Jun 2006 15:56:11 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Need Search::Binary examples
Message-Id: <slrnea0ifb.pbj.tadmc@magna.augustmail.com>

Arvin Portlock <nomail@sorry.com> wrote:

> I do have a bad habit of not
> checking the status of a file open. Mostly because I
> just don't like programs dieing on my users. 


If the program's job is to process a file, and the program cannot
open the file, what is it _supposed_ to do instead?

Silently proceed as if the file was empty or fail noisily?

I don't like my programs silently failing to do their job.  :-)


> For some reason I
> have had problems with defined() working as advertised so
> typically shy away from it aside from checking for the
> existence of hash keys. 


You cannot use defined() to check the existence of hash keys!

You must use exists() for that.


Check the output from:

   my %hash = ( foo => 'FOO', bar => undef );
   foreach ( 'not_a_key', keys %hash ) {
      print "key '$_' defined\n" if defined $hash{$_};
      print "key '$_' exists\n"  if exists  $hash{$_};
   }


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Mon, 26 Jun 2006 14:24:41 -0700
From: Arvin Portlock <nomail@sorry.com>
To:  tadmc@augustmail.com
Subject: Re: Need Search::Binary examples
Message-Id: <44A05099.8090305@sorry.com>

Tad McClellan wrote:

> >For some reason I
> >have had problems with defined() working as advertised so
> >typically shy away from it aside from checking for the
> >existence of hash keys.
>
> You cannot use defined() to check the existence of hash keys!
>
> You must use exists() for that.

I get confused and I'm too lazy to look up things I
don't use enough to remember. Hence my personal idiom
if ($var or $var eq '0'). There's another personal
idiom I have. I'll often use [\w\W] in regular expressions
because I'm too lazy to remember or look up when . matches
\n or \r (I think it does if you put a /m at the end
but [\w\W] is faster than looking it up to be certain).

Yeah, everyone is apalled I'm sure. Just thought I'd
post a confession from the Dark Side for if you ever
wonder why some people do the craziest things in perl.
Answer: we're lazy and it's faster/less work than
looking it up



------------------------------

Date: Mon, 26 Jun 2006 12:39:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Please help Perl Newbie understand this statement
Message-Id: <slrnea06v6.ksn.tadmc@magna.augustmail.com>

jm-1@remotekontrol.com <jm-1@remotekontrol.com> wrote:

> I have not programmed before and I am doing my best to get to grips
> with Perl in order to decode and modify a backup script. 


> Could anyone
> please explain the following line in plain english to me?


Another followup already did that, so I'll address other issues.


> I am working my through
> the tutorials 


Which ones?

There are more bad Perl tutorials than good ones.

If you tell us which ones, then we can tell you whether they are
worth any study or not...


> have pasted the entire script at the bottom of this message.


It appears to have been written by someone who isn't well versed
in programmeing in general, nor in Perl in particular. 

Modify it if you must, but don't be learning the bad habits
it displays.


> #!/usr/bin/perl


You should ask for all the (machine) help you can get:

   use warnings;
   use strict;

They will find many common programming mistakes for you.

Do read up on them:

   perldoc warnings

   perldoc strict


> #Declare the varibles


A good programmer would not repeat in comments what is already
said in the code. Comments are for things that cannot be easily
said in the code (such as "why" rather than "how").


> my ($hour, $min, $sec, $now, $remoteip, $port, $connected, $ping);
> my (@ports, @lines, %status);


A good programmer would limit the scope of variables rather
than making them visible even where they don't need to be
visible.

A good place to learn about scoping in Perl is:

   "Coping with Scoping":

      http://perl.plover.com/FAQs/Namespaces.html



> $command = "/bin/rm -f /root/.ssh/known_hosts";
> system($command);


$command was never declared, so what was the point of declaring
some variables but not others? (rhetorical question because the
answer is clearly "There is no point" to doing that).


> for ($i=0; $i < @firewalls; $i++)
> 	{
> 
> $string = $firewalls[$i];


A good Perl programmer would let perl do the indexing for him,
but replacing those 2 lines with:


   foreach my $string ( @firewalls ) {


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 26 Jun 2006 15:03:13 -0700
From: jm-1@remotekontrol.com
Subject: Re: Please help Perl Newbie understand this statement
Message-Id: <1151359393.882375.103330@r2g2000cwb.googlegroups.com>

Thank You very much for your help. I have been reading the tutorials @
http://learn.perl.org/library/beginning_perl/. The only problem that I
find is the examples are not real world. I would love to read through
and explanation of a real world perl script that many people use "in
human language".

It's ok using make believe examples to learn the concepts of
programming but it leaves one thinking "how would I apply that in the
real world", " I wonder how people have used that example in anger" etc
etc

It is so nice to have people of your nature who freely give thier time
to help folk like me. I have always avoided programming because I find
it frustrating but I am sure that just like many other things, if a
topic is explained to me in a way that I can put it to use, then I will
grasp it very quickly.

Thank you once again

Regards

And

Tad McClellan wrote:
> jm-1@remotekontrol.com <jm-1@remotekontrol.com> wrote:
>
> > I have not programmed before and I am doing my best to get to grips
> > with Perl in order to decode and modify a backup script.
>
>
> > Could anyone
> > please explain the following line in plain english to me?
>
>
> Another followup already did that, so I'll address other issues.
>
>
> > I am working my through
> > the tutorials
>
>
> Which ones?
>
> There are more bad Perl tutorials than good ones.
>
> If you tell us which ones, then we can tell you whether they are
> worth any study or not...
>
>
> > have pasted the entire script at the bottom of this message.
>
>
> It appears to have been written by someone who isn't well versed
> in programmeing in general, nor in Perl in particular.
>
> Modify it if you must, but don't be learning the bad habits
> it displays.
>
>
> > #!/usr/bin/perl
>
>
> You should ask for all the (machine) help you can get:
>
>    use warnings;
>    use strict;
>
> They will find many common programming mistakes for you.
>
> Do read up on them:
>
>    perldoc warnings
>
>    perldoc strict
>
>
> > #Declare the varibles
>
>
> A good programmer would not repeat in comments what is already
> said in the code. Comments are for things that cannot be easily
> said in the code (such as "why" rather than "how").
>
>
> > my ($hour, $min, $sec, $now, $remoteip, $port, $connected, $ping);
> > my (@ports, @lines, %status);
>
>
> A good programmer would limit the scope of variables rather
> than making them visible even where they don't need to be
> visible.
>
> A good place to learn about scoping in Perl is:
>
>    "Coping with Scoping":
>
>       http://perl.plover.com/FAQs/Namespaces.html
>
>
>
> > $command = "/bin/rm -f /root/.ssh/known_hosts";
> > system($command);
>
>
> $command was never declared, so what was the point of declaring
> some variables but not others? (rhetorical question because the
> answer is clearly "There is no point" to doing that).
>
>
> > for ($i=0; $i < @firewalls; $i++)
> > 	{
> >
> > $string = $firewalls[$i];
>
>
> A good Perl programmer would let perl do the indexing for him,
> but replacing those 2 lines with:
>
>
>    foreach my $string ( @firewalls ) {
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas



------------------------------

Date: Mon, 26 Jun 2006 15:08:51 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Problem with Multi- threaded Server
Message-Id: <g698xnjloos.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 26 Jun 2006, xhoster@gmail.com wrote:

"janicehwang1325@yahoo.com" <janicehwang1325@yahoo.com> wrote:
>> Thanks for the debuggin guidelines. Here are some results for my
>> testing:
>>
>> 1. Threaded server works fine without SSL.
>> 2. DBI doesn't cause a problem for threaded server (either enable or
>> disable DBI does not cause the problem with the condition WITHOUT SSL)
>> 3. Threaded server fails when use with SSL
>
>
> Have you read and understood the parts about close and SSL_no_shutdown in
> the IO::Socket::SSL docs?
>
> I can't get SSL to install, so I can't test it, but I suspect this is
> likely the problem.

I'm glad we've established the problem is just in the SSL layer.

An additional suggestion: after you looked at the docs, if you still
can't figure the problem out, contact the IO::Socket::SSL
maintainers.  Until the problem is resolved, you could turn off SSL so
your server can be used, if that's prudent depending on your
particular security situation.

Ted


------------------------------

Date: Mon, 26 Jun 2006 18:16:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Regexp problem
Message-Id: <Xns97EE913F586BEasu1cornelledu@127.0.0.1>

Tad McClellan <tadmc@augustmail.com> wrote in 
news:slrne9vl92.jvh.tadmc@magna.augustmail.com:

> Mark Healey <dont@like.spammers> wrote:
> 
>> Like most open source perldoc sucks.
> 
> 
> So long!

Good to know there are some constants in life ;-) Like the infinite supply 
of killfile candidates.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: Mon, 26 Jun 2006 19:52:06 GMT
From: Charles DeRykus <ced@blv-sam-01.ca.boeing.com>
Subject: Re: regular expression again
Message-Id: <J1HGIu.AIt@news.boeing.com>

Xicheng Jia wrote:
> Peter Janssens wrote:
>> Hi,
>>
>> Original question.
>> I want to retrieve all occurences of a string "aa". So in the search string
>> "aaaa", I have to find it three times (aa)aa, a(aa)a, aa(aa).
>>
>> How can I do that, using regular expressions in Perl?
>>
>> The following solution (previous post) works fine but ...
>> /(a(?=(a)))/g
>>
>> Suppose I want to search for aaa or aab in the string aaabaabaa.
>>
>> I thaught the following will do the job: a(?=a)[ab].
>> But is doesn't.
>>
>> Also, if you try something like aa[ab] it will find the first instance (aaa)
>> but
>> not the second (aab) in  aaabaabaa.
>>
>> Your help is appreciated.
> 
> you could extend John's way, say:
> 
>     print for "aaabaabaa" =~ /(?=(aa[ab]))/g
> 
> or some more regex's ways, like:
> 
>     "aaabaabaa" =~ /(aa[ab])(?{print $1})(?!)/;
> 
> Let me show you how the above regex works:
> 
> (aa[ab]): get a match, and save the string into $1,
> (?{print $1}): immediately print the matched string in $1
> (?!) : matching failed, so $1 forcefully becomes non-matched.
> 
> According to the regex engine(the traditional NFA) behind Perl, the
> regex will try another possiblity from the next trying-point until it
> finds a match or finally fails. (?!) is the key that guarentees the
> regex fails,(so the above matching expression will never success) and
> the result is that the regex traverses all possiblities of the matching
> cases and prints them out..
> 
> BTW. this is NOT a recommended way to solve your problem, but a way to
> know something more about the Perl regex. you might find more useful
> and interesting information in the book "Mastering Regular
> Expressions"(strongly recommended).

Just wanted to add thanks from the sidelines.  I had never seen
the (?!) idiom and an example of its use.

-- 
Charles DeRykus


------------------------------

Date: Mon, 26 Jun 2006 14:59:21 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Regular Expression Generator
Message-Id: <g69hd27lp4m.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 26 Jun 2006, jurgenex@hotmail.com wrote:

jeremyje@gmail.com wrote:
>> Is there a library or a way to generate an appropriate regular
>> expression for any given input string?

> Seriously: it is impossible to derive a generic RE pattern from a single
> text sample.

I think this is incorrect, Jurgen.  The OP was asking about an
appropriate, not a generic regex.  Other than
http://search.cpan.org/~dankogai/Regexp-Optimizer-0.15/lib/Regexp/Optimizer.pm
(which I mentioned in c.l.p.modules to answer his post, before I saw
his cross-post here), you can always just say

my $regex = '^(' . join('|', @strings) . ')$';

and that's a regex that will match any given non-empty strings.

Ted


------------------------------

Date: Mon, 26 Jun 2006 23:00:14 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Regular Expression Generator
Message-Id: <e7pp1p.dk.1@news.isolution.nl>

Ted Zlatanov schreef:

> my $regex = '^(' . join('|', @strings) . ')$';
>
> and that's a regex that will match any given non-empty strings.

'^(?:' . join( '|', map quotemeta, grep /./, @strings ) . ')$'

-- 
Affijn, Ruud

"Gewoon is een tijger."




------------------------------

Date: Mon, 26 Jun 2006 12:53:42 -0600
From: Chris Smith <cdsmith@twu.net>
Subject: Re: What is a type error?
Message-Id: <MPG.1f09db1c1b611507989710@news.altopia.net>

Pascal Costanza <pc@p-cos.net> wrote:
> Chris Smith wrote:
> > Of course zero is not appropriate as a second argument to the division 
> > operator!  I can't possibly see how you could claim that it is.  The 
> > only reasonable statement worth making is that there doesn't exist a 
> > type system in widespread use that is capable of checking this.
> 
> ...and this is typically not even checked at the stage where type tags 
> are checked in dynamically-typed languages. Hence, it is not a type 
> error. (A type error is always what you define to be a type error within 
>   a given type system, right?)

Sure, it's not a type error for that language.

> Note, this example was in response to David's reply that my definition 
> turns every runtime error into a type error. That's not the case, and 
> that's all I want to say.

But your definition does do that.  Your definition of a type error was 
when a program attempts to invoke an operation on values that are not 
appropriate for this operation.  Clearly, in this example, the program 
is invoking an operation (division) on values that are not appropriate 
(zero for the second argument).  Hence, if your definition really is a 
definition, then this must qualify.

> > However, it sounds as 
> > if you're claiming that it wouldn't be possible for the type system to 
> > do this?
> 
> No. I only need an example where a certain error is not a type error in 
> _some_ language. I don't need to make a universal claim here.

Definitions are understood to be statements of the form "if and only 
if".  They assert that /everything/ that fits the definition is 
describable by the word, and /everything/ that doesn't is not 
describable by the word.  If that's not what you meant, then we are 
still in search of a definition.

If you want to make a statement instead of the sort you've implied 
above... namely that a type error is *any* error that's raised by a type 
system, then that's fine.  It certainly brings us closer to static 
types.  Now, though, the task is to define a type system without making 
a circular reference to types.  You've already rejected the statement 
that all runtime errors are type errors, because you specifically reject 
the division by zero case as a type error for most languages.  What is 
that distinction?

-- 
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation


------------------------------

Date: Mon, 26 Jun 2006 14:22:40 -0400
From: George Neuner <gneuner2/@comcast.net>
Subject: Re: What is Expressiveness in a Computer Language
Message-Id: <bq60a2hjm5dp22qta59m5lfa7ebuft16og@4ax.com>

On Sun, 25 Jun 2006 14:28:22 -0600, Chris Smith <cdsmith@twu.net>
wrote:

>George Neuner <gneuner2/@comcast.net> wrote:
>> >Undecidability can always be avoided by adding annotations, but of 
>> >course that would be gross overkill in the case of index type widening.
>> 
>> Just what sort of type annotation will convince a compiler that a
>> narrowing conversion which could produce an illegal value will, in
>> fact, never produce an illegal value?
>
>The annotation doesn't make the narrowing conversion safe; it prevents 
>the narrowing conversion from happening. 

That was my point ... you get a program that won't compile.


>If, for example, I need to 
>subtract two numbers and all I know is that they are both between 2 and 
>40, then I only know that the result is between -38 and 38, which may 
>contain invalid array indices.  However, if the numbers were part of a 
>pair, and I knew that the type of the pair was <pair of numbers, 2 
>through 40, where the first number is greater than the second>, then I 
>would know that the difference is between 0 and 38, and that may be a 
>valid index.
>
>Of course, the restrictions on code that would allow me to retain 
>knowledge of the form [pair of numbers, 2 through 40, a > b] may be 
>prohibitive.  That is an open question in type theory, as a matter of 
>fact; whether types of this level of power may be inferred by any 
>tractable procedure so that safe code like this may be written without 
>making giving the development process undue difficulty by requiring ten 
>times as much type annotations as actual code.  There are attempts that 
>have been made, and they don't look too awfully bad.

I worked in signal and image processing for many years and those are
places where narrowing conversions are used all the time - in the form
of floating point calculations reduced to integer to value samples or
pixels, or to value or index lookup tables.  Often the same
calculation needs to be done for several different purposes.

I can know that my conversion of floating point to integer is going to
produce a value within a certain range ... but, in general, the
compiler can't determine what that range will be.  All it knows is
that a floating point value is being truncated and the stupid
programmer wants to stick the result into some type too narrow to
represent the range of possible values.

Like I said to Ben, I haven't seen any _practical_ static type system
that can deal with things like this.  Writing a generic function is
impossible under the circumstances, and writing a separate function
for each narrow type is ridiculous and a maintenance nightmare even if
they can share the bulk of the code.

George
--
for email reply remove "/" from address


------------------------------

Date: Mon, 26 Jun 2006 13:02:33 -0600
From: Chris Smith <cdsmith@twu.net>
Subject: Re: What is Expressiveness in a Computer Language
Message-Id: <MPG.1f09dd34676ab719989711@news.altopia.net>

George Neuner <gneuner2/@comcast.net> wrote:
> On Sun, 25 Jun 2006 14:28:22 -0600, Chris Smith <cdsmith@twu.net>
> wrote:
> 
> >George Neuner <gneuner2/@comcast.net> wrote:
> >> >Undecidability can always be avoided by adding annotations, but of 
> >> >course that would be gross overkill in the case of index type widening.
> >> 
> >> Just what sort of type annotation will convince a compiler that a
> >> narrowing conversion which could produce an illegal value will, in
> >> fact, never produce an illegal value?
> >
> >The annotation doesn't make the narrowing conversion safe; it prevents 
> >the narrowing conversion from happening. 
> 
> That was my point ... you get a program that won't compile.

That's not actually the case here.  If we're talking only about type 
conversions and not value conversions (see below), then narrowing 
conversions are only necessary because you've forgotten some important 
bit of type information.  By adding annotations, you can preserve that 
piece of information and thus avoid the conversion and get a program 
that runs fine.

> I worked in signal and image processing for many years and those are
> places where narrowing conversions are used all the time - in the form
> of floating point calculations reduced to integer to value samples or
> pixels, or to value or index lookup tables.  Often the same
> calculation needs to be done for several different purposes.

These are value conversions, not type conversions.  Basically, when you 
convert a floating point number to an integer, you are not simply 
promising the compiler something about the type; you are actually asking 
the compiler to convert one value to another -- i.e., see to it that 
whatever this is now, it /becomes/ an integer by the time we're done.  
This also results in a type conversion, but you've just converted the 
value to the appropriate form.  There is a narrowing value conversion, 
but the type conversion is perfectly safe.

> I can know that my conversion of floating point to integer is going to
> produce a value within a certain range ... but, in general, the
> compiler can't determine what that range will be.

If you mean "my compiler can't", then this is probably the case.  If you 
mean "no possible compiler could", then I'm not sure this is really very 
likely at all.

> Like I said to Ben, I haven't seen any _practical_ static type system
> that can deal with things like this.

I agree.  Such a thing doesn't currently exist for general-purpose 
programming languages, although it does exist in limited languages for 
some specific domains.

-- 
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation


------------------------------

Date: Mon, 26 Jun 2006 22:54:53 +0200
From: Joachim Durchholz <jo@durchholz.org>
Subject: Re: What is Expressiveness in a Computer Language
Message-Id: <e7phid$baf$2@online.de>

Andrew McDonagh schrieb:
> Joachim Durchholz wrote:
>> Chris Smith schrieb:
>>> Joachim Durchholz <jo@durchholz.org> wrote:
>>>> Sorry, I have to insist that it's not me who's stretching terms here.
>>>>
>>>> All textbook definitions that I have seen define a type as the 
>>>> set/operations/axioms triple I mentioned above.
>>>> No mention of immutability, at least not in the definitions.
>>>
>>> The immutability comes from the fact (perhaps implicit in these 
>>> textbooks, or perhaps they are not really texts on formal type 
>>> theory) that types are assigned to expressions,
>>
>> That doesn't *define* what's a type or what isn't!
>>
>> If it's impossible to assign types to all expressions of a program in 
>> a language, that does mean that there's no useful type theory for the 
>> program, but it most definitely does not mean that there are no types 
>> in the program.
>> I can still sensibly talk about sets of values, sets of allowable 
>> operations over each value, and about relationships between inputs and 
>> outputs of these operations.
>>
>> So programs have types, even if they don't have a static type system.
>> Q.E.D.
> 
> Of course not.  Otherwise programs using dynamically  typed systems 
> wouldnt exist.

I don't understand.
Do you mean dynamic typing (aka runtime types)?

> I haven't read all of this thread, I wonder, is the problem to do with 
> Class being mistaken for Type? (which is usually the issue)

No, not at all. I have seen quite a lot beyond OO ;-)

Regards,
Jo


------------------------------

Date: Mon, 26 Jun 2006 23:31:49 +0200
From: Joachim Durchholz <jo@durchholz.org>
Subject: Re: What is Expressiveness in a Computer Language
Message-Id: <e7pjnl$gac$1@online.de>

Darren New schrieb:
> Marshall wrote:
>> Also: has subtyping polymorphism or not, has parametric polymorphism or
>> not.
> 
> And covariant or contravariant.

That's actually not a design choice - if you wish to have a sound type 
system, all input parameters *must* be contravariant, all output 
parameters *must* be covariant, and all in/out parameters must be 
novariant. (Eiffel got this one wrong in almost all cases.)

Regards,
Jo


------------------------------

Date: Mon, 26 Jun 2006 23:45:27 +0200
From: Joachim Durchholz <jo@durchholz.org>
Subject: Re: What is Expressiveness in a Computer Language
Message-Id: <e7pkh8$hhd$1@online.de>

Anton van Straaten schrieb:
> Joachim Durchholz wrote:
 >> Anton van Straaten schrieb:
>>> There's a close connection between latent types in the sense I've 
>>> described, and the "tagged values" present at runtime.  However, as 
>>> type theorists will tell you, the tags used to tag values at runtime, 
>>> as e.g. a number or a string or a FooBar object, are not the same 
>>> thing as the sort of types which statically-typed languages have.
>>
>> Would that be a profound difference, or is it just that annotating a 
>> value with a full type expression would cause just too much runtime 
>> overhead?
> 
> It's a profound difference.  The issue is that it's not just the values 
> that need to be annotated with types, it's also other program terms.

Yes - but isn't that essentially just auxiliary data from and for the 
data-flow analysis that tracks what values with what types might reach 
which functions?

 > In
> addition, during a single run of a program, all it can ever normally do 
> is record the types seen on the path followed during that run, which 
> doesn't get you to static types of terms.  To figure out the static 
> types, you really need to do static analysis.

Agreed.

Regards,
Jo


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9386
***************************************


home help back first fref pref prev next nref lref last post