Show ASCII table: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: Tidied. Used chunksOf from Data.List.Split) |
|||
Line 1,702: | Line 1,702: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang haskell>import Data.List (intercalate, transpose) |
<lang haskell>import Data.List (intercalate, transpose) |
||
import Data.List.Split (chunksOf) |
|||
import Data.Char (chr) |
import Data.Char (chr) |
||
⚫ | |||
⚫ | |||
asciiTable :: String |
asciiTable :: String |
||
Line 1,710: | Line 1,714: | ||
transpose (chunksOf 16 $ asciiEntry <$> [32 .. 127]) |
transpose (chunksOf 16 $ asciiEntry <$> [32 .. 127]) |
||
⚫ | |||
⚫ | |||
------------------------------------------------------------- |
|||
asciiEntry :: Int -> String |
asciiEntry :: Int -> String |
||
asciiEntry n |
asciiEntry n |
||
| null k = k |
|||
⚫ | |||
in case k of |
|||
⚫ | |||
[] -> k |
|||
k = asciiName n |
|||
⚫ | |||
asciiName :: Int -> String |
asciiName :: Int -> String |
||
Line 1,728: | Line 1,728: | ||
| 127 == n = "Del" |
| 127 == n = "Del" |
||
| otherwise = [chr n] |
| otherwise = [chr n] |
||
chunksOf :: Int -> [a] -> [[a]] |
|||
chunksOf k = go |
|||
⚫ | |||
go t = |
|||
case splitAt k t of |
|||
(a, b) |
|||
| null a -> [] |
|||
| otherwise -> a : go b |
|||
justifyLeft, justifyRight :: Int -> Char -> String -> String |
justifyLeft, justifyRight :: Int -> Char -> String -> String |
||
justifyLeft n c s = take n (s |
justifyLeft n c s = take n (s <> replicate n c) |
||
justifyRight n c |
justifyRight n c = (drop . length) <*> (replicate n c <>)</lang> |
||
{{Out}} |
{{Out}} |
||
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p |
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p |