Binary digits: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|AppleScript}}: updated primitives) |
||
Line 333: | Line 333: | ||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
{{Trans|JavaScript}} |
{{Trans|JavaScript}} |
||
<lang AppleScript>-- binaryString :: Int -> String |
<lang AppleScript>-- binaryString :: Int -> String |
||
on binaryString(n) |
on binaryString(n) |
||
⚫ | |||
⚫ | |||
end binaryString |
end binaryString |
||
-- showIntAtBase :: Int -> Int -> String |
-- showIntAtBase :: Int -> Int -> String |
||
on showIntAtBase( |
on showIntAtBase(n, base) |
||
if base > 1 then |
if base > 1 then |
||
if n > 0 then |
if n > 0 then |
||
Line 350: | Line 345: | ||
set r to n - m |
set r to n - m |
||
if r > 0 then |
if r > 0 then |
||
set prefix to showIntAtBase( |
set prefix to showIntAtBase(r div base, base) |
||
else |
else |
||
set prefix to "" |
set prefix to "" |
||
Line 370: | Line 365: | ||
end showIntAtBase |
end showIntAtBase |
||
-- TEST ----------------------------------------------------------------------- |
|||
-- TEST |
|||
on run |
on run |
||
⚫ | |||
⚫ | |||
⚫ | |||
end run |
end run |
||
-- GENERIC FUNCTIONS FOR TEST ------------------------------------------------- |
|||
⚫ | |||
⚫ | |||
-- GENERIC FUNCTIONS FOR TESTING |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- map :: (a -> b) -> [a] -> [b] |
-- map :: (a -> b) -> [a] -> [b] |
||
Line 390: | Line 389: | ||
set lst to {} |
set lst to {} |
||
repeat with i from 1 to lng |
repeat with i from 1 to lng |
||
set end of lst to |
set end of lst to |λ|(item i of xs, i, xs) |
||
end repeat |
end repeat |
||
return lst |
return lst |
||
end tell |
end tell |
||
end map |
end map |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- Lift 2nd class handler function into 1st class script wrapper |
-- Lift 2nd class handler function into 1st class script wrapper |
||
Line 411: | Line 402: | ||
else |
else |
||
script |
script |
||
property |
property |λ| : f |
||
end script |
end script |
||
end if |
end if |
||
end mReturn |
end mReturn |
||
-- unlines :: [String] -> String |
|||
on unlines(xs) |
|||
⚫ | |||
end unlines</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>101 |
<pre>101 |