Multiple distinct objects: Difference between revisions
→{{header|AppleScript}}: Updated primitives
(→{{header|AppleScript}}: Updated primitives) |
|||
Line 103:
=={{header|AppleScript}}==
<lang AppleScript>--
on nObjects(f, n)
map(f,
end nObjects
-- TEST ----------------------------------------------------------------------
on run
-- someConstructor :: a -> Int -> b
script someConstructor
on
{index:i}
end
end script
Line 125 ⟶ 124:
end run
-- GENERIC FUNCTIONS ---------------------------------------------------------
▲-- GENERIC FUNCTIONS -----------------------------------------------------------
set d to -1▼
▲ else
set d to 1▼
end if▼
set lst to {}▼
repeat with i from m to n by d▼
set end of lst to i▼
end repeat▼
return lst▼
end enumFromTo
-- map :: (a -> b) -> [a] -> [b]
Line 135 ⟶ 146:
set lst to {}
repeat with i from 1 to lng
set end of lst to
end repeat
return lst
Line 148 ⟶ 159:
else
script
property
end script
end if
end mReturn</lang>
▲-- range :: Int -> Int -> [Int]
▲on range(m, n)
▲ if n < m then
▲ set d to -1
▲ set d to 1
▲ end if
▲ set lst to {}
▲ repeat with i from m to n by d
▲ set end of lst to i
▲ end repeat
▲ return lst
{{Out}}
<lang AppleScript>{{index:1}, {index:2}, {index:3}, {index:4}, {index:5}, {index:6}}</lang>
|