Multiple distinct objects: Difference between revisions

Line 105:
AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz
</pre>
 
 
=={{header|AppleScript}}==
 
<lang AppleScript>
-- nObjects Int -> Constructor -> [Object]
on nObjects(n, foo)
map(foo, range(1, n))
end nObjects
 
 
-- TEST
 
-- foo :: a -> Int -> b
on foo(_, i)
{index:i}
end foo
 
on run
nObjects(6, foo)
end run
 
 
 
-- GENERIC LIBRARY FUNCTIONS
 
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
script mf
property lambda : f
end script
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to mf's lambda(item i of xs, i, xs)
end repeat
return lst
end map
 
-- range :: Int -> Int -> [Int]
on range(m, n)
if n < m then
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 range
</lang>
 
{{Out}}
<lang AppleScript>{{index:1}, {index:2}, {index:3}, {index:4}, {index:5}, {index:6}}</lang>
 
=={{header|AutoHotkey}}==
9,659

edits