Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Truth and Falsehood" doesn't belong in perlsyn #12538

Closed
p5pRT opened this issue Nov 9, 2012 · 9 comments
Closed

"Truth and Falsehood" doesn't belong in perlsyn #12538

p5pRT opened this issue Nov 9, 2012 · 9 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 9, 2012

Migrated from rt.perl.org#115650 (status was 'resolved')

Searchable as RT115650$

@p5pRT
Copy link
Author

p5pRT commented Nov 9, 2012

From @mauke

Created by @mauke

perldoc perlsyn includes this section​:

| Truth and Falsehood
| The number 0, the strings '0' and "", the empty list "()", and "undef"
| are all false in a boolean context. All other values are true.
| Negation of a true value by "!" or "not" returns a special false value.
| When evaluated as a string it is treated as "", but as a number, it is
| treated as 0. Most Perl operators that return true or false behave this
| way.

I don't think this belongs in perlsyn. Truthiness is a property of values, not
of syntactic constructs, and indeed the paragraph is talking about "all other
values" -- which makes it internally inconsistent because 'the empty list "()"'
is not a distinct value. It's a syntactic construct that evaluates to either
undef or no values at all (an empty list) in scalar/list context, respectively.

That is, '()' and 'undef' are simply two particular spellings of the value
undef, but there are many more. Similarly, '0', '0x0', '0b0000_0000', '1 - 1',
'2 ^ 2', ... would be different spellings of the value 0. Therefore I'd remove
"()" from the list and move that part to perldata.

The part about negation yielding a dualvar for false isn't really a syntactic
property either. I'd put it either in perldata (because it's about a special
value returned by some operators) or perlop (because it's about the behavior of
several operators).

Thoughts?

Perl Info

Flags:
    category=docs
    severity=low

Site configuration information for perl 5.16.2:

Configured by mauke at Thu Nov  1 15:23:47 CET 2012.

Summary of my perl5 (revision 5 version 16 subversion 2) configuration:
   
  Platform:
    osname=linux, osvers=2.6.32-5-686, archname=i686-linux
    uname='linux debian-vb 2.6.32-5-686 #1 smp sun sep 23 09:49:36 utc 2012 i686 gnulinux '
    config_args='-Dprefix=/home/mauke/usr -Doptimize=-O2 -flto -Dldflags=-fstack-protector -L/usr/local/lib -O2 -flto -Dlddlflags=-shared -O2 -flto -L/usr/local/lib -fstack-protector -Dcf_email=l.mai@web.de -Dperladmin=none -de'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -flto',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.7.1', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags ='-fstack-protector -L/usr/local/lib -O2 -flto'
    libpth=/usr/local/lib /lib/../lib /usr/lib/../lib /lib /usr/lib /usr/lib/i486-linux-gnu /usr/lib64
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.11.3.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.11.3'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -flto -L/usr/local/lib -fstack-protector'

Locally applied patches:
    SAVEARGV0 - disable magic open in <ARGV>


@INC for perl 5.16.2:
    /home/mauke/usr/lib/perl5/site_perl/5.16.2/i686-linux
    /home/mauke/usr/lib/perl5/site_perl/5.16.2
    /home/mauke/usr/lib/perl5/5.16.2/i686-linux
    /home/mauke/usr/lib/perl5/5.16.2
    /home/mauke/usr/lib/perl5/site_perl/5.16.1/i686-linux
    /home/mauke/usr/lib/perl5/site_perl/5.16.1
    /home/mauke/usr/lib/perl5/site_perl
    .


Environment for perl 5.16.2:
    HOME=/home/mauke
    LANG=en_US.utf8
    LANGUAGE (unset)
    LC_COLLATE=POSIX
    LD_LIBRARY_PATH=/home/mauke/usr/lib
    LOGDIR (unset)
    PATH=/home/mauke/perl5/perlbrew/bin:/home/mauke/.cabal/bin:/home/mauke/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    PERLBREW_BASHRC_VERSION=0.55
    PERLBREW_HOME=/home/mauke/.perlbrew
    PERLBREW_ROOT=/home/mauke/perl5/perlbrew
    PERL_BADLANG (unset)
    PERL_UNICODE=SAL
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Nov 9, 2012

From bmb@Mail.Libs.UGA.EDU

On 11/9/12, l.mai@​web.de (via RT) <perlbug-followup@​perl.org> wrote​:

perldoc perlsyn includes this section​:

| Truth and Falsehood
| The number 0, the strings '0' and "", the empty list "()", and
"undef"
| are all false in a boolean context. All other values are true.
| Negation of a true value by "!" or "not" returns a special false
value.
| When evaluated as a string it is treated as "", but as a number, it
is
| treated as 0. Most Perl operators that return true or false behave
this
| way.

I don't think this belongs in perlsyn. Truthiness is a property of values,
not
of syntactic constructs, and indeed the paragraph is talking about "all
other
values" -- which makes it internally inconsistent because 'the empty list
"()"'
is not a distinct value. It's a syntactic construct that evaluates to
either
undef or no values at all (an empty list) in scalar/list context,
respectively.

It think this is a helpful location for folks coming from other
languages where there are 'true' and 'false' syntactic elements.

That is, '()' and 'undef' are simply two particular spellings of the value
undef

Huh? :-)

, but there are many more. Similarly, '0', '0x0', '0b0000_0000', '1 -
1',
'2 ^ 2', ... would be different spellings of the value 0. Therefore I'd
remove
"()" from the list and move that part to perldata.

The part about negation yielding a dualvar for false isn't really a
syntactic
property either. I'd put it either in perldata (because it's about a
special
value returned by some operators) or perlop (because it's about the behavior
of
several operators).

Thoughts?

I think the comprehensive statements, 'The number 0, the strings '0'
and "" , the empty list () , and undef are all false in a boolean
context. All other values are true.' are helpful as a compact
reference unit.

--
Brad

@p5pRT
Copy link
Author

p5pRT commented Nov 9, 2012

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 9, 2012

From @ikegami

On Fri, Nov 9, 2012 at 2​:18 PM, Brad Baxter <bmb@​mail.libs.uga.edu> wrote​:

I don't think this belongs in perlsyn. Truthiness is a property of
values,
not of syntactic constructs

It think this is a helpful location for folks coming from other

languages where there are 'true' and 'false' syntactic elements.

That doesn't change anything. Syntactic elements relating to variables are
in perldata too.

That is, '()' and 'undef' are simply two particular spellings of the
value
undef

Huh? :-)

If you by "()" you mean the operator that returns undef or an empty list​:
Operators aren't true or false.
If you by "()" you mean an empty list​: Lists aren't true or false.

Either way you look at it, "()" doesn't belong there.

@p5pRT
Copy link
Author

p5pRT commented Nov 10, 2012

From Eirik-Berg.Hanssen@allverden.no

On Fri, Nov 9, 2012 at 9​:03 PM, Eric Brine <ikegami@​adaelis.com> wrote​:

That is, '()' and 'undef' are simply two particular spellings of the
value

undef

  ... in a scalar context, yes, of which boolean is one, right?

Huh? :-)

If you by "()" you mean the operator that returns undef or an empty list​:
Operators aren't true or false.
If you by "()" you mean an empty list​: Lists aren't true or false.

Either way you look at it, "()" doesn't belong there.

  I think I'm most annoyed that it calls is "the empty list". It
propagates the myth of lists in scalar contexts.

  Either way, yes, please do away with it.

$ perl -MData​::Dump=pp -e 'sub nil { +() } pp do { nil }; pp do { if (nil)
{ die } }'
()
undef
$ echo "Myth busted?"

Eirik

@p5pRT
Copy link
Author

p5pRT commented Nov 14, 2017

From zefram@fysh.org

Done in commit 77fae43.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Nov 16, 2017

@xsawyerx - Status changed from 'open' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2018

From @khwilliamson

Thank you for filing this report. You have helped make Perl better.

With the release yesterday of Perl 5.28.0, this and 185 other issues have been
resolved.

Perl 5.28.0 may be downloaded via​:
https://metacpan.org/release/XSAWYERX/perl-5.28.0

If you find that the problem persists, feel free to reopen this ticket.

@p5pRT p5pRT closed this as completed Jun 23, 2018
@p5pRT
Copy link
Author

p5pRT commented Jun 23, 2018

@khwilliamson - Status changed from 'pending release' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant