Talk:Empty string

From Rosetta Code

Can we have an example of a language which has special syntax for empty strings, to justify the first claim in the task description? —Kevin Reid 21:51, 4 July 2011 (UTC)

The Perl 6 and Python examples both mentioned how empty strings are treated as boolean false, while nonempty ones are true (well in Perl if nonempty string looks like number "0" it's again treated as false, but that's more exception than rule). --Ledrug 23:30, 4 July 2011 (UTC)
Those are interpretations or semantics of empty strings, not syntax for empty strings. —Kevin Reid 00:16, 5 July 2011 (UTC)
There are lots of examples of languages with special semantics around null strings. Syntax, I'm not so sure. SNOBOL was one, variables are NULL strings by default and they get reinterpreted depending on the operation. Add a null string and it treats it as a zero. Icon/Unicon have special syntax for a null type but that's not the same as a null string. What's expected where a language doesn't have special syntax? --Dgamey 03:26, 5 July 2011 (UTC)
Just demonstrate how to achieve the task would be achieved within the language. Markhobley 08:32, 5 July 2011 (UTC)
Perhaps ruby's nil.to_s would count as special syntax? --Rdm 16:49, 5 July 2011 (UTC)

No one has presented an example of syntax for creating an empty string, so unless there are any objections I will remove that part of the task description soon. —Kevin Reid 17:57, 6 July 2011 (UTC)

Ok hang on a bit with that: ruby has already been mentioned and I may be able to provide some more examples. Markhobley 18:31, 6 July 2011 (UTC)
nil.to_s is not syntax; it's a method of nil! I will wait. —Kevin Reid 18:42, 6 July 2011 (UTC)
Certainly. But nil.to_s has syntax which is not the standard syntax for representing an arbitrary string. But perhaps your objection is that the syntax involved is not dedicated to the purpose of representing empty strings? It's true that the method invocation syntax behind nil.to_s is very general and that 'arbitrary string'.to_s can be used to represent an arbitrary string. --Rdm 19:58, 6 July 2011 (UTC)
I think Kevin Reid's objection is valid, as none of the examples here so far provided a syntax dedicated to dealing with an empty string; nil.to_s in a sense is still showing the semantics about equivenlance between nil and empty string. It probably wouldn't do any harm to leave the "syntax" wording alone, but strictly speaking it shouldn't be there. --Ledrug 01:28, 8 July 2011 (UTC)
How about Here, an empty replacement field is treated as an empty string. (Note that in another context in snobol, blank is a concatenation operator.) Note also that the same issue arises in shell scripting: in various contexts the absence of an argument is treated the same as the presence of an empty string. In other words, the following are equivalent:
<lang bash>$ FOO='5'; FOO=; echo $FOO

$ FOO='5'; FOO=; echo $FOO</lang> --Rdm 01:40, 8 July 2011 (UTC)

Heh the SNOBOL example is fair enough. As for shells, the multitude of quoting rules, whitespaces and such are so all over the place that I'd rather we not discuss it (but if you want to feed a program an empty argument instead of no argument, you do say foo "", not foo — but hey, I'm not discussing it.) :) --Ledrug 02:42, 8 July 2011 (UTC)
The possible minor rewording of the task description will not affect the task itself. Is there any reason that we can not promote this to task? Markhobley 16:42, 7 July 2011 (UTC)