<story><title>Sed challenge: join cal -y months into a single column</title><url>https://jol.dev/blog/2021-11-16-n2-sed-challenge-join-cal-y-months-into-a-single-column.html</url></story><parent_chain><item><author>rak1507</author><text>Just for fun, I tried it in APL.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  cal ← ⎕SH &amp;#x27;cal -y&amp;#x27;                                 ⍝ get output of cal command
  bymonth ← {⍵⊂⍨0=23|⍳≢⍵}⍤1↑2↓cal                    ⍝ partition into month groups
  lines ← {⍵⊂⍨0=8|⍳≢⍵}⍤1⍉bymonth                     ⍝ partition into chunks in each line
  months ← ~∘&amp;#x27; &amp;#x27;¨,⍉⊃¨lines                           ⍝ extract month names and remove spaces
  days ← (23⍴1 0 0)⊂⍤1↑⊃,&amp;#x2F;,⌿2↓¨lines                 ⍝ partition into days
  trimmed ← ∊⍤1⍉{⍵&amp;#x2F;⍨(&amp;#x27; &amp;#x27;∨.≠¨⍵)∨∧\&amp;#x27; &amp;#x27;∧.=¨⍵}⍤1⍉¯1↓days ⍝ remove excess spaces
  ⎕←53↑(¯2↓⍤1⊢trimmed) , ↑months\⍨∨&amp;#x2F;&amp;#x27; 1 &amp;#x27;⍷trimmed    ⍝ append months to calendar where the 1s are, and print
&lt;/code&gt;&lt;/pre&gt;
Surprisingly tricky (but still easier than sed IMO :P)</text></item></parent_chain><comment><author>markjreed</author><text>I attempted to run that APL, and it didn&amp;#x27;t quite work as is on my system (Dyalog on macOS). As written, it seems to be an odd mixture of things that assume ⎕IO 0 and ⎕IO 1, in that with ⎕IO←1, the bymonth assignment only gets two columns instead of three, but with ⎕IO←0, it needs to be 0=22 and 1↓cal instead of 0=23 and 2↓cal.&lt;p&gt;Similarly, the lines assignment needed to be {⍵⊂⍨0=9|⍳≢⍵}⍤1⍉bymonth.&lt;p&gt;After those changes it worked OMM, but the month names were appended directly to the end of the first Saturday&amp;#x27;s date with no space (e.g. &amp;quot;1 2January&amp;quot;). So I changed ↑months to ↑(&amp;#x27; &amp;#x27;,¨months) in the last line to insert a space there (there&amp;#x27;s likely a better way to do that; I&amp;#x27;m still pretty new at APL).&lt;p&gt;I added `-h` to make sure `cal` didn&amp;#x27;t highlight today&amp;#x27;s date, which can throw things off, and eliminated intermediate vars that were only used once; this was what I wound up with (works from a clean ws in Dyalog OMM):&lt;p&gt;&lt;pre&gt;&lt;code&gt;    ⎕io ← 0
    lines ← {⍵⊂⍨0=9|⍳≢⍵}⍤1⍉{⍵⊂⍨0=22|⍳≢⍵}⍤1↑1↓⎕sh &amp;#x27;cal -hy&amp;#x27;
    months ← ~∘&amp;#x27; &amp;#x27;¨,⍉⊃¨lines
    days ← ∊⍤1⍉{⍵&amp;#x2F;⍨(&amp;#x27; &amp;#x27;∨.≠¨⍵)∨∧\&amp;#x27; &amp;#x27;∧.=¨⍵}⍤1⍉¯1↓(23⍴1 0 0)⊂⍤1↑⊃,&amp;#x2F;,⌿2↓¨lines
    ⎕←53↑(¯2↓⍤1⊢days) , ↑(&amp;#x27; &amp;#x27;,¨months)\⍨∨&amp;#x2F;&amp;#x27; 1 &amp;#x27;⍷days&lt;/code&gt;&lt;/pre&gt;</text></comment>
<story><title>Sed challenge: join cal -y months into a single column</title><url>https://jol.dev/blog/2021-11-16-n2-sed-challenge-join-cal-y-months-into-a-single-column.html</url></story><parent_chain><item><author>rak1507</author><text>Just for fun, I tried it in APL.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  cal ← ⎕SH &amp;#x27;cal -y&amp;#x27;                                 ⍝ get output of cal command
  bymonth ← {⍵⊂⍨0=23|⍳≢⍵}⍤1↑2↓cal                    ⍝ partition into month groups
  lines ← {⍵⊂⍨0=8|⍳≢⍵}⍤1⍉bymonth                     ⍝ partition into chunks in each line
  months ← ~∘&amp;#x27; &amp;#x27;¨,⍉⊃¨lines                           ⍝ extract month names and remove spaces
  days ← (23⍴1 0 0)⊂⍤1↑⊃,&amp;#x2F;,⌿2↓¨lines                 ⍝ partition into days
  trimmed ← ∊⍤1⍉{⍵&amp;#x2F;⍨(&amp;#x27; &amp;#x27;∨.≠¨⍵)∨∧\&amp;#x27; &amp;#x27;∧.=¨⍵}⍤1⍉¯1↓days ⍝ remove excess spaces
  ⎕←53↑(¯2↓⍤1⊢trimmed) , ↑months\⍨∨&amp;#x2F;&amp;#x27; 1 &amp;#x27;⍷trimmed    ⍝ append months to calendar where the 1s are, and print
&lt;/code&gt;&lt;/pre&gt;
Surprisingly tricky (but still easier than sed IMO :P)</text></item></parent_chain><comment><author>wahern</author><text>It&amp;#x27;s too bad APL never enjoyed ubiquity on Unix-like platforms. The world would have been a better place. Maybe if Stallman or some early GNU participant had championed APL we&amp;#x27;d all be either using APL or constantly excusing ourselves. Like Emacs did for Lisp.&lt;p&gt;I&amp;#x27;m decent with sed. I wouldn&amp;#x27;t call myself an expert, but know how to employ addressing and hold spaces, which are sadly aracana to most people who employ sed. I ended up learning sed because it was there, proved useful, and it fit into the command-line toolkit really well. (In order of importance.) APL would never slot into that toolkit as well as other tools, but it&amp;#x27;s value-add would more than compensate. Unfortunately, the value-add isn&amp;#x27;t enough to compensate for the fact that it&amp;#x27;s not &lt;i&gt;there&lt;/i&gt; and in your face every time you&amp;#x27;re exploring a problem and its solution space.</text></comment>