Pascal's triangle: Difference between revisions
m
→{{header|AppleScript}}: Tidied
m (→{{header|Nim}}) |
m (→{{header|AppleScript}}: Tidied) |
||
Line 351:
=={{header|AppleScript}}==
Drawing n rows from a generator:
<lang AppleScript>-------------------- PASCAL'S TRIANGLE -------------------
-- pascal :: Generator [[Int]]
on pascal()
Line 366 ⟶ 365:
--------------------------- TEST -------------------------
on run
showPascal(take(7, pascal()))
end run
------------------------ FORMATTING ----------------------
-- showPascal :: [[Int]] -> String
Line 383 ⟶ 385:
-- center :: Int -> Char -> String -> String
Line 400 ⟶ 402:
end if
end |center|
-- intercalate :: String -> [String] -> String
on intercalate(sep, xs)
set {dlm, my text item delimiters} to
{my text item delimiters, sep}
set s to xs as text
set my text item delimiters to dlm
return s
end intercalate
-- iterate :: (a -> a) -> a -> Generator [a]
Line 424 ⟶ 429:
end script
end iterate
-- length :: [a] -> Int
Line 434 ⟶ 440:
end if
end |length|
-- map :: (a -> b) -> [a] -> [b]
Line 446 ⟶ 453:
end tell
end map
-- min :: Ord a => a -> a -> a
Line 456 ⟶ 464:
end min
-- mReturn :: First-class m => (a -> b) -> m (a -> b)
on mReturn(f)
if script is class of f then
f
else
Line 467 ⟶ 476:
end if
end mReturn
-- plus :: Num -> Num -> Num
Line 472 ⟶ 483:
a + b
end plus
-- Egyptian multiplication - progressively doubling a list, appending
Line 489 ⟶ 501:
return out & dbl
end replicate
-- take :: Int -> [a] -> [a]
Line 516 ⟶ 529:
end if
end take
-- unlines :: [String] -> String
Line 525 ⟶ 539:
str
end unlines
-- unwords :: [String] -> String
on unwords(xs)
set {dlm, my text item delimiters} to
{my text item delimiters, space}
set s to xs as text
set my text item delimiters to dlm
return s
end unwords
-- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
|