This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,2 @@
'A."
"65,

View file

@ -0,0 +1,4 @@
CHAR: katakana-letter-a .
"ア" first .
12450 1string print

View file

@ -0,0 +1,4 @@
fansh> 97.toChar
a
fansh> 'a'.toInt
97

View file

@ -0,0 +1,4 @@
println[char["a"]] // prints 97
println[char[97]] // prints a
println[char["Frink rules!"]] // prints [70, 114, 105, 110, 107, 32, 114, 117, 108, 101, 115, 33]
println[[70, 114, 105, 110, 107, 32, 114, 117, 108, 101, 115, 33]] // prints "Frink rules!"

View file

@ -0,0 +1,5 @@
# Code must be in 0 .. 255.
CHAR_INT(65);
# 'A'
INT_CHAR('Z');
# 90

View file

@ -0,0 +1 @@
97[]+''+p

View file

@ -0,0 +1,4 @@
'a')\;p
'a'(\;p
'a'0=p
'a'{}/p

View file

@ -0,0 +1,2 @@
printf ("%d\n", ('a' as char) as int)
printf ("%c\n", 97)

View file

@ -0,0 +1 @@
WRITE(Messagebox) ICHAR('a'), CHAR(97)

View file

@ -0,0 +1,6 @@
procedure main(arglist)
if *arglist > 0 then L := arglist else L := [97, "a"]
every x := !L do
write(x, " ==> ", char(integer(x)) | ord(x) ) # char produces a character, ord produces a number
end

View file

@ -0,0 +1,5 @@
4 u: 97 98 99 9786
abc☺
3 u: 7 u: 'abc☺'
97 98 99 9786

View file

@ -0,0 +1,2 @@
'a ord.
97 chr.

View file

@ -0,0 +1,5 @@
_ic "abcABC"
97 98 99 65 66 67
_ci 97 98 99 65 66 67
"abcABC"

View file

@ -0,0 +1,9 @@
: CHAR "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[" comb
'\\ comb -1 remove append "]^_`abcdefghijklmnopqrstuvwxyz{|}~" comb append ;
: CODE 95 iota 33 + ; : comb "" split ;
: extract' rot 1 compress index subscript expand drop ;
: chr CHAR CODE extract' ;
: ord CODE CHAR extract' ;
'a ord . # 97
97 chr . # a

View file

@ -0,0 +1,4 @@
charCode = 97
char$ = "a"
print chr$(charCode) 'prints a
print asc(char$) 'prints 97

View file

@ -0,0 +1,2 @@
print ascii "a ; 97
print char 97 ; a

View file

@ -0,0 +1,4 @@
|?- char_code(Char, 97), write(Char).
a
Char = a
yes

View file

@ -0,0 +1,4 @@
|?- char_code(a, Code), write(Code).
97
Code = 97
yes

View file

@ -0,0 +1,2 @@
WRITE $ASCII("M")
WRITE $CHAR(77)

View file

@ -0,0 +1,4 @@
> use StringTools in Ord( "A" ); Char( 65 ) end;
65
"A"

View file

@ -0,0 +1,5 @@
> convert( "A", bytes );
[65]
> convert( [65], bytes );
"A"

View file

@ -0,0 +1,2 @@
ToCharacterCode["abcd"]
FromCharacterCode[{97}]

View file

@ -0,0 +1,5 @@
ascii(65);
"A"
cint("A");
65

View file

@ -0,0 +1,14 @@
message "enter a letter: ";
string a;
a := readstring;
message decimal (ASCII a); % writes the decimal number of the first character
% of the string a
message "enter a number: ";
num := scantokens readstring;
message char num; % num can be anything between 0 and 255; what will be seen
% on output depends on the encoding used by the "terminal"; e.g.
% any code beyond 127 when UTF-8 encoding is in use will give
% a bad encoding; e.g. to see correctly an "è", we should write
message char10; % (this add a newline...)
message char hex"c3" & char hex"a8"; % since C3 A8 is the UTF-8 encoding for "è"
end

View file

@ -0,0 +1,18 @@
MODULE asc;
IMPORT InOut;
VAR letter : CHAR;
ascii : CARDINAL;
BEGIN
letter := 'a';
InOut.Write (letter);
ascii := ORD (letter);
InOut.Write (11C); (* ASCII TAB *)
InOut.WriteCard (ascii, 8);
ascii := ascii - ORD ('0');
InOut.Write (11C); (* ASCII TAB *)
InOut.Write (CHR (ascii));
InOut.WriteLn
END asc.

View file

@ -0,0 +1,2 @@
jan@Beryllium:~/modula/rosetta$ ./asc
a 97 1

View file

@ -0,0 +1,2 @@
ORD('a') (* Returns 97 *)
VAL(97, CHAR); (* Returns 'a' *)