develooper Front page | perl.perl5.porters | Postings from June 2014

[perl #122196] why are control-flow keywords confused with subroutines?

Thread Previous | Thread Next
From:
Linda Walsh
Date:
June 30, 2014 02:51
Subject:
[perl #122196] why are control-flow keywords confused with subroutines?
Message ID:
rt-4.0.18-6569-1404096659-1711.122196-75-0@perl.org
# New Ticket Created by  Linda Walsh 
# Please include the string:  [perl #122196]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=122196 >



This is a bug report for perl from perl-diddler@tlinx.org,
generated with the help of perlbug 1.39 running under perl 5.16.3.


-----------------------------------------------------------------
[Please describe your issue here]

This seems weird and very counter-intuitive, at the least.

Normally, perl prides itself on separate namespaces for
subs, vars, arrays, hashes... 

It has conflicts that make sense in cases of user defined
subs conflicting with perl functions like 'sin', 'exit',
'print', etc...

But It seems odd to see conflicts with control-flow words
that one wouldn't think could be "functions" or "sub"s.

Ex:

I had a prog where something in a loop started getting
a bit large, so wanted to move it to its own sub so as
not to detract from seeing the program structure.  Based
on actions in the sub, it would either choose 'next'
or continue with the next test.

Logical thing to do for clarity was define constants 
for next and continue, and return them to the loop so
so the actions could be mirrored.  Was surprised to see
the following diagnostics from this prog:

----
#!/usr/bin/perl
use warnings; use strict;

use constant { next=>1, continue=>2 };

sub special_case($) {
	my $param=$_[0];

	my $whatever=int rand $param;
	$whatever>5 and return next;
}

for (0..10) {
	my $res=special_case($_);
	$res==next && next;
	$res==continue && continue;
}

> /tmp/tst
Ambiguous call resolved as CORE::continue(), qualify as such or use & at /tmp/tst line 16.
Ambiguous call resolved as CORE::continue(), qualify as such or use & at /tmp/tst line 16.
Exiting subroutine via next at /tmp/tst line 10.
Exiting subroutine via next at /tmp/tst line 10.
====================

So why is 'next' being confused with a control word?

Especially in context of a return -- does 'next' return
a value when called as a function?

Is it callable as a function (I don't recall it being
documented in perlfunc, for example).

It seems odd that perl keeps Scalars, funcs, arrays, and hashes
separate and unconfused, but then doesn't keep control-flow
words separate from functions...

Are all perl keywords "functions?"

'my/our/sub...etc...'?




[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl 5.16.3:

Configured by law at Wed Jan 22 12:58:58 PST 2014.

Summary of my perl5 (revision 5 version 16 subversion 3) configuration:
   
  Platform:
    osname=linux, osvers=3.12.0-isht-van, archname=x86_64-linux-thread-multi-ld
    uname='linux ishtar 3.12.0-isht-van #1 smp preempt wed nov 13 16:50:51 pst 2013 x86_64 x86_64 x86_64 gnulinux '
    config_args=''
    hint=previous, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=define
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-g -O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    ccversion='', gccversion='4.8.1 20130909 [gcc-4_8-branch revision 202388]', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='long double', nvsize=16, Off_t='off_t', lseeksize=8
    alignbytes=16, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags ='-g -fstack-protector -fPIC'
    libpth=/usr/lib64 /lib64
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc -lgdbm_compat
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.18.so, so=so, useshrplib=true, libperl=libperl-5.16.3.so
    gnulibc_version='2.18'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/home/perl/perl-5.16.3/lib/x86_64-linux-thread-multi-ld/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -g -O2 -fstack-protector -fPIC'

Locally applied patches:
    

---
@INC for perl 5.16.3:
    /home/law/bin/lib
    /home/perl/perl-5.16.3/lib/site/x86_64-linux-thread-multi-ld
    /home/perl/perl-5.16.3/lib/site
    /home/perl/perl-5.16.3/lib/x86_64-linux-thread-multi-ld
    /home/perl/perl-5.16.3/lib
    .

---
Environment for perl 5.16.3:
    HOME=/home/law
    LANG (unset)
    LANGUAGE (unset)
    LC_COLLATE=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=.:/home/law/bin/lib:/usr/bin:/bin:/usr/sbin:/sbin:/opt/kde3/bin:/usr/local/bin:/home/law/bin:/etc/local/func_lib:/home/law/lib
    PERL5OPT=-Mutf8 -CSA -I/home/law/bin/lib
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About