I'm trying to design a text processing language that's elegant and concise. I'm failing.

pad :: ([1^.* 5^.] [2^.* 6^.] :: [1 2] -> pad -> [3^.*] [4^.*] :: [3 5] [2 4]) | ([] [1^.* 2^.] :: [] [1] -> pad -> [3^.* 4^.*] :: [3 '0'] [4 2]) | ([1^.* 2^.] [] :: [1] [] -> pad -> [3^.* 4^.*] :: [4 '0'] [3 2])

Sorry, this had some bugs in it. Corrected version:

pad :: ([1^.* 5^.] [2^.* 6^.] :: [1 2] -> pad -> [3^.*] [4^.*] :: [3 5] [4 6]) | ([] [1^.* 2^.] :: [] [1] -> pad -> [3^.* 4^.*] :: [3 '0'] [4 2]) | ([1^.* 2^.] [] :: [1] [] -> pad -> [3^.* 4^.*] :: [3 2] [4 '0'])

Oh shit I forgot the base case.

pad :: ([1^.* 5^.] [2^.* 6^.] :: [1 2] -> pad -> [3^.*] [4^.*] :: [3 5] [4 6]) | ([] [1^.* 2^.] :: [] [1] -> pad -> [3^.* 4^.*] :: [3 '0'] [4 2]) | ([1^.* 2^.] [] :: [1] [] -> pad -> [3^.* 4^.*] :: [3 2] [4 '0']) | ([] [])

Follow

If you were wondering, this is left pad.

Sign in to participate in the conversation
Cybrespace

cybrespace: the social hub of the information superhighway jack in to the mastodon fediverse today and surf the dataflow through our cybrepunk, slightly glitchy web portal support us on patreon or liberapay!