Multiple distinct objects: Difference between revisions
→{{header|AppleScript}}: Slight reorganisation, updated primitives
m (Remove from object-oriented category.) |
(→{{header|AppleScript}}: Slight reorganisation, updated primitives) |
||
Line 110:
=={{header|AppleScript}}==
<lang AppleScript>-- nObjects Constructor -> Int -> [Object]
▲ map(foo, range(1, n))
end nObjects
-- TEST
on run
nObjects(6, someConstructor)▼
-- someConstructor :: a -> Int -> b▼
on lambda(_, i)
{index:i}▼
end script
--> {{index:1}, {index:2}, {index:3}, {index:4}, {index:5}, {index:6}}
end run
▲-- someConstructor :: a -> Int -> b
▲ {index:i}
▲end someConstructor
-- GENERIC FUNCTIONS -----------------------------------------------------------
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
repeat with i from 1 to lng
set
end tell
▲ end repeat
end map
-- Lift 2nd class handler function into 1st class script wrapper
-- 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
-- range :: Int -> Int -> [Int]
Line 160 ⟶ 171:
end repeat
return lst
end range</lang>
{{Out}}
|