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 -----------------------------------------------------
-- Kelvin to other scale
 
-- kelvinAs :: ScaleName -> Num -> Num
Line 277:
end kelvinAs
 
-- MORE GENERAL CONVERSION ---------------------------------------------------
 
-- More general conversion
 
-- heatBabel :: n -> ScaleName -> ScaleName -> Num
Line 287 ⟶ 286:
script reading
on lambda|λ|(x, strFrom)
if strFrom = "k" then
x as real
Line 297 ⟶ 296:
x / ratio
end if
end lambda|λ|
end script
script writing
on lambda|λ|(x, strTo)
if strTo = "k" then
x
Line 311 ⟶ 310:
x * ratio
end if
end lambda|λ|
end script
writing's lambda|λ|(reading's lambda|λ|(n, ¬
toLowerCasetoLower(text 1 of strFromScale)), ¬
toLowerCasetoLower(text 1 of strToScale))
end heatBabel
 
 
-- TEST ----------------------------------------------------------------------
-- TEST
 
on kelvinTranslations(n)
script translations
on lambda|λ|(x)
{x, kelvinAs(x, n)}
end lambda|λ|
end script
Line 334 ⟶ 332:
on run
script tabbed
on lambda|λ|(x)
intercalate(tab, x)
end lambda|λ|
end script
Line 343 ⟶ 341:
 
 
-- GENERIC FUNCTIONS ---------------------------------------------------------
 
-- GENERIC LIBRARY 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
end toLowerCase
 
-- intercalate :: Text -> [Text] -> Text
Line 367 ⟶ 357:
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
Line 380 ⟶ 370:
else
script
property lambda|λ| : f
end script
end if
end mReturn
 
-- toLowerCasetoLower :: String -> String
</lang>
on toLowerCasetoLower(str)
 
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
9,655

edits