[ prog / sol / mona ]

prog


The Forced Indentation Of Code

66 2022-04-05 10:27

removed fixed column widths, added autosizing columns, added incipient sorting support on the numeric columns >>64

>> console.log (((id2code, extractors, formatters, pads, stringify, layout, sort, thread, magic) => ((table, aligns, strs) => layout (stringify (sort (table), strs, formatters), aligns, pads)) (magic.split (" ").map (id => [id, id2code (thread, id)]).filter (p => p [1] !== null).map (([id, code], index) => (text => [index + 1, parseInt (id, 10)].concat (extractors.map (ex => ex ["fun"] (text)))) (code.innerText)), ["right", "right"].concat (extractors.map (ex => ex ["align"])), ["tostring", "tostring"].concat (extractors.map (ex => ex ["str"])))) ((thread, id) => document.getElementById ("t" + thread + "p" + id).parentNode.nextElementSibling.querySelector ("code"), [{"fun": s => [...s.matchAll (/\blambda | => /g)].length, "align": "right", "str": "tostring"}, {"fun": (max => s => s.split ("\n").reduce ((acc, item) => max (acc, item.length), 0)) (Math.max), "align": "right", "str": "tostring"}, {"fun": s => (m => m ? m [0] : "?") (s.match (/^(>>> |>> |scheme@\(guile-user\)> )/m)), "align": "left", "str": "id"}], {"id": x => x, "tostring": x => x.toString ()}, {"left": (s, n, pad) => s.padEnd (n, pad), "right": (s, n, pad) => s.padStart (n, pad)}, (rows, how, formatters) => rows.map (r => r.map ((c, index) => formatters [how [index]] (c))), (lengths => (rows, how, pads) => (lengths => rows.map (r => r.map ((c, index) => pads [how [index]] (c, lengths [index], " ")).join (" ")).join ("\n")) (lengths (rows))) ((max => rows => rows.reduce ((acc, r) => acc.map ((a, index) => max (a, r [index].length)), rows [0].map (x => 0))) (Math.max)), (column => table => table.sort ((a, b) => a [column] - b [column])) (0), 22, "9 10 11 13 14 17 21 24 25 28 30 34 35 37 39 42 43 46 49 53 55 59 65"))
 1  9 12  391 >>>                  
 2 10  7  461 scheme@(guile-user)> 
 3 11 13  483 >>                   
 4 13 15  627 >>                   
 5 14 13  471 >>                   
 6 17 14  524 >>>                  
 7 21 18  789 >>>                  
 8 24 15  851 scheme@(guile-user)> 
 9 25 13  692 scheme@(guile-user)> 
10 28 25 1599 >>>                  
11 30 10  508 >>                   
12 34 13  560 >>                   
13 35 19 1375 scheme@(guile-user)> 
14 37 15  642 >>                   
15 39 21  909 >>                   
16 42 10  452 >>                   
17 43 10  444 >>                   
18 46 18  707 >>>                  
19 49 23 1070 >>>                  
20 53 21  873 >>>                  
21 55 14 1066 scheme@(guile-user)> 
22 59 21 1475 scheme@(guile-user)> 
23 65 19 1110 scheme@(guile-user)> 
<- undefined
>> 
267


VIP:

do not edit these