1

“Add the option -f to fold upper and lower case together, so that case distinctions are not made during sorting; for example, a and A compare equal.”

Excerpt From: Brian W. Kernighan. “The C Programming Language, Second Edition.

I am not sure what this means exactly. I was thinking about two options:

  • convert all uppercase to lowercase letters or vice versa
  • keep the cases as they are and merely treat them as equal

Does the expression to fold something together in this case have a specific meaning?
Or am I free to choose an interpretation?

5
  • 1
    Treat them as equal, as given in the example. Think of the idiom, bring into the fold.
    – lurker
    Commented Jan 3, 2016 at 1:53
  • That is keep them unequal values, but treat them as if they were equal, right?
    – Ely
    Commented Jan 3, 2016 at 2:01
  • 1
    It takes away the distinction between Capital and Lower Case, so Apple, APPLE and apple are all the same.
    – lurker
    Commented Jan 3, 2016 at 2:05
  • I think I got that point, but I am not sure if I am understood. So merely treat them as if they were equal, but not turning them into equal? Do you know what I mean? Does the expression imply either of the meanings or is it more abstract ?
    – Ely
    Commented Jan 3, 2016 at 2:28
  • 1
    I'm sorry, mate. You are correct - treats them as equal for the sake of the sort.
    – lurker
    Commented Jan 3, 2016 at 2:47

1 Answer 1

1

To "fold x and y together" is to put both x and y into the same category. In other words, you treat both of them as equals. In more rigorous terms (for your CS stuff):

if x = b, and y = b, then x must = y

To actually answer your question, though, folding things together does NOT mean to convert them all into the same object. It just means to treat that as equals - members of a single group, in which all items are equal.

HOWEVER, what I said above is about the language meaning. In computer science, the implementation for this could be converting all of the objects to be equal (in this case, calling .upper() or .lower() on all of the input strings, or however you fix all of the characters to be of the same case). This likely isn't the way it is implemented, because it isn't very efficient to start mutating all of these strings (nor is it possible in many languages...you have to create new objects), but it certainly is a possible implementation. So yes, both are possible options in the world of computer science.

(As a sidenote, you've picked a great book to read! Kernighan is great - I met him once, and he's really very nice.)

2
  • Thank you. I understand that to fold things together is commonly understood as treat things as if they were the same. Or is it not so common? Your answer solved it for me in my specific case.
    – Ely
    Commented Jan 3, 2016 at 3:09
  • @Elyasin Yes. That is correct. Actually making the objects equal is ONE possible way of treating them as equals. Simply having them be treated as equals in a comparator is another way of treating them as equals.
    – Alex K
    Commented Jan 3, 2016 at 3:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .