Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -1,21 +1,12 @@
package main
import "fmt"
import (
"fmt"
)
func main() {
// yes, there is more concise syntax, but this makes
// the data types very clear.
var b byte = 'a'
var r rune = 'π'
var s string = "aπ"
fmt.Println(b, r, s)
fmt.Println("string cast to []rune:", []rune(s))
// A range loop over a string gives runes, not bytes
fmt.Print(" string range loop: ")
for _, c := range s {
fmt.Print(c, " ") // c is type rune
}
// We can also print the bytes of a string without an explicit loop
fmt.Printf("\n string bytes: % #x\n", s)
// Given a character value in your language, print its code
fmt.Printf("%d\n", 'A') // prt 65
// Given a code, print out the corresponding character.
fmt.Printf("%c\n", 65) // prt A
}

View file

@ -1,3 +1,21 @@
b := byte(97)
r := rune(960)
fmt.Printf("%c %c\n%c %c\n", 97, 960, b, r)
package main
import "fmt"
func main() {
// yes, there is more concise syntax, but this makes
// the data types very clear.
var b byte = 'a'
var r rune = 'π'
var s string = "aπ"
fmt.Println(b, r, s)
fmt.Println("string cast to []rune:", []rune(s))
// A range loop over a string gives runes, not bytes
fmt.Print(" string range loop: ")
for _, c := range s {
fmt.Print(c, " ") // c is type rune
}
// We can also print the bytes of a string without an explicit loop
fmt.Printf("\n string bytes: % #x\n", s)
}

View file

@ -1,3 +1,3 @@
fmt.Println(string(97)) // prints "a"
fmt.Println(string(960)) // prints "π"
fmt.Println(string([]rune{97, 960})) // prints "aπ"
b := byte(97)
r := rune(960)
fmt.Printf("%c %c\n%c %c\n", 97, 960, b, r)

View file

@ -0,0 +1,3 @@
fmt.Println(string(97)) // prints "a"
fmt.Println(string(960)) // prints "π"
fmt.Println(string([]rune{97, 960})) // prints "aπ"

View file

@ -1,2 +1,27 @@
say ord('𪚥').fmt('0x%04x');
say chr(0x2a6a5);
for 'AΑА𪚥🇺🇸👨👩👧👦'.comb {
.put for
[ 'Character',
'Character name',
'Unicode property',
'Ordinal(s)',
'Hex ordinal(s)',
'UTF-8',
'UTF-16LE',
'UTF-16BE',
'Round trip by name',
'Round trip by ordinal'
]».fmt('%21s:')
Z
[ $_,
.uninames.join(', '),
.uniprops,
.ords,
.ords.fmt('0x%X'),
.encode('utf8' )».fmt('%02X'),
.encode('utf16le')».fmt('%02X').join.comb(4),
.encode('utf16be')».fmt('%02X').join.comb(4),
.uninames».uniparse.join,
.ords.chrs
];
say '';
}

View file

@ -0,0 +1,19 @@
use strict;
use warnings;
use utf8;
binmode(STDOUT, ':utf8');
use Encode;
use Unicode::UCD 'charinfo';
use List::AllUtils qw(zip natatime);
for my $c (split //, 'AΑА薵') {
my $o = ord $c;
my $utf8 = join '', map { sprintf "%x ", ord } split //, Encode::encode("utf8", $c);
my $iterator = natatime 2, zip
@{['Character', 'Character name', 'Ordinal(s)', 'Hex ordinal(s)', 'UTF-8', 'Round trip']},
@{[ $c, charinfo($o)->{'name'}, $o, sprintf("0x%x",$o), $utf8, chr $o, ]};
while ( my ($label, $value) = $iterator->() ) {
printf "%14s: %s\n", $label, $value
}
print "\n";
}

View file

@ -0,0 +1,19 @@
use strict;
use warnings;
use feature 'say';
use utf8;
binmode(STDOUT, ':utf8');
use Unicode::Normalize 'NFC';
use Unicode::UCD qw(charinfo charprop);
while ('Δ̂🇺🇸👨‍👩‍👧‍👦' =~ /(\X)/g) {
my @ordinals = map { ord } split //, my $c = $1;
printf "%14s: %s\n"x7 . "\n",
'Character', NFC $c,
'Character name', join(', ', map { charinfo($_)->{'name'} } @ordinals),
'Unicode property', join(', ', map { charprop($_, "Gc") } @ordinals),
'Ordinal(s)', join(' ', @ordinals),
'Hex ordinal(s)', join(' ', map { sprintf("0x%x", $_) } @ordinals),
'UTF-8', join('', map { sprintf "%x ", ord } (utf8::encode($c), split //, $c)),
'Round trip', join('', map { chr } @ordinals);
}

View file

@ -1,2 +0,0 @@
print ord('a'), "\n"; # prints "97"
print chr(97), "\n"; # prints "a"

View file

@ -0,0 +1,4 @@
> "a".ord
=> 97
> 97.chr
=> "a"