News for hackers. Stuff that matters.
Re:Wikifunctions by solardev on Wednesday December 06, 2023 @04:44PM (#38549939)
Whoa, I never knew (and accidentally discovered through this) that empty strings are valid substrings of other strings.
Re:Wikifunctions by threatofrain on Wednesday December 06, 2023 @07:54PM (#38551544)
As long as your language includes an empty string concept, why not? Similarly, is an empty array a subarray of any array? And on the other end, can you have an empty number boolean?
Re:Wikifunctions by avereveard on Wednesday December 06, 2023 @10:01PM (#38552307)
But then if empty string are part of a string at what index do you find an empty string within a string you cannot dereference the space between letters
Re:Wikifunctions by account42 on Friday December 08, 2023 @05:40AM (#38567461)
At every index of course, including one past the last character.

You don't need to dereference anything here as the empty string has length 0.

Re:Wikifunctions by avereveard on Monday December 11, 2023 @11:47AM (#38602168)
I see thanks
Re:Wikifunctions by nodogoto on Wednesday December 06, 2023 @07:04PM (#38551182)
So long as you consider "empty strings" to be "strings" in the first place. String of what?

It's like saying you have an "empty cup of water".

Re:Wikifunctions by cfiggers on Wednesday December 06, 2023 @11:14PM (#38552750)
You just... Blew my mind.

So, but wait... Is the genitive "of water" functioning like an assertion? "All of the contents of the cup are water."

And wouldn't that assertion, in the case where the cup has no contents, be a vacuous truth?[0]

In other words, a cup of water, if it actually has water in it, cannot also be a cup of magma. But there's nothing stopping an cup with no contents at all being "of" both.

[0] https://en.wikipedia.org/wiki/Vacuous_truth

Re:Wikifunctions by mistercheph on Wednesday December 06, 2023 @11:59PM (#38553006)
It's time to put down the encyclopedia and pick up Plato and Aristotle
Re:Wikifunctions by lgeorget on Thursday December 07, 2023 @02:02AM (#38553666)
It holds true mathematically speaking. You can make (mathematical) sets of everything but there's only one empty set.

It's a bit like that with pointers in C: a char* is not a int* but null pointers are convertible to any pointer type.

Re:Wikifunctions by smsm42 on Thursday December 07, 2023 @01:53AM (#38553613)
As long as you consider cups of water and cups of milk be different objects (i.e. cups are not interchangeable, and you can't just throw out milk and fill it with water) it is a completely sensible statement.

For example, in Jewish religious families, there are often two sets of kitchen utensils - for meat products and for dairy/other products, since mixing those makes the food unfit for consumption by a religious person. In this situation, if you said "I have an empty meat pot" and somebody answered you "No, I need an empty milk pot, give me another one!" - it would make a total sense. Even though both pots are empty, they are not the same kind of pot for their users.

Similarly, if a string is a sequence of certain objects (characters, bytes, runes, graphemes, whatever you please) then empty sequence of such objects is not the same as an empty sequence of other objects - you could append a character to it, but you can't append a database connection to it, for example, and expect something sane to happen.

So yes, "empty cup of water" is exactly what it is, because in most programming languages, empty cups are not all alike. In some languages, there are sequence types that are agnostic towards their elements, and then an empty sequence of that kind wouldn't be a sequence of anything - it'd be just a separate entity. But strings rarely are implemented this way, for many practical reasons.

Re:Wikifunctions by account42 on Friday December 08, 2023 @05:36AM (#38567445)
People can come up with whatever weird believes they want, that doesn't mean this actually makes sense.
Re:Wikifunctions by smsm42 on Friday December 08, 2023 @10:53PM (#38578389)
You entirely missed the point of the example. The point is not that you are supposed to embrace their beliefs. The point is that object that are all alike in one system can be very different in another, and if you assume they are all alike, you will misunderstand what is going on. Such as, if you assume that empty string is just "nothing", you will misunderstand how strings - and in general, typed sequences - work in most programming languages.

It's like a bad student that when the teacher says "assume the train departs from the station at 9 am", to formulate a math problem, objects "but the train actually departs from our station at 10am!". Way to miss the point!

Re:Wikifunctions by chatmasta on Wednesday December 06, 2023 @06:23PM (#38550861)
It depends on language, library, and which substring function. And in some languages, like Bash IIRC, some functions and scripts handle differently `foo=""` (variable foo is set to empty string) and `foo=` (variable foo is not set).
Re:Wikifunctions by account42 on Friday December 08, 2023 @05:34AM (#38567433)
`foo=` does set the variable to empty in Bash and other POSIX compliant shells.
Re:Wikifunctions by ben0x539 on Wednesday December 06, 2023 @05:46PM (#38550542)
Well, not just _other_ strings.
Re:Wikifunctions by lemurien on Wednesday December 06, 2023 @05:41PM (#38550490)
It’s a bit like the empty set that is a subset of any other set.