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]
--on nObjects(f, Int -> Constructor -> [Object]n)
map(foof, range(1, n))
on nObjects(n, foo)
map(foo, range(1, n))
end nObjects
 
 
-- TEST
 
on run
nObjects(6, someConstructor)
-- someConstructor :: a -> Int -> b
nObjects(6,script someConstructor)
on lambda(_, i)
{index:i}
end repeatlambda
end script
end nObjects(someConstructor, 6)
--> {{index:1}, {index:2}, {index:3}, {index:4}, {index:5}, {index:6}}
end run
 
-- someConstructor :: a -> Int -> b
on someConstructor(_, i)
{index:i}
end someConstructor
 
 
-- GENERIC FUNCTIONS -----------------------------------------------------------
 
 
 
-- GENERIC LIBRARY FUNCTIONS
 
-- 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 tell
set end of lst to mf's lambda(item i of xs, i, xs)
end repeat
return lst
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>
 
</lang>
 
{{Out}}
9,655

edits