It finally adds easy-to-use Case operations to APL.
And there's really not so much to it. The left (currently, we might extend that in the future) argument has to be a single simple scalar integer, 1 or ¯1 or ¯3.
@JeffZeitlin For ASCII and most European languages, there's no difference between lowercasing and normalising case. However, some languages have multiple forms of a single letter. Normalising makes all those forms the same, so they can be compared easily.
@rak1507 We couldn't use 0 because there'd be no obvious corresponding number for the length-changing equivalent. Also, we may extend 0 to mean a case-query.
Can anyone find my 11-character solution? (Hint: a train ― of course.)
Maybe we should continue meanwhile…
Let's have a look at ⎕DT. It is the all-knowing wizard of date-time conversions. Basically, it allows you to convert any numeric representation of a date-time into any other representation. You can use it to glue together two 3rd-party systems that otherwise can't easily communicate.
@Razetime Welcome to. We're in the middle of an APL lesson, but feel free to hang around.
The left argument, as you've seen, tells ⎕DT what you want to convert to. The numbers are largely arbitrary, but not entirely so. Positive codes indicate a scalar format (one number per date-time) and negative numbers indicate a vector format (multiple numbers per date-time).
Also the number divided by 10 and floored indicates the family. So we had 2(0) for UNIX and 4(0) for applications (Excel).
The last element of ⎕TS is the milliseconds. We can get more precision in the ⎕TS-style result by using ¯2 for microseconds and ¯3 for nanoseconds:
I won't bother you with all the allowed codes. They are readily available in the documentation.
What you do need to know is how to convert from one of these formats.
Until now, we've just used the Dyalog day number. That's the default for simple scalars in the right argument. The default for enclosed vectors is the ⎕TS format (¯1).
If your input is anything else, you need to give ⎕DT a two-element left argument. The first element is the input type, and the second is the output type.
E.g. This converts an ISO year, week of year, day of week to ⎕TS-style:
@Adám Interesting. Never played around with SE bots, so I don't know what's possible. But wondering if when one edits a Dyalog Bot thing, if the bot can then edit its response?
Challenge: Given two style dates (as a 2 element vector of Y,M,D vectors), compute the inclusive number of days between them. E.g. (2020 6 25)(2020 08 10) should give 47.
@AviFS I guess it is potentially possible. Ask Moonchild.
(2020 08 10)(2020 6 25) should also give 47. And (2020 08 10)(2020 08 10) should give 1.
If anyone wants more time, let me know now. Otherwise, I'll assume nobody is working on the challenge :-)
OK: {1+|-/1⎕DT⍵} will do.
@JeffZeitlin OK, now for the last 15 mins, let's talk about converting date-times to text.
The first step is to convert to a Dyalog day number.
Then you use 1200⌶ to convert that to text. It takes a left argument which is a pattern using a scheme we came up with, which I think is a really neat one. Much better than any of the existing ones out there.
The system in the pattern for 1200⌶ is that numeric parts of the date are uppercase, while parts of the time are lowercase. You can use a single character for a variable-width pattern, or multi-character for a 0-padded pattern. If instead you want space-padding, use an underscore as the first character:
@JeffZeitlin That one was the most controversial of our choices. I guess you can remember it as "hour" of the day, and simply "time" (which isn't enough to specify the hour).
@Quintec Yes and no. There's no mechanism for attaching a timezone to a value. However, we do provide 'Z' and 'J' to mean Zulu time and local time, allowing you to compute the current offset. (We also included the other military time zones for convenience.)
@JeffZeitlin Because it was unclear if this formatting should be stand-alone, folded into ⎕FMT or ⍕, or be an extension of ⎕DT. Notice that the left arguments of ⎕DT and 1200⌶ don't conflict, so we could allow 20 '%ISO%' ⎕DT dates to format Unix times directly, without converting them first.
('%ISO%' is a built-in pre-defined pattern equivalent to 'YYYY-MM-DD"T"hh:mm:ss'. You can define more such patterns.)
Anyone up for discussing 2019's phase 1 q1 with me? my solution is 1∘=|∘⍳∘≢⊂⊢ but I'm wondering how that can be made better, there seems to be a lot of ∘s and idk if that's necessary.
@rak1507 That looks good for a tacit solution. If you find yourself using a lot of monadic functions, it is often better to go with a dfn: {1=⍵⊂⍨⍺|⍳≢⍵}
@rak1507 I'll give you two hints: N↑Y will pad Y appropriately if it runs out of elements before reaching length N while N⍴Y will recycle elements from Y to reach length N.
@rak1507 Indeed, you should be careful using ⍎, but if you know what the content is composed of, you're fine. 1⍕ will not format text that can be interpreted as code. The safe alternative to ⍎ (for making text into numbers) is ⎕VFI.
Hey, I'm trying to make a train that will filter out arrays of two number pairs to only give ones where the sum is a certain number, and I've tried (10=+/¨∘|)/⊣ but it doesn't seem to work, and I'm not quite sure why. Doing ((10=+/¨∘|) array) / array works, and that's the (f x) g x pattern I asked about earlier! So if anyone can help that'd be great
@rak1507 That's the exact problem with / family in trains. That doesn't work because the (10=+/¨∘|)/ part is interpreted as a reduce rather than a replicate.