Raku By Example
View me onGitHub
## 匹配汉字

say so '你好'~~ /你好/;               # doesn't need to be quoted
say '你好'.uniprop('Script');        # Han
say unimatch('','Han');            # True
say unimatch('','Hani');           # True
say '你好, hello'.uniprop('Script'); # Han
say '안녕하세요'.uniprop('Script');    # Hangul
say 'こんにちは'.uniprop('Script');   # Hiragana
say uniname('');                   # CJK UNIFIED IDEOGRAPH-4E00(象形文字)

# http://www.unicode.org/reports/tr24/
# <:Hani> 是 <:Han> 的长形式
say 'Raku 入门abc指南'.comb(/<:Han>+/).join(',');  # 入门,指南
say 'Raku 入门abc指南'.comb(/<:Hani>+/).join(','); # 入门,指南

say so ₆ ~~ /<:No>/;

## ord

say "\c[SUBSCRIPT ZERO]".ord;   # 8320
say "\c[SUBSCRIPT ONE]".ord;    # 8321
say "\c[SUBSCRIPT TWO]".ord;    # 8322
say "\c[SUBSCRIPT THREE]".ord;  # 8323
say "\c[SUBSCRIPT FOUR]".ord;   # 8324
say "\c[SUBSCRIPT FIVE]".ord;   # 8325
say "\c[SUBSCRIPT SIX]".ord;    # 8326
say "\c[SUBSCRIPT SEVEN]".ord;  # 8327
say "\c[SUBSCRIPT EIGHT]".ord;  # 8328
say "\c[SUBSCRIPT NINE]".ord;   # 8329


say "\c[SUPERSCRIPT ZERO]".ord;  # 8304
say "\c[SUPERSCRIPT ONE]".ord;   # 185
say "\c[SUPERSCRIPT TWO]".ord;   # 178
say "\c[SUPERSCRIPT THREE]".ord; # 179
say "\c[SUPERSCRIPT FOUR]".ord;  # 8308
say "\c[SUPERSCRIPT FIVE]".ord;  # 8309
say "\c[SUPERSCRIPT SIX]".ord;   # 8310
say "\c[SUPERSCRIPT SEVEN]".ord; # 8311
say "\c[SUPERSCRIPT EIGHT]".ord; # 8312
say "\c[SUPERSCRIPT NINE]".ord;  # 8313

## 下标

#!/usr/bin/env perl6

('' ~ .chr ~ '' ~ .uniname ~ ', ').say if .uniname ~~ /SUBSCRIPT/ for 2070 .. 0x209F;

#`(
「ᵢ」LATIN SUBSCRIPT SMALL LETTER I,
「ᵣ」LATIN SUBSCRIPT SMALL LETTER R,
「ᵤ」LATIN SUBSCRIPT SMALL LETTER U,
「ᵥ」LATIN SUBSCRIPT SMALL LETTER V,
「ᵦ」GREEK SUBSCRIPT SMALL LETTER BETA,
「ᵧ」GREEK SUBSCRIPT SMALL LETTER GAMMA,
「ᵨ」GREEK SUBSCRIPT SMALL LETTER RHO,
「ᵩ」GREEK SUBSCRIPT SMALL LETTER PHI,
「ᵪ」GREEK SUBSCRIPT SMALL LETTER CHI,
「₀」SUBSCRIPT ZERO,
「₁」SUBSCRIPT ONE,
「₂」SUBSCRIPT TWO,
「₃」SUBSCRIPT THREE,
「₄」SUBSCRIPT FOUR,
「₅」SUBSCRIPT FIVE,
「₆」SUBSCRIPT SIX,
「₇」SUBSCRIPT SEVEN,
「₈」SUBSCRIPT EIGHT,
「₉」SUBSCRIPT NINE,
「₊」SUBSCRIPT PLUS SIGN,
「₋」SUBSCRIPT MINUS,
「₌」SUBSCRIPT EQUALS SIGN,
「₍」SUBSCRIPT LEFT PARENTHESIS,
「₎」SUBSCRIPT RIGHT PARENTHESIS,
「ₐ」LATIN SUBSCRIPT SMALL LETTER A,
「ₑ」LATIN SUBSCRIPT SMALL LETTER E,
「ₒ」LATIN SUBSCRIPT SMALL LETTER O,
「ₓ」LATIN SUBSCRIPT SMALL LETTER X,
「ₔ」LATIN SUBSCRIPT SMALL LETTER SCHWA,
「ₕ」LATIN SUBSCRIPT SMALL LETTER H,
「ₖ」LATIN SUBSCRIPT SMALL LETTER K,
「ₗ」LATIN SUBSCRIPT SMALL LETTER L,
「ₘ」LATIN SUBSCRIPT SMALL LETTER M,
「ₙ」LATIN SUBSCRIPT SMALL LETTER N,
「ₚ」LATIN SUBSCRIPT SMALL LETTER P,
「ₛ」LATIN SUBSCRIPT SMALL LETTER S,
「ₜ」LATIN SUBSCRIPT SMALL LETTER T,
)

('' ~ .chr ~ '' ~ .uniname ~ ', ').say if .uniname ~~ /SUBSCRIPT/ for 1 .. 0x2C7C;

#`(
「ٖ」ARABIC SUBSCRIPT ALEF,
「ᵢ」LATIN SUBSCRIPT SMALL LETTER I,
「ᵣ」LATIN SUBSCRIPT SMALL LETTER R,
「ᵤ」LATIN SUBSCRIPT SMALL LETTER U,
「ᵥ」LATIN SUBSCRIPT SMALL LETTER V,
「ᵦ」GREEK SUBSCRIPT SMALL LETTER BETA,
「ᵧ」GREEK SUBSCRIPT SMALL LETTER GAMMA,
「ᵨ」GREEK SUBSCRIPT SMALL LETTER RHO,
「ᵩ」GREEK SUBSCRIPT SMALL LETTER PHI,
「ᵪ」GREEK SUBSCRIPT SMALL LETTER CHI,
「₀」SUBSCRIPT ZERO,
「₁」SUBSCRIPT ONE,
「₂」SUBSCRIPT TWO,
「₃」SUBSCRIPT THREE,
「₄」SUBSCRIPT FOUR,
「₅」SUBSCRIPT FIVE,
「₆」SUBSCRIPT SIX,
「₇」SUBSCRIPT SEVEN,
「₈」SUBSCRIPT EIGHT,
「₉」SUBSCRIPT NINE,
「₊」SUBSCRIPT PLUS SIGN,
「₋」SUBSCRIPT MINUS,
「₌」SUBSCRIPT EQUALS SIGN,
「₍」SUBSCRIPT LEFT PARENTHESIS,
「₎」SUBSCRIPT RIGHT PARENTHESIS,
「ₐ」LATIN SUBSCRIPT SMALL LETTER A,
「ₑ」LATIN SUBSCRIPT SMALL LETTER E,
「ₒ」LATIN SUBSCRIPT SMALL LETTER O,
「ₓ」LATIN SUBSCRIPT SMALL LETTER X,
「ₔ」LATIN SUBSCRIPT SMALL LETTER SCHWA,
「ₕ」LATIN SUBSCRIPT SMALL LETTER H,
「ₖ」LATIN SUBSCRIPT SMALL LETTER K,
「ₗ」LATIN SUBSCRIPT SMALL LETTER L,
「ₘ」LATIN SUBSCRIPT SMALL LETTER M,
「ₙ」LATIN SUBSCRIPT SMALL LETTER N,
「ₚ」LATIN SUBSCRIPT SMALL LETTER P,
「ₛ」LATIN SUBSCRIPT SMALL LETTER S,
「ₜ」LATIN SUBSCRIPT SMALL LETTER T,
「⨧」PLUS SIGN WITH SUBSCRIPT TWO,
「ⱼ」LATIN SUBSCRIPT SMALL LETTER J,
)

## 上标

('' ~ .chr ~ '' ~ .uniname ~ ', ').say if .uniname ~~ /SUPERSCRIPT/ for 2070 .. 0x209F;

#`(
「⁰」SUPERSCRIPT ZERO,
「ⁱ」SUPERSCRIPT LATIN SMALL LETTER I,
「⁴」SUPERSCRIPT FOUR,
「⁵」SUPERSCRIPT FIVE,
「⁶」SUPERSCRIPT SIX,
「⁷」SUPERSCRIPT SEVEN,
「⁸」SUPERSCRIPT EIGHT,
「⁹」SUPERSCRIPT NINE,
「⁺」SUPERSCRIPT PLUS SIGN,
「⁻」SUPERSCRIPT MINUS,
「⁼」SUPERSCRIPT EQUALS SIGN,
「⁽」SUPERSCRIPT LEFT PARENTHESIS,
「⁾」SUPERSCRIPT RIGHT PARENTHESIS,
「ⁿ」SUPERSCRIPT LATIN SMALL LETTER N,
)


# or
('' ~ .chr ~ '' ~ .uniname ~ ', ').say if .uniname ~~ /SUPERSCRIPT/ for 1 .. 0x10FFFD;

# or

('' ~ .chr ~ '' ~ .uniname ~ ', ').say if .uniname ~~ /SUPERSCRIPT/ for 0x00B2 .. 0xFCD9;

#`(
「²」SUPERSCRIPT TWO,
「³」SUPERSCRIPT THREE,
「¹」SUPERSCRIPT ONE,
「ٰ」ARABIC LETTER SUPERSCRIPT ALEF,
「ܑ」SYRIAC LETTER SUPERSCRIPT ALAPH,
「⁰」SUPERSCRIPT ZERO,
「ⁱ」SUPERSCRIPT LATIN SMALL LETTER I,
「⁴」SUPERSCRIPT FOUR,
「⁵」SUPERSCRIPT FIVE,
「⁶」SUPERSCRIPT SIX,
「⁷」SUPERSCRIPT SEVEN,
「⁸」SUPERSCRIPT EIGHT,
「⁹」SUPERSCRIPT NINE,
「⁺」SUPERSCRIPT PLUS SIGN,
「⁻」SUPERSCRIPT MINUS,
「⁼」SUPERSCRIPT EQUALS SIGN,
「⁽」SUPERSCRIPT LEFT PARENTHESIS,
「⁾」SUPERSCRIPT RIGHT PARENTHESIS,
「ⁿ」SUPERSCRIPT LATIN SMALL LETTER N,
「ﱛ」ARABIC LIGATURE THAL WITH SUPERSCRIPT ALEF ISOLATED FORM,
「ﱜ」ARABIC LIGATURE REH WITH SUPERSCRIPT ALEF ISOLATED FORM,
「ﱝ」ARABIC LIGATURE ALEF MAKSURA WITH SUPERSCRIPT ALEF ISOLATED FORM,
「ﱣ」ARABIC LIGATURE SHADDA WITH SUPERSCRIPT ALEF ISOLATED FORM,
「ﲐ」ARABIC LIGATURE ALEF MAKSURA WITH SUPERSCRIPT ALEF FINAL FORM,
「ﳙ」ARABIC LIGATURE HEH WITH SUPERSCRIPT ALEF INITIAL FORM,
)

## Unicode 数字

say ''.uniname;  # FRACTION NUMERATOR ONE

say ''.uniname; # VULGAR FRACTION ZERO THIRDS
say ''.uniname;  # VULGAR FRACTION TWO THIRDS
say '¾'.uniname;  # VULGAR FRACTION THREE QUARTERS

say ''.uniname; # VULGAR FRACTION TWO FIFTHS
say ''.uniname; # VULGAR FRACTION THREE FIFTHS
say ''.uniname; # VULGAR FRACTION FOUR FIFTHS

say ''.uniname; #  VULGAR FRACTION FIVE SIXTHS


say ''.uniname;  # VULGAR FRACTION THREE EIGHTHS
say ''.uniname;  # VULGAR FRACTION FIVE EIGHTHS
say ''.uniname; # VULGAR FRACTION SEVEN EIGHTHS

say '½'.uniname; # VULGAR FRACTION ONE HALF
say ''.uniname; # VULGAR FRACTION ONE THIRD
say '¼'.uniname; # VULGAR FRACTION ONE QUARTER
say ''.uniname; # VULGAR FRACTION ONE FIFTH
say ''.uniname; # VULGAR FRACTION ONE SIXTH
say ''.uniname; # VULGAR FRACTION ONE SEVENTH
say ''.uniname;  # VULGAR FRACTION ONE EIGHTH
say ''.uniname; # VULGAR FRACTION ONE NINTH
say ''.uniname; # VULGAR FRACTION ONE TENTH

say "\c[VULGAR FRACTION ONE HALF]";    # ½
say "\c[VULGAR FRACTION ONE THIRD]";   # ⅓
say "\c[VULGAR FRACTION ONE QUARTER]"; # ¼
say "\c[VULGAR FRACTION ONE FIFTH]";   # ⅕
say "\c[VULGAR FRACTION ONE SIXTH]";   # ⅙
say "\c[VULGAR FRACTION ONE SEVENTH]"; # ⅐
say "\c[VULGAR FRACTION ONE EIGHTH]";  # ⅛
say "\c[VULGAR FRACTION ONE NINTH]";   # ⅑
say "\c[VULGAR FRACTION ONE TENTH]";   # ⅒

say* 3;
say ''.uniname;  # VULGAR FRACTION ONE TENTH
say ''.uniname;  # FRACTION SLASH
say "\x[2044]";   # ⁄, fraction slash
say "\x[2079,2044,2081,2080]"; # ⁹⁄₁₀
say '⁹⁄₁₀'.uniname; # SUPERSCRIPT NINE
say ''.uniname;  # SUPERSCRIPT LATIN SMALL LETTER N

say ''.uniprop('Script'); # Latin

say so ''.uniname ~~ /SCRIPT/; # True

for 1 .. 0x10FFFD {
    .chr.print if .chr ~~ /<:digit>/ && .uniname ~~ /Script/;
}

# SUBSCRIPT ZERO - SUBSCRIPT NINE
say "\x[2080]"; # ₀
say "\x[2081]"; # ₁
say "\x[2082]"; # ₂
say "\x[2083]"; # ₃
say "\x[2084]"; # ₄
say "\x[2085]"; # ₅
say "\x[2086]"; # ₆
say "\x[2087]"; # ₇
say "\x[2088]"; # ₈
say "\x[2089]"; # ₉

say "SUBSCRIPT ZERO".uniparse;  # ₀
say "SUBSCRIPT ONE".uniparse;   # ₁
say "SUBSCRIPT TWO".uniparse;   # ₂
say "SUBSCRIPT THREE".uniparse; # ₃
say "SUBSCRIPT FOUR".uniparse;  # ₄
say "SUBSCRIPT FIVE".uniparse;  # ₅
say "SUBSCRIPT SIX".uniparse;   # ₆
say "SUBSCRIPT SEVEN".uniparse; # ₇
say "SUBSCRIPT EIGHT".uniparse; # ₈
say "SUBSCRIPT NINE".uniparse;  # ₉

say "\c[SUBSCRIPT ZERO]";  # ₀
say "\c[SUBSCRIPT ONE]";   # ₁
say "\c[SUBSCRIPT TWO]";   # ₂
say "\c[SUBSCRIPT THREE]"; # ₃
say "\c[SUBSCRIPT FOUR]";  # ₄
say "\c[SUBSCRIPT FIVE]";  # ₅
say "\c[SUBSCRIPT SIX]";   # ₆
say "\c[SUBSCRIPT SEVEN]"; # ₇
say "\c[SUBSCRIPT EIGHT]"; # ₈
say "\c[SUBSCRIPT NINE]";  # ₉

say ''.uniname; # SUBSCRIPT ZERO
say ''.uniname; # SUBSCRIPT ONE
say ''.uniname; # SUBSCRIPT TWO
say ''.uniname; # SUBSCRIPT THREE
say ''.uniname; # SUBSCRIPT FOUR
say ''.uniname; # SUBSCRIPT FIVE
say ''.uniname; # SUBSCRIPT SIX
say ''.uniname; # SUBSCRIPT SEVEN
say ''.uniname; # SUBSCRIPT EIGHT
say ''.uniname; # SUBSCRIPT NINE

# SUPERSCRIPT ZERO - SUPERSCRIPT NINE
say "\c[SUPERSCRIPT ZERO]".ord;  # 8304
say "\c[SUPERSCRIPT ONE]".ord;   # 185
say "\c[SUPERSCRIPT TWO]".ord;   # 178
say "\c[SUPERSCRIPT THREE]".ord; # 179
say "\c[SUPERSCRIPT FOUR]".ord;  # 8308
say "\c[SUPERSCRIPT FIVE]".ord;  # 8309
say "\c[SUPERSCRIPT SIX]".ord;   # 8310
say "\c[SUPERSCRIPT SEVEN]".ord; # 8311
say "\c[SUPERSCRIPT EIGHT]".ord; # 8312
say "\c[SUPERSCRIPT NINE]".ord;  # 8313

say "SUPERSCRIPT ZERO".uniparse;  # ⁰
say "SUPERSCRIPT ONE".uniparse;   # ¹
say "SUPERSCRIPT TWO".uniparse;   # ²
say "SUPERSCRIPT THREE".uniparse; # ³
say "SUPERSCRIPT FOUR".uniparse;  # ⁴
say "SUPERSCRIPT FIVE".uniparse;  # ⁵
say "SUPERSCRIPT SIX".uniparse;   # ⁶
say "SUPERSCRIPT SEVEN".uniparse; # ⁷
say "SUPERSCRIPT EIGHT".uniparse; # ⁸
say "SUPERSCRIPT NINE".uniparse;  # ⁹

say "\c[SUPERSCRIPT ZERO]";  # ⁰
say "\c[SUPERSCRIPT ONE]";   # ¹
say "\c[SUPERSCRIPT TWO]";   # ²
say "\c[SUPERSCRIPT THREE]"; # ³
say "\c[SUPERSCRIPT FOUR]";  # ⁴
say "\c[SUPERSCRIPT FIVE]";  # ⁵
say "\c[SUPERSCRIPT SIX]";   # ⁶
say "\c[SUPERSCRIPT SEVEN]"; # ⁷
say "\c[SUPERSCRIPT EIGHT]"; # ⁸
say "\c[SUPERSCRIPT NINE]";  # ⁹

say ''.uniname; # SUPERSCRIPT ZERO
say '¹'.uniname; # SUPERSCRIPT ONE
say '²'.uniname; # SUPERSCRIPT TWO
say '³'.uniname; # SUPERSCRIPT THREE
say ''.uniname; # SUPERSCRIPT FOUR
say ''.uniname; # SUPERSCRIPT FIVE
say ''.uniname; # SUPERSCRIPT SIX
say ''.uniname; # SUPERSCRIPT SEVEN
say ''.uniname; # SUPERSCRIPT EIGHT
say ''.uniname; # SUPERSCRIPT NINE


say "\x[2140]"; # ⅀
say "\x[2142]"; # ⅂
say "\x[2143]"; # ⅃
say "\x[2144]"; # ⅄
say "\x[2145]"; # ⅅ
say "\x[2146]"; # ⅆ
say "\x[2147]"; # ⅇ
say "\x[2148]"; # ⅈ
say "\x[2149]"; # ⅉ
say "\x[2150]"; # ⅐
say "\x[2151]"; # ⅑
say "\x[2152]"; # ⅒
say "\x[2153]"; # ⅓
say "\x[2154]"; # ⅔
say "\x[2155]"; # ⅕
say "\x[2156]"; # ⅖
say "\x[2157]"; # ⅗
say "\x[2158]"; # ⅘
say "\x[2159]"; # ⅙
say "\x[2160]"; # Ⅰ
say "\x[2161]"; # Ⅱ
say "\x[2162]"; # Ⅲ
say "\x[2163]"; # Ⅳ
say "\x[2164]"; # Ⅴ
say "\x[2165]"; # Ⅵ
say "\x[2166]"; # Ⅶ
say "\x[2167]"; # Ⅷ
say "\x[2168]"; # Ⅸ
say "\x[2169]"; # Ⅹ
say "\x[2170]"; # ⅰ
say "\x[2171]"; # ⅱ
say "\x[2172]"; # ⅲ
say "\x[2173]"; # ⅳ
say "\x[2174]"; # ⅴ
say "\x[2175]"; # ⅵ
say "\x[2176]"; # ⅶ
say "\x[2177]"; # ⅷ
say "\x[2178]"; # ⅸ
say "\x[2179]"; # ⅹ
say "\x[2180]"; # ↀ
say "\x[2181]"; # ↁ
say "\x[2182]"; # ↂ
say "\x[2183]"; # Ↄ
say "\x[2184]"; # ↄ
say "\x[2185]"; # ↅ
say "\x[2186]"; # ↆ
say "\x[2187]"; # ↇ

## Unicode 分数

# http://unicodefractions.com

say '½'.uniname; # VULGAR FRACTION ONE HALF
say ''.uniname; # VULGAR FRACTION ONE THIRD
say ''.uniname; # VULGAR FRACTION TWO THIRDS
say '¼'.uniname; # VULGAR FRACTION ONE QUARTER
say '¾'.uniname; # VULGAR FRACTION THREE QUARTERS
say ''.uniname; # VULGAR FRACTION ONE FIFTH
say ''.uniname; # VULGAR FRACTION TWO FIFTHS
say ''.uniname; # VULGAR FRACTION THREE FIFTHS
say ''.uniname; # VULGAR FRACTION FOUR FIFTHS
say ''.uniname; # VULGAR FRACTION ONE SIXTH
say ''.uniname; # VULGAR FRACTION FIVE SIXTHS
say ''.uniname; # VULGAR FRACTION ONE SEVENTH
say ''.uniname; # VULGAR FRACTION ONE EIGHTH
say ''.uniname; # VULGAR FRACTION THREE EIGHTHS
say ''.uniname; # VULGAR FRACTION FIVE EIGHTHS
say ''.uniname; # VULGAR FRACTION SEVEN EIGHTHS
say ''.uniname; # VULGAR FRACTION ONE NINTH
say ''.uniname; # VULGAR FRACTION ONE TENTH


say '³⁄₄₇'.ords; # (179 8260 8324 8327)

## unicode invulgar fractions

say '³⁄₄₇'.ords;        # (179 8260 8324 8327)
say "\c[179]";          # ³
say "\c[179]".uniname;  # SUPERSCRIPT THREE
say "\c[8260]";         # ⁄
say "\c[8260]".uniname; # FRACTION SLASH

# if we want 5/49 fraction
say "\c[8309,8260,8324,8329]";
say '⁵⁄₄₉'.ords; # (8309 8260 8324 8329)
say (⁵⁄₄₉).WHAT;

# generate heart
sub i-love-you {
    for 15 ...^ -15 -> $y {
        for -150, -145 ...^ 150 -> $x {
            if ( ($x/100+ ($y/10- 1- (($x/100)²) * (($y/10)³ ) <= 0 {
                print('*');
            } else {
                print(" ");
            }
        }
        say();
    }
}

i-love-you();

## unival

put unival(''); # 1
put unival(''); # 2
put unival(''); # 3
put unival(''); # 4
put unival(''); # 5
put unival(''); # 6
put unival(''); # 7
put unival(''); # 8
put unival(''); # 9
put unival(''); # 10
put unival(''); # 100
put unival(''); # 1000
put unival(''); # 10000
put unival('亿'); # 100000000

put unival(''); # 1
put unival(''); # 2
put unival(''); # 3
put unival(''); # 4
put unival(''); # 5
put unival(''); # 6
put unival(''); # 7
put unival(''); # 8
put unival(''); # 9
put unival(''); # 10
put unival(''); # 100
put unival(''); # 1000
put unival(''); # 10000
put unival(''); # 100000000

put univals('三千六百'); # (3 1000 6 100)
put univals('四万万');   # (4 10000 10000)
put univals('十三亿');   # (10 3 100000000)