Case Conversion: Mapping and Folding

Dyalog v18.0 introduced ⎕C, which converts the case of characters in an array by mapping to lower case, mapping to upper case, or folding. This superseded an earlier experimental I-beam (819⌶) that could map to lower or upper case but not fold – this I-beam is currently deprecated and will be removed in Dyalog v20.0.

There’s often confusion about the difference between mapping and folding. Mapping is used when you want characters in an array to be in a particular case, whereas folding is used when you want to eliminate case to perform case-insensitive comparisons. The confusion arises because case insensitive comparisons can usually be done well by mapping to lower case rather than folding – indeed, on first inspection, mapping to lower case and folding appear to be the same thing.

The difference is best illustrated through some examples. Used monadically, the I-beam maps to lower case and ⎕C folds:

      819⌶'Hello'
hello
      ⎕C'Hello'
hello

A case-insensitive match function that uses 819⌶ to map both arguments to lower case before checking if they match might look like this:

      cc←≡⍥(819⌶)

In many cases it will appear to work without issues:

      'hello' cc 'HELLO'
1
      'hello' cc 'GOODBYE'
0

However, it doesn’t always work. Greek, for example, has two different lower-case sigma characters (σ and ς) but only one upper case (Σ). ίσως and ΊΣΩΣ are case-insensitively equal, but the function does not work:

      'ίσως' cc 'ΊΣΩΣ'
0

This is because when these two arrays are mapped to lower case they become ίσως and ίσωσ respectively, which do not match. If we use folding instead:

      cc←≡⍥⎕C

the comparisons work as expected:

      'hello' cc 'HELLO'
1
      'hello' cc 'GOODBYE'
0
      'ίσως' cc 'ΊΣΩΣ'
1

This works because folding converts the Greek words to ίσωσ and ίσωσ respectively – every different sigma character, even the lower-case ones, have been changed to σ, and now the two arrays match.

The main use of case conversion is to perform caseless comparisons, so you might wonder why mapping to upper and lower case is supported at all. There are still occasions where you might need that – most notably, when formatting text for display.

If you are still using 819⌶ to perform caseless comparison you should change to using ⎕C to get correct behaviour. And do not forget that 819⌶ will not be supported beyond Dyalog v19.0.

Want to learn more? Adám Brudzewsky explains mapping and folding in this webinar, beginning at 00:06:33.

Welcome Karl Holt

Karl had always imagined that he would spend his career in academia, as had many who know him. However, after becoming disenchanted with the whole university environment halfway through his Master’s degree, he sought a role outside academia and joined Dyalog Ltd. Although he’s only been here for a few months, he feels that he has already settled in well.

Karl was one of the few computer science students who actually enjoyed the courses on project management; he was also part of an even smaller minority who enjoyed writing mathematical proofs! He not only brings his mathematics and coding abilities with him, but also a fresh energy to the team.

Karl is a perfectionist, and often spends countless hours contemplating the right way to pick up a cup and otherwise trivial daily activities. This fits perfectly with how he has been mentored by our CTO, Morten, as every time he has shown Morten what he found to be a specifically beautiful APL expression, Morten has shown him five different ways to do the same thing, each of which is even prettier and has its own strength!

Even though the majority of Karl’s education has been in the natural sciences, he also enjoys many facets of the “softer” ones. He has a broad range of interests, and always enjoys hearing about what other people are working on – everything from quantum physics to anthropological studies contemplating the queerness of algae. His favorite read in 2023 was “Invisible Women“, a book disclosing the big data gaps within political minorities, especially women’s experiences in a world designed for men.

Karl is just as happy being an interested listener to a conversation as he is being the main speaker. He keeps a long list of projects he would love to work on if he someday had the time; for now, he spends his spare time playing board games, solving fun puzzles, staring at bodies of water, and hanging out with his friends and many siblings.

Employee Spotlight: Stefan

About to ski down to the fjord in Norway’s Sunnmøre Alps

It’s now one year since Stefan joined Dyalog Ltd, and we asked him what he made of the experience so far. “I can’t believe how time flies. It feels like it was only yesterday I arrived at the Bramley office for the first time, to pick up my laptop and meet everyone.”

Prior to joining us, Stefan worked for IBM, where he discovered APL more or less by accident. “Coming from a huge, anonymous mega-corp, it’s a welcome change being able to actually get to know the whole company,” Stefan continues. “Here, of course people have their particular core areas, but everyone gets stuck in with a little bit of everything.”

Stefan takes a particular interest in the Mac platform, as he is a life-long, unapologetic Apple user. Everywhere else he’s worked (especially at IBM, inventor of the PC), developers demand Apple hardware, so he was surprised to find that at Dyalog Ltd, that’s more unusual.

Epic powder day in Italy’s Courmayeur

Outside work, Stefan likes the adventurous side of the great outdoors. He spent many years rock climbing home and abroad, until chronic elbow tendinitis forced a stop to that. Back country skiing is another hobby, and he tends to take all his vacation days in winter. “Living aboard a boat in Svalbard, skiing with a rifle to ward against polar bears was a bucket list experience”, he says. “Sampling the famous japow and live volcanos on Hokkaido, and ticking couloirs in Canada’s Purcells range is up there, too.” Stefan rides bikes to keep fit, and his garage has accumulated far too many bikes over the years.

“Dyalog is my dream gig,” he says. “I always wanted to work for a company where the people really care for the product they make.”

Top of the Grandpa Peabody boulder in The Buttermilks, Bishop, California