Identity matrix: Difference between revisions
m
→{{header|AppleScript}}: tidied, updated output.
m (→{{header|Factor}}: update for new matrix vocabulary) |
m (→{{header|AppleScript}}: tidied, updated output.) |
||
Line 326:
=={{header|AppleScript}}==
<lang AppleScript>
--
on
set xs to enumFromTo(1, n)
script row
on |λ|(x)
script col
on |λ|(i)
if i = x then
Line 343:
end |λ|
end script
map(col, xs)
end |λ|
end script
map(row, xs)
end
on run
unlines(map(showList, ¬
identityMatrix(5)))
end run
-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
if
set
set end of lst to i▼
end repeat▼
else
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 enumFromTo
-- intercalate :: String -> [String] -> String
on intercalate(delim, xs)
set {dlm, my text item delimiters} to ¬
{my text item delimiters, delim}
set my text item delimiters to dlm
s
end intercalate
-- map :: (a -> b) -> [a] -> [b]
Line 387 ⟶ 397:
end tell
end map
-- Lift 2nd class handler function into 1st class script wrapper
Line 398 ⟶ 409:
end script
end if
end mReturn
-- showList :: [a] -> String
on showList(xs)
"[" & intercalate(", ", map(my str, xs)) & "]"
end showList
-- str :: a -> String
on str(x)
x as string
end str
-- unlines :: [String] -> String
on unlines(xs)
-- A single string formed by the intercalation
-- of a list of strings with the newline character.
set {dlm, my text item delimiters} to ¬
{my text item delimiters, linefeed}
set s to xs as text
set my text item delimiters to dlm
s
end unlines</lang>
{{Out}}
<pre>
=={{header|Applesoft BASIC}}==
|