langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,23 @@
/* NetRexx */
options replace format comments java crossref symbols nobinary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
-- create some sample data: character, hex and unicode
samp = ' ' || 'a'.sequence('e') || '$' || '\xa2'.sequence('\xa5') || '\u20a0'.sequence('\u20b5')
-- use the C2D C2X D2C and X2C built-in functions
say "'"samp"'"
say ' | Chr C2D C2X D2C X2C'
say '---+ --- ------ ---- --- ---'
loop ci = 1 to samp.length
cc = samp.substr(ci, 1)
cd = cc.c2d -- char to decimal
cx = cc.c2x -- char to hexadecimal
dc = cd.d2c -- decimal to char
xc = cx.x2c -- hexadecimal to char
say ci.right(3)"| '"cc"'" cd.right(6) cx.right(4, 0) "'"dc"' '"xc"'"
end ci
return

View file

@ -0,0 +1,2 @@
Printf.printf "%d\n" (int_of_char 'a'); (* prints "97" *)
Printf.printf "%c\n" (char_of_int 97); (* prints "a" *)

View file

@ -0,0 +1,4 @@
# Char.code ;;
- : char -> int = <fun>
# Char.chr;;
- : int -> char = <fun>

View file

@ -0,0 +1,11 @@
MODULE Ascii;
IMPORT Out;
VAR
c: CHAR;
d: INTEGER;
BEGIN
c := CHR(97);
d := ORD("a");
Out.Int(d,3);Out.Ln;
Out.Char(c);Out.Ln
END Ascii.

View file

@ -0,0 +1,2 @@
'a'->As(Int)->PrintLine();
97->As(Char)->PrintLine();

View file

@ -0,0 +1,4 @@
MESSAGE
CHR(97) SKIP
ASC("a")
VIEW-AS ALERT-BOX.

View file

@ -0,0 +1,2 @@
{System.show &a} %% prints "97"
{System.showInfo [97]} %% prints "a"

View file

@ -0,0 +1,2 @@
print(Vecsmall("a")[1]);
print(Strchr([72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]))

View file

@ -0,0 +1,5 @@
declare 1 u union,
2 c character (1),
2 i fixed binary (8) unsigned;
c = 'a'; put skip list (i); /* prints 97 */
i = 97; put skip list (c); /* prints 'a' */

View file

@ -0,0 +1,2 @@
writeln(ord('a'));
writeln(chr(97));

View file

@ -0,0 +1,2 @@
say ord('𪚥').fmt('0x%04x');
say chr(0x2a6a5);

View file

@ -0,0 +1 @@
$char = [char] 'a'

View file

@ -0,0 +1 @@
$charcode = [int] $char # => 97

View file

@ -0,0 +1 @@
[int] [char] '☺' # => 9786

View file

@ -0,0 +1,2 @@
[char] 97 # a
[char] 9786 # ☺

View file

@ -0,0 +1,11 @@
If OpenConsole()
;Results are the same when compiled for Ascii or Unicode
charCode.c = 97
Char.s = "a"
PrintN(Chr(charCode)) ;prints a
PrintN(Str(Asc(Char))) ;prints 97
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf

View file

@ -0,0 +1,11 @@
If OpenConsole()
;UTF-8 encoding compiled for Unicode (UCS-2)
charCode.c = 960
Char.s = "π"
PrintN(Chr(charCode)) ;prints π
PrintN(Str(Asc(Char))) ;prints 960
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf

View file

@ -0,0 +1 @@
'c putc

View file

@ -0,0 +1,2 @@
print chr$(97) 'prints a
print asc("a") 'prints 97

View file

@ -0,0 +1,14 @@
define('chr(n)') :(chr_end)
chr &alphabet tab(n) len(1) . chr :s(return)f(freturn)
chr_end
define('asc(str)c') :(asc_end)
asc str len(1) . c
&alphabet break(c) @asc :s(return)f(freturn)
asc_end
* # Test and display
output = char(65) ;* Built-in
output = chr(65)
output = asc('A')
end

View file

@ -0,0 +1,2 @@
writeln(ord('a'));
writeln(chr(97));

View file

@ -0,0 +1,2 @@
$a code.
97 as: String Character.

View file

@ -0,0 +1,2 @@
print (Int.toString (ord #"a") ^ "\n"); (* prints "97" *)
print (Char.toString (chr 97) ^ "\n"); (* prints "a" *)

View file

@ -0,0 +1,4 @@
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789→Str1
Disp inString(Str1,"A
Input "CODE? ",A
Disp sub(Str1,A,1

View file

@ -0,0 +1,21 @@
Prgm
Local k, s
ClrIO
Loop
Disp "Press a key, or ON to exit."
getKey() © clear buffer
0 → k : While k = 0 : getKey() → k : EndWhile
ClrIO
If k ≥ 256 Then
Disp "Not a character."
Disp "Code: " & string(k)
Else
char(k) → s ©
© char() and ord() are inverses. ©
Disp "Character: " & s ©
Disp "Code: " & string(ord(s)) ©
EndIf
EndLoop
EndPrgm

View file

@ -0,0 +1,3 @@
$$ MODE TUSCRIPT
SET character ="a", code=DECODE (character,byte)
PRINT character,"=",code

View file

@ -0,0 +1,2 @@
"a" ord print
97 chr print

View file

@ -0,0 +1,2 @@
"π" ord print
960 chr print

View file

@ -0,0 +1,9 @@
#import std
#import nat
chr = -: num characters
asc = -:@rlXS num characters
#cast %cnX
test = (chr97,asc`a)

View file

@ -0,0 +1,2 @@
Console.WriteLine(Chr(97)) 'Prints a
Console.WriteLine(Asc("a")) 'Prints 97

View file

@ -0,0 +1,2 @@
IntOut(0, ^a); \(Integer Out) displays "97" on the console (device 0)
ChOut(0, 97); \(Character Out) displays "a" on the console (device 0)