Jump to content

Show ASCII table: Difference between revisions

m
→‎{{header|Haskell}}: Tidied. Used chunksOf from Data.List.Split
m (→‎{{header|Haskell}}: Tidied. Used chunksOf from Data.List.Split)
Line 1,702:
=={{header|Haskell}}==
<lang haskell>import Data.List (intercalate, transpose)
import Data.List.Split (chunksOf)
import Data.Char (chr)
 
main :: IO ()
main = putStrLn asciiTable
 
asciiTable :: String
Line 1,710 ⟶ 1,714:
transpose (chunksOf 16 $ asciiEntry <$> [32 .. 127])
 
main :: IO ()
main = putStrLn asciiTable
 
-------------------------------------------------------------
asciiEntry :: Int -> String
asciiEntry n =
let| null k = asciiName nk
| otherwise _ ->= concat [justifyRight 4 ' ' (show n), " : ", k]
in case k of
where
[] -> k
k = asciiName n
_ -> concat [justifyRight 4 ' ' (show n), " : ", k]
 
asciiName :: Int -> String
Line 1,728:
| 127 == n = "Del"
| otherwise = [chr n]
 
chunksOf :: Int -> [a] -> [[a]]
chunksOf k = go
where
go t =
case splitAt k t of
(a, b)
| null a -> []
| otherwise -> a : go b
 
justifyLeft, justifyRight :: Int -> Char -> String -> String
justifyLeft n c s = take n (s ++<> replicate n c)
 
justifyRight n c s = (drop (. length s) <*> (replicate n c ++ s<>)</lang>
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.