develooper Front page | perl.perl6.language | Postings from May 2005

Declarations of constants

Thread Next
From:
Ingo Blechschmidt
Date:
May 27, 2005 08:21
Subject:
Declarations of constants
Message ID:
d77dfl$j4a$1@sea.gmane.org
Hi,

  # Way 1
  my $MEANING_OF_LIFE is constant = 42;


  # Way 2
  my &MEANING_OF_LIVE = -> () { 42 };
  # or
  sub MEANING_OF_LIVE () { 42 }

  # Then one can use sigilless constants:
  say MEANING_OF_LIVE;


  # Way 3 (still possible?)
  use constant MEANING_OF_LIVE => 42;


  # Way 4 (evil?)
  macro MEANING_OF_LIVE { "42" }


  # Way 5 (overloading of the numification of Class -- evil)
  Class does role {
    method *prefix:<+> (MEANING_OF_LIVE $class:) {
      42;
    }
  }
  class MEANING_OF_LIVE {}
  
  say +MEANING_OF_LIVE;


  # Please add more ways :)


--Ingo

-- 
Linux, the choice of a GNU | Black holes result when God divides the
generation on a dual AMD   | universe by zero.  
Athlon!                    |


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