June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -5,56 +5,34 @@ on run
end run
-- GENERIC FUNCTIONS ----------------------------------------------------------
-- chr :: Int -> Char
on chr(n)
character id n
end chr
-- ord :: Char -> Int
on ord(c)
id of c
end ord
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- enumFromTo :: Enum a => a -> a -> [a]
on enumFromTo(m, n)
set {intM, intN} to {fromEnum(m), fromEnum(n)}
if intM > intN then
set d to -1
if class of m is integer then
enumFromToInt(m, n)
else
set d to 1
enumFromToChar(m, n)
end if
set lst to {}
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 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
-- enumFromToChar :: Char -> Char -> [Char]
on enumFromToChar(m, n)
set {intM, intN} to {id of m, id of n}
set xs to {}
repeat with i from intM to intN by signum(intN - intM)
set end of xs to character id i
end repeat
return xs
end enumFromToChar
-- signum :: Num -> Num
on signum(x)
if x < 0 then
-1
else if x = 0 then
0
else
x as integer
1
end if
end fromEnum
end signum