Binary digits: Difference between revisions
Content added Content deleted
(→{{header|AppleScript}}: Normalised argument sequence of showIntAtBase, updated primitives) |
|||
Line 220: | Line 220: | ||
<lang AppleScript> |
<lang AppleScript>-- binaryString :: Int -> String |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- binaryString :: Int -> String |
|||
on binaryString(n) |
on binaryString(n) |
||
showIntAtBase( |
showIntAtBase(2, n) |
||
end binaryString |
end binaryString |
||
Line 236: | Line 229: | ||
-- showIntAtBase :: Int -> Int -> String |
-- showIntAtBase :: Int -> Int -> String |
||
on showIntAtBase( |
on showIntAtBase(base, n) |
||
if base > 1 then |
if base > 1 then |
||
if n > 0 then |
if n > 0 then |
||
Line 242: | Line 235: | ||
set r to n - m |
set r to n - m |
||
if r > 0 then |
if r > 0 then |
||
set prefix to showIntAtBase(r div |
set prefix to showIntAtBase(base, r div base) |
||
else |
else |
||
set prefix to "" |
set prefix to "" |
||
Line 261: | Line 254: | ||
end if |
end if |
||
end showIntAtBase |
end showIntAtBase |
||
-- TEST |
|||
on run |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Line 268: | Line 271: | ||
-- map :: (a -> b) -> [a] -> [b] |
-- map :: (a -> b) -> [a] -> [b] |
||
on map(f, xs) |
on map(f, xs) |
||
tell mReturn(f) |
|||
set lng to length of xs |
|||
set lst to {} |
|||
repeat with i from 1 to lng |
|||
⚫ | |||
set |
set end of lst to lambda(item i of xs, i, xs) |
||
end repeat |
|||
return lst |
|||
⚫ | |||
set end of lst to mf's lambda(item i of xs, i, xs) |
|||
⚫ | |||
return lst |
|||
end map |
end map |
||
Line 288: | Line 289: | ||
end intercalate |
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 |
|||
⚫ | |||
script |
|||
property lambda : f |
|||
end script |
|||
end if |
|||
end mReturn</lang> |
|||