Pascal's triangle: Difference between revisions

Content added Content deleted
Line 319: Line 319:
on spacedAndIndented(lst)
on spacedAndIndented(lst)
set strLine to intercalate(" ", lst)
set strLine to intercalate(" ", lst)
nreps(" ", ¬
nreps(space, ¬
((my closure's lngWidth) - (length of strLine)) / 2) & strLine
((my closure's lngWidth) - (length of strLine)) / 2) & strLine
end spacedAndIndented
end spacedAndIndented
Line 340: Line 340:


-- GENERIC LIBRARY FUNCTIONS
-- GENERIC LIBRARY FUNCTIONS



-- foldl :: (a -> b -> a) -> a -> [b] -> a
-- foldl :: (a -> b -> a) -> a -> [b] -> a
Line 352: Line 353:
return v
return v
end foldl
end foldl

-- foldr :: (a -> b -> a) -> a -> [b] -> a
on foldr(f, startValue, xs)
set mf to mReturn(f)
set v to startValue
set lng to length of xs
repeat with i from lng to 1 by -1
set v to mf's lambda(v, item i of xs, i, xs)
end repeat
return v
end foldr


-- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
-- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
Line 425: Line 414:
end script
end script
end mClosure
end mClosure

</lang>
</lang>