Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,113 @@
use framework "Foundation" -- Yosemite onwards, for the toLowerCase() function
-- KELVIN TO OTHER SCALE -----------------------------------------------------
-- kelvinAs :: ScaleName -> Num -> Num
on kelvinAs(strOtherScale, n)
heatBabel(n, "Kelvin", strOtherScale)
end kelvinAs
-- MORE GENERAL CONVERSION ---------------------------------------------------
-- heatBabel :: n -> ScaleName -> ScaleName -> Num
on heatBabel(n, strFromScale, strToScale)
set ratio to 9 / 5
set cels to 273.15
set fahr to 459.67
script reading
on |λ|(x, strFrom)
if strFrom = "k" then
x as real
else if strFrom = "c" then
x + cels
else if strFrom = "f" then
(fahr + x) * ratio
else
x / ratio
end if
end |λ|
end script
script writing
on |λ|(x, strTo)
if strTo = "k" then
x
else if strTo = "c" then
x - cels
else if strTo = "f" then
(x * ratio) - fahr
else
x * ratio
end if
end |λ|
end script
writing's |λ|(reading's |λ|(n, ¬
toLower(text 1 of strFromScale)), ¬
toLower(text 1 of strToScale))
end heatBabel
-- TEST ----------------------------------------------------------------------
on kelvinTranslations(n)
script translations
on |λ|(x)
{x, kelvinAs(x, n)}
end |λ|
end script
map(translations, {"K", "C", "F", "R"})
end kelvinTranslations
on run
script tabbed
on |λ|(x)
intercalate(tab, x)
end |λ|
end script
intercalate(linefeed, map(tabbed, kelvinTranslations(21)))
end run
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
set {dlm, my text item delimiters} to {my text item delimiters, strText}
set strJoined to lstText as text
set my text item delimiters to dlm
return strJoined
end intercalate
-- 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 |λ|(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- 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 |λ| : f
end script
end if
end mReturn
-- toLower :: String -> String
on toLower(str)
set ca to current application
((ca's NSString's stringWithString:(str))'s ¬
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toLower

View file

@ -0,0 +1,8 @@
on convertFromKelvin(kelvinValue)
return ("K" & tab & (kelvinValue as real)) & ¬
(linefeed & "C" & tab & (kelvinValue - 273.15)) & ¬
(linefeed & "F" & tab & ((kelvinValue - 273.15) * 9 / 5 + 32)) & ¬
(linefeed & "R" & tab & (kelvinValue * 9 / 5))
end convertFromKelvin
convertFromKelvin(21)

View file

@ -0,0 +1,14 @@
on convertFromKelvin(kelvinValue)
set kelvinMeasurement to kelvinValue as degrees Kelvin
set celsiusValue to kelvinMeasurement as degrees Celsius as number
set fahrenheitValue to kelvinMeasurement as degrees Fahrenheit as number
set rankineValue to kelvinValue * 9 / 5
return ("K" & tab & (kelvinValue as real)) & ¬
(linefeed & "C" & tab & celsiusValue) & ¬
(linefeed & "F" & tab & fahrenheitValue) & ¬
(linefeed & "R" & tab & rankineValue)
end convertFromKelvin
convertFromKelvin(21)

View file

@ -0,0 +1,34 @@
use AppleScript version "2.5" -- macOS 10.12 (Sierra) or later
use framework "Foundation"
on convertFromKelvin(kelvinValue)
set || to current application
-- Set up an NSMeasurement object representing the given number of Kelvin units.
set kelvinUnit to ||'s class "NSUnitTemperature"'s kelvin()
set kelvinMeasurement to ||'s class "NSMeasurement"'s alloc()'s initWithDoubleValue:(kelvinValue) unit:(kelvinUnit)
-- Get value of the same measurement in each of the other "units" in turn.
set celsiusUnit to ||'s class "NSUnitTemperature"'s celsius()
set celsiusMeasurement to kelvinMeasurement's measurementByConvertingToUnit:(celsiusUnit)
set celsiusValue to celsiusMeasurement's doubleValue()
set fahrenheitUnit to ||'s class "NSUnitTemperature"'s fahrenheit()
set fahrenheitMeasurement to kelvinMeasurement's measurementByConvertingToUnit:(fahrenheitUnit)
set fahrenheitValue to fahrenheitMeasurement's doubleValue()
-- There's no predefined unit for Rankine (as at macOS 10.14 Mojave), but custom units are easy to define.
-- A unit's linear 'converter' must contain the unit's size and zero offset relative to those of its class's "base unit"
-- which for temperatures is the 'kelvin' unit.
set rankineConverter to ||'s class "NSUnitConverterLinear"'s alloc()'s initWithCoefficient:(5 / 9) |constant|:(0)
set rankineUnit to ||'s class "NSUnitTemperature"'s alloc()'s initWithSymbol:("°R") converter:(rankineConverter)
set rankineMeasurement to kelvinMeasurement's measurementByConvertingToUnit:(rankineUnit)
set rankineValue to rankineMeasurement's doubleValue()
return ("K" & tab & (kelvinValue as real)) & ¬
(linefeed & "C" & tab & celsiusValue) & ¬
(linefeed & "F" & tab & fahrenheitValue) & ¬
(linefeed & "R" & tab & rankineValue)
end convertFromKelvin
convertFromKelvin(21)