September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,62 +1,60 @@
-- showCharRange :: String -> String -> [String]
on showCharRange(strFrom, strTo)
-- showChar :: Int -> String
script showChar
on lambda(intID)
character id intID
end lambda
end script
map(showChar, range(id of strFrom, id of strTo))
end showCharRange
-- TEST
on run
{showCharRange("a", "z"), ¬
showCharRange("🐐", "🐟")}
{enumFromTo("a", "z"), ¬
enumFromTo("🐐", "🐟")}
end run
-- GENERIC FUNCTIONS ----------------------------------------------------------
---------------------------------------------------------------------------
-- GENERIC FUNCTIONS
-- chr :: Int -> Char
on chr(n)
character id n
end chr
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to lambda(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- ord :: Char -> Int
on ord(c)
id of c
end ord
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property lambda : f
end script
end if
end mReturn
-- enumFromTo :: Enum a => a -> a -> [a]
on enumFromTo(m, n)
set {intM, intN} to {fromEnum(m), fromEnum(n)}
-- range :: Int -> Int -> [Int]
on range(m, n)
if n < m then
if intM > intN then
set d to -1
else
set d to 1
end if
set lst to {}
repeat with i from m to n by d
set end of lst to i
end repeat
if class of m is text then
repeat with i from intM to intN by d
set end of lst to chr(i)
end repeat
else
repeat with i from intM to intN by d
set end of lst to i
end repeat
end if
return lst
end range
end enumFromTo
-- fromEnum :: Enum a => a -> Int
on fromEnum(x)
set c to class of x
if c is boolean then
if x then
1
else
0
end if
else if c is text then
if x "" then
id of x
else
missing value
end if
else
x as integer
end if
end fromEnum

View file

@ -0,0 +1,5 @@
10 FOR I=ASC("A") TO ASC("Z")
20 A$ = A$+CHR$(I)
30 NEXT
40 PRINT CHR$(14) : REM 'SWITCH CHARACTER SET TO LOWER/UPPER CASES
50 PRINT A$

View file

@ -0,0 +1 @@
For x= ORD("a") To ORD("z") : @(x - ORD("a")) = x : Next

View file

@ -0,0 +1,11 @@
@echo off
setlocal enabledelayedexpansion
:: This code appends the ASCII characters from 97-122 to %alphabet%, removing any room for error.
for /l %%i in (97,1,122) do (
cmd /c exit %%i
set "alphabet=!alphabet! !=exitcodeAscii!"
)
echo %alphabet%
pause>nul

View file

@ -1,4 +1,4 @@
(defvar *lower*
(loop with a = (char-code #\a)
for i upto 25
for i below 26
collect (code-char (+ a i))))

View file

@ -0,0 +1,5 @@
(defvar *lowercase-alphabet-string*
(map 'string #'code-char (loop
for c from (char-code #\a) to (char-code #\z)
collect c))
"The 26 lower case letters in alphabetical order.")

View file

@ -0,0 +1,4 @@
(assert (= 26 (length *lowercase-alphabet-string*) (length *lower*)))
(assert (every #'char< *lowercase-alphabet-string* (subseq *lowercase-alphabet-string* 1)))
(assert (apply #'char< *lower*))
(assert (string= *lowercase-alphabet-string* (coerce *lower* 'string)))

View file

@ -0,0 +1,8 @@
Public Sub Main()
Dim siCount As Short
For siCount = Asc("a") To Asc("z")
Print Chr(siCount);
Next
End

View file

@ -0,0 +1,3 @@
lower = ['a' .. 'z']
main = print lower

View file

@ -0,0 +1,5 @@
alpha :: String
alpha = enumFromTo 'a' 'z'
main :: IO ()
main = print alpha

View file

@ -1,4 +0,0 @@
lower = ['a' .. 'z']
main = do
print lower

View file

@ -1,20 +1,55 @@
(lstRanges => {
// charRange :: Char -> Char -> [Char]
function charRange(cFrom, cTo) {
let [m, n] = [cFrom, cTo]
.map(s => s.codePointAt(0));
(() => {
// enumFromTo :: Enum a => a -> a -> [a]
const enumFromTo = (m, n) => {
const [intM, intN] = [m, n].map(fromEnum),
f = typeof m === 'string' ? (
(_, i) => chr(intM + i)
) : (_, i) => intM + i;
return Array.from({
length: (n - m) + 1
}, (_, i) => String.fromCodePoint(m + i));
}
length: Math.floor(intN - intM) + 1
}, f);
};
// GENERIC FUNCTIONS ------------------------------------------------------
// TEST
return lstRanges
.map(([from, to]) => charRange(from, to).join(' '))
.join('\n')
// compose :: (b -> c) -> (a -> b) -> (a -> c)
const compose = (f, g) => x => f(g(x));
})([['a', 'z'], ['א','ת'],['α', 'ω'],['🐐', '🐟']]);
// chr :: Int -> Char
const chr = x => String.fromCodePoint(x);
// ord :: Char -> Int
const ord = c => c.codePointAt(0);
// fromEnum :: Enum a => a -> Int
const fromEnum = x => {
const type = typeof x;
return type === 'boolean' ? (
x ? 1 : 0
) : type === 'string' ? ord(x) : x;
};
// map :: (a -> b) -> [a] -> [b]
const map = (f, xs) => xs.map(f);
// show :: a -> String
const show = x => JSON.stringify(x);
// uncurry :: Function -> Function
const uncurry = f => args => f.apply(null, args);
// unlines :: [String] -> String
const unlines = xs => xs.join('\n');
// unwords :: [String] -> String
const unwords = xs => xs.join(' ');
// TEST -------------------------------------------------------------------
return unlines(map(compose(unwords, uncurry(enumFromTo)), [
['a', 'z'],
['α', 'ω'],
['א', 'ת'],
['🐐', '🐟']
]));
})();

View file

@ -0,0 +1,6 @@
// version 1.0.6
fun main(args: Array<String>) {
val alphabet = CharArray(26) { (it + 97).toChar() }.joinToString("")
println(alphabet)
}

View file

@ -1,2 +1,5 @@
# From constants built into R:
letters
# Or generate the same with:
sapply(97:122, intToUtf8)

View file

@ -0,0 +1,9 @@
> i, 1..26
d = [i+96,0]
a[i] = #.str(d)
<
'now A is an array of letters a..z
> i, 1..#.size(a,1)
#.output(a[i],#.rs)
<

View file

@ -0,0 +1 @@
&ALPHABET ('a' LEN(25)) . OUTPUT ;* Works in ASCII but not EBCDIC.

View file

@ -0,0 +1,13 @@
// built-in: lowercase and uppercase letters
display c(alpha)
display c(ALPHA)
// generate a variable with the letters
clear
set obs 26
gen a=char(96+_n)
// or in Mata
mata
char(97..122)
end

View file

@ -0,0 +1 @@
h$` h$` >0_0 t h$y ms p h? jn00_0 p r h#1 ma t jn0_0 >00_0 p p r p

View file

@ -0,0 +1,6 @@
["a".."z"] // lasy list
["a".."z"].walk() //-->L("a","b","c","d","e",...
"a".toAsc().pump(26,List,"toChar") // another way to create the list
"a".toAsc().pump(26,String,"toChar") // create a string
//-->"abcdefghijklmnopqrstuvwxyz"
Utils.Helpers.lowerLetters // string const