Temperature conversion: Difference between revisions
→{{Header|AppleScript}}: Updated primitives
(Added ZX81 BASIC) |
(→{{Header|AppleScript}}: Updated primitives) |
||
Line 270:
<lang AppleScript>use framework "Foundation" -- Yosemite onwards, for the toLowerCase() function
-- KELVIN TO OTHER SCALE -----------------------------------------------------
-- kelvinAs :: ScaleName -> Num -> Num
Line 277:
end kelvinAs
-- MORE GENERAL CONVERSION ---------------------------------------------------
-- heatBabel :: n -> ScaleName -> ScaleName -> Num
Line 287 ⟶ 286:
script reading
on
if strFrom = "k" then
x as real
Line 297 ⟶ 296:
x / ratio
end if
end
end script
script writing
on
if strTo = "k" then
x
Line 311 ⟶ 310:
x * ratio
end if
end
end script
writing's
end heatBabel
-- TEST ----------------------------------------------------------------------
on kelvinTranslations(n)
script translations
on
{x, kelvinAs(x, n)}
end
end script
Line 334 ⟶ 332:
on run
script tabbed
on
intercalate(tab, x)
end
end script
Line 343 ⟶ 341:
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- toLowerCase :: String -> String▼
on toLowerCase(str)▼
set ca to current application▼
((ca's NSString's stringWithString:(str))'s ¬▼
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text▼
-- intercalate :: Text -> [Text] -> Text
Line 367 ⟶ 357:
set lst to {}
repeat with i from 1 to lng
set end of lst to
end repeat
return lst
Line 380 ⟶ 370:
else
script
property
end script
end if
end mReturn
▲ set ca to current application
▲ ((ca's NSString's stringWithString:(str))'s ¬
▲ lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toLower</lang>
{{Out}}
<pre>K 21.0
|