Binary digits: Difference between revisions

Content added Content deleted
(→‎{{header|AppleScript}}: Normalised argument sequence of showIntAtBase, updated primitives)
Line 220:
 
 
<lang AppleScript>on-- runbinaryString :: Int -> String
intercalate(linefeed, ¬
map(binaryString, [5, 50, 9000]))
end run
 
-- binaryString :: Int -> String
on binaryString(n)
showIntAtBase(n2, 2n)
end binaryString
Line 236 ⟶ 229:
 
-- showIntAtBase :: Int -> Int -> String
on showIntAtBase(nbase, basen)
if base > 1 then
if n > 0 then
Line 242 ⟶ 235:
set r to n - m
if r > 0 then
set prefix to showIntAtBase(base, r div base, base)
else
set prefix to ""
Line 261 ⟶ 254:
end if
end showIntAtBase
 
 
-- TEST
on run
intercalate(linefeed, ¬
map(binaryString, [5, 50, 9000]))
end run
 
 
 
Line 268 ⟶ 271:
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
scripttell mfmReturn(f)
propertyset lambdalng :to flength of xs
end script set lst to {}
repeat with i from 1 to lng
set lngend of lst to lengthlambda(item i of xs, i, xs)
set lst to {} end repeat
repeat with i from 1return to lnglst
end repeattell
set end of lst to mf's lambda(item i of xs, i, xs)
end repeat
return lst
end map
 
Line 288 ⟶ 289:
end intercalate
 
-- Lift 2nd class handler function into 1st class script wrapper
</lang>
-- 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</lang>