News for hackers. Stuff that matters.
Re:Sed challenge: join cal -y months into a single column by rak1507 on Wednesday November 17, 2021 @06:26PM (#29260223)
Just for fun, I tried it in APL.

  cal ← ⎕SH 'cal -y'                                 ⍝ 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 ← ~∘' '¨,⍉⊃¨lines                           ⍝ extract month names and remove spaces
  days ← (23⍴1 0 0)⊂⍤1↑⊃,/,⌿2↓¨lines                 ⍝ partition into days
  trimmed ← ∊⍤1⍉{⍵/⍨(' '∨.≠¨⍵)∨∧\' '∧.=¨⍵}⍤1⍉¯1↓days ⍝ remove excess spaces
  ⎕←53↑(¯2↓⍤1⊢trimmed) , ↑months\⍨∨/' 1 '⍷trimmed    ⍝ append months to calendar where the 1s are, and print
Surprisingly tricky (but still easier than sed IMO :P)
Re:Sed challenge: join cal -y months into a single column by markjreed on Friday November 19, 2021 @09:17AM (#29277350)
I attempted to run that APL, and it didn'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.

Similarly, the lines assignment needed to be {⍵⊂⍨0=9|⍳≢⍵}⍤1⍉bymonth.

After those changes it worked OMM, but the month names were appended directly to the end of the first Saturday's date with no space (e.g. "1 2January"). So I changed ↑months to ↑(' ',¨months) in the last line to insert a space there (there's likely a better way to do that; I'm still pretty new at APL).

I added `-h` to make sure `cal` didn't highlight today'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):

    ⎕io ← 0
    lines ← {⍵⊂⍨0=9|⍳≢⍵}⍤1⍉{⍵⊂⍨0=22|⍳≢⍵}⍤1↑1↓⎕sh 'cal -hy'
    months ← ~∘' '¨,⍉⊃¨lines
    days ← ∊⍤1⍉{⍵/⍨(' '∨.≠¨⍵)∨∧\' '∧.=¨⍵}⍤1⍉¯1↓(23⍴1 0 0)⊂⍤1↑⊃,/,⌿2↓¨lines
    ⎕←53↑(¯2↓⍤1⊢days) , ↑(' ',¨months)\⍨∨/' 1 '⍷days
Re:Sed challenge: join cal -y months into a single column by rak1507 on Friday November 19, 2021 @09:23AM (#29277433)
It (should be) purely ⎕IO←0. https://tio.run/##jZK7SgNBFIb7fYrTbQKbyyYINum1srBNM27G7OLemJ...

Potentially cal -y on macOS produces a different shape? What's ⍴↑cal?

Try doing cal←⎕SE.UCMD'Calendar 2021' and replace ↑2↓cal with 1↓cal - potentially that'll work?

Re:Sed challenge: join cal -y months into a single column by markjreed on Friday November 19, 2021 @10:33AM (#29278201)
⍴↑⎕sh 'cal -y' is 36 66. ⍴⎕SE.UCMD'Calendar 2021' is 33 66. Hm.

What system are you on? On Ubuntu, cal -y | wc -l also gives me 36.

Re:Sed challenge: join cal -y months into a single column by rak1507 on Friday November 19, 2021 @01:50PM (#29280794)
I was just testing with TIO, it looks like the version of `cal` on there is different to the common one. The ⎕SE.UCMD'Calendar 2021' version should work cross platform (as it doesn't rely on anything external).
Re:Sed challenge: join cal -y months into a single column by wahern on Wednesday November 17, 2021 @09:58PM (#29261538)
It'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'd all be either using APL or constantly excusing ourselves. Like Emacs did for Lisp.

I'm decent with sed. I wouldn'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's value-add would more than compensate. Unfortunately, the value-add isn't enough to compensate for the fact that it's not there and in your face every time you're exploring a problem and its solution space.

Re:Sed challenge: join cal -y months into a single column by e12e on Thursday November 18, 2021 @07:16AM (#29264572)
Seems there is an alternative history where Stallman went with APL and not lisp:

https://en.wikipedia.org/wiki/APL_(programming_language)#GNU...

> (...) Richard Stallman, founder of the GNU Project, was an early adopter of APL, using it to write a text editor as a high school student in the summer of 1969.

And:

  Rho, rho, rho of X
  Always equals 1
  Rho is dimension, rho rho rank.
  APL is fun!

    Richard M. Stallman, 1969
https://www.gnu.org/software/apl/

But:

> GNU APL was written and is being maintained by Jürgen Sauermann.

and I believe it's fairly young when compared to emacs/emacs lisp.

Re:Sed challenge: join cal -y months into a single column by jolmg on Wednesday November 17, 2021 @10:00PM (#29261549)
> Maybe if Stallman or some early GNU participant had championed APL we'd all be either using APL or constantly excusing ourselves.

I think the major issue is that APL seems to require more than ASCII to work it.

Re:Sed challenge: join cal -y months into a single column by wahern on Wednesday November 17, 2021 @10:04PM (#29261572)
AFAIU APL implementations very early on supported ASCII equivalents. But maybe it was too late to either disabuse people of the notion that it required non-ASCII, or the convention proved too strong to overcome.
Re:Sed challenge: join cal -y months into a single column by voldacar on Thursday November 18, 2021 @12:36AM (#29262295)
there are ascii variants of APL like j,q,k etc
Re:Sed challenge: join cal -y months into a single column by boffinAudio on Thursday November 18, 2021 @09:28AM (#29265752)
In the very halcyon days of Unix, lets just say early-80's, I met so many new-to-C guys coming away from APL screaming, with their hair on fire, that I, as an innocent young mangenue, was sure it would be one of those languages that would die a horrid yet rapid death and I could therefore completely ignore it.

Yet, here we are. I'm still amazed to see people using it, and even more amazed to see someone break it out for some toy play.

Still, not gonna learn it. I like my hair.

Re:Sed challenge: join cal -y months into a single column by rak1507 on Thursday November 18, 2021 @07:43AM (#29264760)
Yeah agreed, Dyalog APL started out on Unix but is now more focused on Windows, I wish I could integrate it into scripts and things but it's often difficult/impossible to do so.
Re:Sed challenge: join cal -y months into a single column by totetsu on Thursday November 18, 2021 @12:54AM (#29262386)
(⊃0⍵0)⊃ ⊂{⍨⊂}
Re:Sed challenge: join cal -y months into a single column by eloisius on Wednesday November 17, 2021 @07:06PM (#29260562)
And people say Ruby is beautiful