News for hackers. Stuff that matters.

markjreed

Re:Dyalog APL Graphs on Thursday April 27, 2023 @04:20PM (#35733984)
Bold to assume that nobody on the cricket team has dated each other..
Just `pip install hy` and then `python -mhy` to run it. Once you see how Python translates into Hy, it's pretty straightforward.

    (import os)
    (import [os.path :as op])
    (with [f (open (op.join dir_name file_name) "w")]
        (.write f "..."))
Some things you just have to learn, like using `(setv var value)` to do assignment, or the fact that `(for)` is an imperative loop while `(lfor)` is a list comprehension, but a little experimentation goes a long way and the docs are quite good.
Installed it, and the code in the README won't even run, so I guess it's not quite ready for messing with. Looks interesting in theory, though . . .
Re:Sed challenge: join cal -y months into a single column 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 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