Case-sensitivity of identifiers: Difference between revisions

Add Zig example
No edit summary
(Add Zig example)
 
(24 intermediate revisions by 15 users not shown)
Line 143:
'The three dogs are named ',DOG,', ',Dog,', and ',dog
The three dogs are named Benjamin, Samba, and Bernie</syntaxhighlight>
 
=={{header|AppleScript}}==
AppleScript labels are case insensitive, every instance of a particular label within a script document compiling to the same case as the first instance. It's possible to use vertical bars — normally used to distinguish labels from identical language or library keywords — to give the same label different cases within a script, but there's little point in doing so as it's still the same label.
 
<syntaxhighlight lang="applescript">set {dog, |Dog|, |DOG|} to {"Benjamin", "Samba", "Bernie"}
 
if (dog = |Dog|) then
if (dog = |DOG|) then return "There is just one dog named " & dog & "."
return "There are two dogs named " & dog & " and " & |DOG| & "."
else if (dog = |DOG|) then
return "There are two dogs named " & dog & " and " & |Dog| & "."
end if
return "The three dogs are named " & dog & ", " & |Dog| & ", and " & |DOG| & "."</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"There is just one dog named Bernie."</syntaxhighlight>
 
=={{header|Arturo}}==
 
Line 170 ⟶ 187:
 
The three dogs are named Benjamin, Samba and Bernie.
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{works with|QBasic}}
Applesoft BASIC is case-insensitive. Applesoft BASIC keyword tokens and variable names get converted to upper case in programs. Only the first two characters of variable names are significant.
QBASIC is case-insensitive
<syntaxhighlight lang="basic">dog$ = "Benjamin":Dog$ = "Samba":DOG$ = "Bernie":III = 254 * (DOG$ = dog$ AND Dog$ = DOG$) + 1: PRINT MID$ ("There is just one dog",256 - III) MID$ ("The three dogs are",III)" named " MID$ (dog$ + ", " + Dog$ + " and ",III)DOG$"."</syntaxhighlight>
<syntaxhighlight lang="basic256">DOG$ = "Benjamin"
{{out}}
DOG$ = "Samba"
<pre>There is just one dog named Bernie.</pre>
DOG$ = "Bernie"
The Apple II and Apple II plus will convert all input characters to upper case.
PRINT "There is just one dog, named "; DOG$</syntaxhighlight>
<pre>THERE IS JUST ONE DOG NAMED BERNIE.</pre>
=={{header|BASIC256}}==
 
==={{header|BASIC256}}===
BASIC256 is case-insensitive
<syntaxhighlight lang="basic256">dog = "Benjamin"
Line 184 ⟶ 204:
print "There is just one dog, named "; dog
end</syntaxhighlight>
{{out}}
<pre>There is just one dog, named Bernie</pre>
 
==={{header|BBC BASIC}}===
<syntaxhighlight lang="bbcbasic"> dog$ = "Benjamin"
Dog$ = "Samba"
DOG$ = "Bernie"
PRINT "The three dogs are " dog$ ", " Dog$ " and " DOG$ "."</syntaxhighlight>
{{out}}
<pre>The three dogs are Benjamin, Samba and Bernie.</pre>
 
==={{header|Chipmunk Basic}}===
Chipmunk Basic is case-insensitive
<syntaxhighlight lang="qbasic">10 dog$ = "Benjamin"
20 dog$ = "Smokey"
30 dog$ = "Samba"
40 dog$ = "Bernie"
50 print "There is just one dog, named ";dog$</syntaxhighlight>
{{out}}
<pre>There is just one dog, named Bernie</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
' FreeBASIC is case-insensitive
Dim dog As String
dog = "Benjamin"
Dog = "Samba"
DOG = "Bernie"
Print "There is just one dog, named "; dog
Sleep</syntaxhighlight>
{{out}}
<pre>There is just one dog, named Bernie</pre>
 
==={{header|FutureBasic}}===
FB is lettercase-insensitive and throws an error with variables or constants with identical names but of varying case. However, here's an easy work around.
<syntaxhighlight lang="futurebasic">CFDictionaryRef canines
canines = @{@"dog":@"Benjamin", @"Dog":@"Samba", @"DOG":@"Bernie"}
print "The three dogs are "; canines[@"dog"]; ", "; canines[@"Dog"]; " and "; canines[@"DOG"]; "."
 
HandleEvents</syntaxhighlight>
{{out}}
<pre>There are three dogs named Benjamin, Samba and Bernie.</pre>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
GW-BASIC is case-insensitive. GW-BASIC keyword tokens and variable names get converted to upper case in programs.
<syntaxhighlight lang="qbasic">10 dog$ = "Benjamin"
20 dog$ = "Smokey"
30 dog$ = "Samba"
40 dog$ = "Bernie"
50 print "There is just one dog, named ";dog$</syntaxhighlight>
{{out}}
<pre>There is just one dog, named Bernie</pre>
 
==={{header|Liberty BASIC}}===
{{works with|Just BASIC}}
Just BASIC and Liberty BASIC names are case sensitive
 
NB the IDE warns you that there are similar variables named dog$, Dog$ & DOG$
<syntaxhighlight lang="lb">
dog$ = "Benjamin"
Dog$ = "Samba"
DOG$ = "Bernie"
print "The three dogs are "; dog$; ", "; Dog$; " and "; DOG$; "."
 
end</syntaxhighlight>
{{out}}
<pre>The three dogs are Benjamin, Samba and Bernie.</pre>
 
==={{header|Minimal BASIC}}===
Minimal BASIC is case-insensitive. Minimal BASIC convert all input characters to upper case.
<syntaxhighlight lang="qbasic">10 let d$ = "Benjamin"
20 let D$ = "Samba"
30 print "There is just one dog, named "; d$
40 end</syntaxhighlight>
{{out}}
<pre>THERE IS JUST ONE DOG, NAMED SAMBA</pre>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
MSX BASIC is case-insensitive. MSX-BASIC keyword tokens and variable names get converted to upper case in programs.
<syntaxhighlight lang="qbasic">10 dog$ = "Benjamin"
20 dog$ = "Smokey"
30 dog$ = "Samba"
40 dog$ = "Bernie"
50 print "There is just one dog, named ";dog$</syntaxhighlight>
{{out}}
<pre>There is just one dog, named Bernie</pre>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">dog$="Benjamin"
Dog$="Samba"
DOG$="Bernie"
Debug "There is just one dog named "+dog$</syntaxhighlight>
 
==={{header|QBasic}}===
QBASIC is case-insensitive
<syntaxhighlight lang="basic256">DOG$ = "Benjamin"
DOG$ = "Samba"
DOG$ = "Bernie"
PRINT "There is just one dog, named "; DOG$</syntaxhighlight>
 
==={{header|Quite BASIC}}===
Quite BASIC is case-insensitive
<syntaxhighlight lang="qbasic">10 let d$ = "Benjamin"
20 let D$ = "Samba"
30 print "There is just one dog, named "; d$
40 end</syntaxhighlight>
{{out}}
<pre>There is just one dog, named Samba</pre>
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
Run BASIC names are case sensitive
<syntaxhighlight lang="runbasic">
dog$ = "Benjamin"
doG$ = "Smokey"
Dog$ = "Samba"
DOG$ = "Bernie"
print "The 4 dogs are "; dog$; ", "; doG$; ", "; Dog$; " and "; DOG$; "."</syntaxhighlight>
{{out}}
<pre>The 4 dogs are Benjamin, Smokey, Samba and Bernie.</pre>
 
==={{header|True BASIC}}===
{{works with|QBasic}}
True Basic is case-insensitive
<syntaxhighlight lang="qbasic">LET dog$ = "Benjamin"
LET Dog$ = "Samba"
LET DOG$ = "Bernie"
PRINT "There is just one dog, named "; dog$
END</syntaxhighlight>
 
==={{header|XBasic}}===
XBasic in case-insensitive
<syntaxhighlight lang="qbasic">PROGRAM "Case-sensitivity"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
dog$ = "Benjamin"
dog$ = "Smokey"
dog$ = "Samba"
dog$ = "Bernie"
PRINT "There is just one dog, named "; dog$
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
<pre>There is just one dog, named Bernie</pre>
 
==={{header|Yabasic}}===
Yabasic names are case sensitive:
<syntaxhighlight lang="yabasic">
dog$ = "Benjamin"
doG$ = "Smokey"
Dog$ = "Samba"
DOG$ = "Bernie"
print "The four dogs are named ", dog$, ", ", doG$, ", ", Dog$, " and ", DOG$
end</syntaxhighlight>
{{out}}
<pre>The four dogs are named Benjamin, Smokey, Samba and Bernie</pre>
 
==={{header|ZX Spectrum Basic}}===
<syntaxhighlight lang="basic">10 LET D$="Benjamin"
20 PRINT "There is just one dog named ";d$</syntaxhighlight>
 
=={{header|Batch File}}==
<syntaxhighlight lang="dos">
Line 199 ⟶ 388:
There is just one dog named Bernie.
</pre>
 
=={{header|BBC BASIC}}==
<syntaxhighlight lang="bbcbasic"> dog$ = "Benjamin"
Dog$ = "Samba"
DOG$ = "Bernie"
PRINT "The three dogs are " dog$ ", " Dog$ " and " DOG$ "."</syntaxhighlight>
Output:
<pre>The three dogs are Benjamin, Samba and Bernie.</pre>
=={{header|bc}}==
The only variables are 'a' through 'z'. They can only hold numbers, not strings. Some implementations allow longer names like 'dog', but only with lowercase letters. A name like 'Dog' or 'DOG' is a syntax error.
Line 338 ⟶ 521:
 
These are the style warnings from [[SBCL]]. Other implementations of Common Lisp might give different warnings.
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
var dog := "Benjamin";
var Dog := "Samba";
var DOG := "Bernie";
 
print("There are three dogs named ");
print(dog);
print(", ");
print(Dog);
print(", and ");
print(DOG);
print(".\n");</syntaxhighlight>
{{out}}
<pre>There are three dogs named Benjamin, Samba, and Bernie.</pre>
 
=={{header|Crystal}}==
<syntaxhighlight lang="crystal">dog = "Benjamin"
Line 348 ⟶ 548:
{{out}}
<pre>The three dogs are named Benjamin, Samba and Bernie.</pre>
 
=={{header|D}}==
<syntaxhighlight lang="d">import std.stdio;
Line 361 ⟶ 562:
Output:
<pre>There are three dogs named Benjamin, Samba, and Bernie'</pre>
 
=={{header|Dart}}==
Dart names are case sensitive
 
note: The name of the variables 'Dog' and 'DOG' is not a lowerCamelCase identifier.
<syntaxhighlight lang="dart">void main() {
String dog = "Benjamin", doG = "Smokey", Dog = "Samba", DOG = "Bernie";
 
print("The four dogs are named $dog, $doG, $Dog and $DOG");
}</syntaxhighlight>
{{out}}
<pre>The four dogs are named Benjamin, Smokey, Samba and Bernie</pre>
 
=={{header|dc}}==
A register name has only one character, so this example uses 'd' and 'D'.
Line 409 ⟶ 623:
{{out}}
<pre>There are three dogs named Benjamin, Samba and Bernie.</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc main() void:
*char dog = "Benjamin",
Dog = "Samba",
DOG = "Bernie";
 
writeln("There are three dogs named ",
dog, ", ", Dog, ", and ", DOG, ".")
corp</syntaxhighlight>
{{out}}
<pre>There are three dogs named Benjamin, Samba, and Bernie.</pre>
 
=={{header|EasyLang}}==
EasyLang is case-sensitive.
<syntaxhighlight lang="easylang">dog$ = "Benjamin"
Dog$ = "Samba"
DOG$ = "Bernie"
#
print "The three dogs are named " & dog$ & ", " & Dog$ & ", and " & DOG$ & "."</syntaxhighlight>
 
=={{header|EchoLisp}}==
<syntaxhighlight lang="scheme">
Line 418 ⟶ 653:
The three dogs are named Benjamin, Samba and Bernie.
</syntaxhighlight>
 
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
String dog = "Benjamin"; // convention: lower camelCase for variable and property names
String Dog = "Samba"; // convention: upper CamelCase for class, type, and constant names
String DOG = "Bernie"; // convention: all-caps only for constants
 
@Inject Console console;
console.print($"There are three dogs named {dog}, {Dog}, and {DOG}");
</syntaxhighlight>
 
=={{header|Elena}}==
In ELENA identifiers are case sensitive.
Line 520 ⟶ 766:
Output:
<pre> There is just one dog named Bernie</pre>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
' FreeBASIC is case-insensitive
Dim dog As String
dog = "Benjamin"
Dog = "Samba"
DOG = "Bernie"
Print "There is just one dog, named "; dog
Sleep</syntaxhighlight>
 
{{out}}
<pre>
There is just one dog, named Bernie
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
 
' FutureBasic is case-insensitive
CFStringRef dog
 
dog = @"Benjamin"
Dog = @"Samba"
DOG = @"Bernie"
 
window 1
print @"There is just one dog named "dog"."
 
HandleEvents
 
{{out}}
<pre>
There is just one dog named Bernie.
</pre>
 
=={{header|Frink}}==
Frink is case-sensitive.
Line 562 ⟶ 772:
DOG = "Bernie"
println["There are three dogs named $dog, $Dog and $DOG"]</syntaxhighlight>
 
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=fed58074944b894f5d4cfb8e16c6819a Click this link to run this code]'''
Line 820 ⟶ 1,032:
<pre>3
Samba </pre>
=={{header|Liberty BASICLogtalk}}==
NB the IDE warns you that there are similar variables named dog$, Dog$ & DOG$
<syntaxhighlight lang="lb">
dog$ = "Benjamin"
Dog$ = "Samba"
DOG$ = "Bernie"
print "The three dogs are "; dog$; ", "; Dog$; " and "; DOG$; "."
 
In Logtalk, as in the underlying Prolog, variables must begin with an uppercase character or an underscore. Thus the task as written cannot be performed but an analogous one can be.
end
 
<syntaxhighlight lang="logtalk">
:- object(three_dogs_or_one).
 
:- public(test/0).
 
test :-
fill_dogs(DOG, Dog, DoG),
write_message(DOG, Dog, DoG).
 
% Note: this predicate would actually fail if variables weren't case sensitive...
fill_dogs('Benjamin', 'Samba', 'Bernie').
 
% Note: ...as a result there is no way for this clause to ever succeed.
write_message(A, A, A) :-
format('There is one dog named ~w.~n', [A]).
 
write_message(A, B, C) :-
A \= B, B \= C, A \= C,
format('There are three dogs named ~w, ~w, and ~w.~n', [A, B, C]).
 
:- end_object.
</syntaxhighlight>
 
The three dogs are Benjamin, Samba and Bernie.
{{Out}}
 
<pre>
?- {dogs}.
% ... messages elided
?- true.
 
?- three_dogs_or_one::test.
There are three dogs named Benjamin, Samba, and Bernie.
true.
?-
</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">dog = "Benjamin"
Line 838 ⟶ 1,079:
print( "There are three dogs named "..dog..", "..Dog.." and "..DOG.."." )</syntaxhighlight>
<pre>There are three dogs named Benjamin, Samba and Bernie.</pre>
 
=={{header|M2000 Interpreter}}==
Labels are case sensitive, but identifiers are not case sensitive.
Line 904 ⟶ 1,146:
is(a = A);
false</syntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.1937.30}}
min's symbols are case sensitive.
<syntaxhighlight lang="min">"Benjamin" :dog
Line 911 ⟶ 1,154:
"Bernie" :DOG
 
"There are three dogs named $1, $2, and $3." (dog Dog DOG)=> =% printputs!</syntaxhighlight>
{{out}}
<pre>There are three dogs named Benjamin, Samba, and Bernie.</pre>
<pre>
 
There are three dogs named Benjamin, Samba, and Bernie.
</pre>
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">dog = "Benjamin"
Line 937 ⟶ 1,179:
InOut.WriteLn
END dog.</syntaxhighlight>
 
=={{header|N/t/roff}}==
In groff, string variables are case sensitive.
<syntaxhighlight lang="nroff">
.ds dog Benjamin
.ds Dog Samba
.ds DOG Bernie
The three dogs are named \*[dog], \*[Dog] and \*[DOG].
</syntaxhighlight>
{{out}}
<pre>The three dogs are named Benjamin, Samba and Bernie.
</pre>
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">dog = "Benjamin"
Line 950 ⟶ 1,205:
def DOG = "Bernie";
WriteLine($"The three dogs are named $dog, $Dog, and $DOG");</syntaxhighlight>
 
=={{header|NESL}}==
NESL is completely case-insensitive.
Line 1,096 ⟶ 1,352:
The three dogs are named Benjamin, Samba and Bernie
</pre>
=={{header|PHP}}==
<syntaxhighlight lang="PHP"><?php
 
// In true PHP style, this example is inconsistent.
// Variable identifiers are case sensitive
 
$dog = 'Benjamin';
$Dog = 'Samba';
$DOG = 'Bernie';
 
echo "There are 3 dogs named {$dog}, {$Dog} and {$DOG}\n";
 
// Whereas function identifiers are case insensitive
 
function DOG() { return 'Bernie'; }
 
echo 'There is only 1 dog named ' . dog() . "\n";</syntaxhighlight>
 
'''Output:'''
 
There are 3 dogs named Benjamin, Samba and Bernie<br>
There is only 1 dog named Bernie
 
=={{header|PicoLisp}}==
<syntaxhighlight lang="picolisp">(let (dog "Benjamin" Dog "Samba" DOG "Bernie")
Line 1,101 ⟶ 1,380:
Output:
<pre>The three dogs are named Benjamin, Samba and Bernie</pre>
 
=={{header|PL/I}}==
<syntaxhighlight lang="pli">*process or(!) source xref attributes macro options;
Line 1,157 ⟶ 1,437:
 
</pre>
=={{header|PureBasic}}==
<syntaxhighlight lang="purebasic">dog$="Benjamin"
Dog$="Samba"
DOG$="Bernie"
Debug "There is just one dog named "+dog$</syntaxhighlight>
=={{header|Python}}==
Python variable names are case sensitive:
<syntaxhighlight lang="python">>>> dog = 'Benjamin'; Dog = 'Samba'; DOG = 'Bernie'
Dog = 'Samba'
>>> print ('The three dogs are named ',dog,', ',Dog,', and ',DOG)
DOG = 'Bernie'
The three dogs are named Benjamin , Samba , and Bernie
 
>>> </syntaxhighlight>
print(f"The three dogs are named {dog}, {Dog} and {DOG}.")</syntaxhighlight>
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery">[ $ 'Benjamin' ] is dog ( --> $ )
Line 1,319 ⟶ 1,596:
see "The 4 dogs are : " + dog + ", " + doG + ", " + Dog + " and " + DOG + "."
</syntaxhighlight>
=={{header|RPL}}==
RPL designers recommend to use lowercase for local variables, whilst uppercase shall be used for global variables and programs.
≪ "Samba" 'DOG' STO → "Benjamin" "Bernie" Dog dog
≪ '''IF''' DOG dog == '''THEN'''
"Just 1 dog named " DOG +
'''ELSE'''
"3 dogs: " Dog + ", " + DOG + " & " + dog +
'''END'''
≫ ≫ EVAL
{{out}}
<pre>
1: "3 dogs: Benjamin, Samba & Bernie"
</pre>
 
=={{header|Ruby}}==
Ruby gives a special meaning to the first letter of a name. A lowercase letter starts a local variable. An uppercase letter starts a constant. So <tt>dog</tt> is a local variable, but <tt>Dog</tt> and <tt>DOG</tt> are constants. To adapt this task to Ruby, I added <tt>dOg</tt> and <tt>doG</tt> so that I have more than one local variable.
Line 1,341 ⟶ 1,632:
The local variables are dog, dOg, doG, names.
The constants are Dog, DOG.</pre>
 
=={{header|Run BASIC}}==
 
<syntaxhighlight lang="runbasic">
dog$ = "Benjamin"
doG$ = "Smokey"
Dog$ = "Samba"
DOG$ = "Bernie"
print "The 4 dogs are "; dog$; ", "; doG$; ", "; Dog$; " and "; DOG$; "."
</syntaxhighlight>
=={{header|Rust}}==
Rust style dictates that identifiers should be written in snake case, e.g. <tt>big_dog</tt>, <tt>small_dog</tt>; whereas types (structs and enums) should be written in camel case, e.g. <tt>BigDog</tt>, <tt>SmallDog</tt>. Failing to comply with this standard does not cause a compiler error, but it will trigger a compiler warning, and the culture is very strongly towards compliance with this standard.
Line 1,517 ⟶ 1,802:
Which prints...
<pre>The three dogs are named Benjamin, Samba and Bernie</pre>
=={{header|True BASIC}}==
{{works with|QBasic}}
True Basic is case-insensitive
<syntaxhighlight lang="qbasic">LET dog$ = "Benjamin"
LET Dog$ = "Samba"
LET DOG$ = "Bernie"
PRINT "There is just one dog, named "; dog$
END</syntaxhighlight>
=={{header|UNIX Shell}}==
<syntaxhighlight lang="sh">dog="Benjamin"
Line 1,556 ⟶ 1,833:
=={{header|Wren}}==
Identifiers in Wren are case sensitive.
<syntaxhighlight lang="ecmascriptwren">var dog = "Benjamin"
var Dog = "Samba"
var DOG = "Bernie"
Line 1,565 ⟶ 1,842:
The three dogs are named Benjamin, Samba and Bernie.
</pre>
 
=={{header|XBS}}==
In XBS variable names are case-sensitive.
Line 1,591 ⟶ 1,869:
switch (/c) is to detect inconsistent capitalizing of names such as
Ascii and ASCII or CpuReg and CPUReg.
 
=={{header|Yabasic}}==
=={{header|Zig}}==
Yabasic names are case sensitive:
In Zig identifiers are case-sensitive.
<syntaxhighlight lang="yabasic">
 
dog$ = "Benjamin"
<syntaxhighlight lang="zig">const std = @import("std");
Dog$ = "Samba"
 
DOG$ = "Bernie"
pub fn main() void {
print "The three dogs are named ", dog$, ", ", Dog$, " and ", DOG$
const dog = "Benjamin";
end</syntaxhighlight>
const Dog = "Samba";
const DOG = "Bernie";
 
std.debug.print("The three dogs are named {s}, {s}, and {s}.\n", .{ dog, Dog, DOG });
}</syntaxhighlight>
 
{{out}}
<pre>
The three dogs are named Benjamin, Samba, and Bernie.
</pre>
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">var dog = "Benjamin", Dog = "Samba", DOG = "Bernie";</syntaxhighlight>
Line 1,606 ⟶ 1,895:
L(L("DOG","Bernie"),L("Dog","Samba"),L("dog","Benjamin"))
</pre>
=={{header|ZX Spectrum Basic}}==
<syntaxhighlight lang="basic">10 LET D$="Benjamin"
20 PRINT "There is just one dog named ";d$</syntaxhighlight>
{{omit from|360 Assembly}}
{{omit from|6502 Assembly|Depends on assembler. Some have a -nocase command line argument that ignores sensitivity of labels.}}
28

edits