Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

A sub named ∃

by diotalevi (Canon)
on Nov 29, 2006 at 05:58 UTC ( [id://586622]=perlquestion: print w/replies, xml ) Need Help??

diotalevi has asked for the wisdom of the Perl Monks concerning the following question:

I recently figured out how to type unicode in Emacs so I thought it'd be fun to write some functions with unicode names. Nope. It didn't work. I recalled [5.8.0 Note] A Sub Named Sigma but the same magic doesn't work here. Am I doing this wrong or is this a bug in my perl? I tried both 5.8.8 and bleadperl.

use utf8;
use strict;
use warnings;
use Test::More tests => 2;

sub ∃ (&\@) { my $cb = shift @_; $cb->() and return 1 for @_; 0 }
sub ∄ (&\@) { not ∃( @_ ) }

my @numbers = 1 .. 10;
ok( ∃ { /\d/ } @numbers, '∃' );
ok( ∄ { /[[:alpha:]]/ } @numbers, '∄' );

1..2 Illegal declaration of anonymous subroutine at /home/josh/src/any.pl l +ine 6. # Looks like your test died before it could output anything.

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Replies are listed 'Best First'.
Re: A sub named ∃ (\w)
by tye (Sage) on Nov 29, 2006 at 06:17 UTC

    Subroutine names have to start with a letter. Sigma is a letter, just in a different language. "not a member of" is not a letter. Well, that's my guess, anyway.

    - tye        

      Yeah, you're right. ∃ isn't an identifier character per unicore/gc_sc/IdStart.pl.

      ok( "\x{2203}" !~ /\p{IdStart}/ )

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: A sub named ∃
by monarch (Priest) on Nov 29, 2006 at 08:28 UTC
    I tried this on NT Emacs (although with a different language) using a utf8 source file:

      use utf8;
      use Test::Simple tests=>1;

      use strict;

      sub трщь {
        return 1;
      }

      ok( трщь(), "Unicode Sub" );

    The result was:

    C:\temp>perl -w russian.pl 1..1 ok 1 - Unicode Sub
    on Windows 2000.
Re: A sub named ∃
by Steve_p (Priest) on Nov 30, 2006 at 03:41 UTC

    I believe that this bug is to blame. There are plans to fix it, but, as of yet, I don't know that there has been any progress towards resolving it.

      I suspect you know the situation better than me, but why in this particular case the explanation that
      ∃!~/\w/
      will not suffice?
      Perl allows utf8-names from letters of non-English alphabets, although documentation strictly warns against this.

        /w isn't the pattern for matching the first character in identifiers. I never consider \w when matching that first character. In unicode, the pattern to follow is likely /\A\p{IdFirst}\w*\z/. In ASCII, the pattern is /\A[[:alpha:]_]\w*\z/. The pattern /\^\w+\z/ is always wrong when matching identifiers.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      Note: In the following source code,
      replace "∃" with the UTF-8 representation of "∃", and
      replace "трщь" with the UTF-8 representation of "трщь".

      use strict; use warnings; no warnings 'redefine'; for ( [ "Symbol, use utf8: " => "use utf8; sub ∃ {}" ], [ "Symbol, no utf8: " => "no utf8; sub ∃ {}" ], [ "Russian, use utf8: " => "use utf8; sub трщ&#11 +00; {}" ], [ "Russian, no utf8: " => "no utf8; sub трщ&#11 +00; {}" ], ) { print $_->[0], eval "$_->[1]; 1" ? "Success\n" : $@; }
      outputs
      Symbol, use utf8: Illegal declaration of anonymous subroutine at (eva +l 1) line 1. Symbol, no utf8: Illegal declaration of anonymous subroutine at (eva +l 2) line 1. Russian, use utf8: Success Russian, no utf8: Illegal declaration of anonymous subroutine at (eva +l 4) line 1.

      If the problem is what you say it is, wouldn't use utf8 have no effect on the error?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://586622]
Approved by davido
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-19 14:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found