Case-sensitivity of identifiers: Difference between revisions
Content deleted Content added
Ttmrichter (talk | contribs) →{{header|Lua}}: Added a Logtalk implementation. |
Add Zig example |
||
(10 intermediate revisions by 8 users not shown) | |||
Line 187:
The three dogs are named Benjamin, Samba and Bernie.
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
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.
<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>
{{out}}
<pre>There is just one dog named Bernie.</pre>
The Apple II and Apple II plus will convert all input characters to upper case.
<pre>THERE IS JUST ONE DOG NAMED BERNIE.</pre>
==={{header|BASIC256}}===
BASIC256 is case-insensitive
<syntaxhighlight lang="basic256">dog = "Benjamin"
Line 201 ⟶ 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 216 ⟶ 388:
There is just one dog named 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 355 ⟶ 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 365 ⟶ 548:
{{out}}
<pre>The three dogs are named Benjamin, Samba and Bernie.</pre>
=={{header|D}}==
<syntaxhighlight lang="d">import std.stdio;
Line 378 ⟶ 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 426 ⟶ 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}}==
Line 446 ⟶ 655:
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
String
String
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}}==
Line 554 ⟶ 766:
Output:
<pre> There is just one dog named Bernie</pre>
=={{header|Frink}}==
Frink is case-sensitive.
Line 577 ⟶ 772:
DOG = "Bernie"
println["There are three dogs named $dog, $Dog and $DOG"]</syntaxhighlight>
Line 854 ⟶ 1,032:
<pre>3
Samba </pre>
=={{header|Logtalk}}==
Line 1,012 ⟶ 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 1,025 ⟶ 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,256 ⟶ 1,437:
</pre>
=={{header|Python}}==
Python variable names are case sensitive:
<syntaxhighlight lang="python">
Dog = 'Samba'
DOG = 'Bernie'
print(f"The three dogs are named {dog}, {Dog} and {DOG}.")</syntaxhighlight>
=={{header|Quackery}}==
<syntaxhighlight lang="quackery">[ $ 'Benjamin' ] is dog ( --> $ )
Line 1,420 ⟶ 1,598:
=={{header|RPL}}==
RPL designers recommend to use lowercase for local variables, whilst uppercase shall be used for global variables and programs.
≪ "
≪ '''IF''' DOG dog == '''THEN'''
"Just 1 dog named " DOG +
'''ELSE'''
"3 dogs: " Dog + ", " + DOG + " & " + dog +
'''END'''
≫ ≫ EVAL
{{out}}
<pre>
Line 1,455 ⟶ 1,633:
The constants are Dog, DOG.</pre>
=={{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,631 ⟶ 1,802:
Which prints...
<pre>The three dogs are named Benjamin, Samba and Bernie</pre>
=={{header|UNIX Shell}}==
<syntaxhighlight lang="sh">dog="Benjamin"
Line 1,670 ⟶ 1,833:
=={{header|Wren}}==
Identifiers in Wren are case sensitive.
<syntaxhighlight lang="
var Dog = "Samba"
var DOG = "Bernie"
Line 1,679 ⟶ 1,842:
The three dogs are named Benjamin, Samba and Bernie.
</pre>
=={{header|XBS}}==
In XBS variable names are case-sensitive.
Line 1,705 ⟶ 1,869:
switch (/c) is to detect inconsistent capitalizing of names such as
Ascii and ASCII or CpuReg and CPUReg.
=={{header|Zig}}==
In Zig identifiers are case-sensitive.
<syntaxhighlight lang="zig">const std = @import("std");
pub fn main() void {
const dog = "Benjamin";
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,720 ⟶ 1,895:
L(L("DOG","Bernie"),L("Dog","Samba"),L("dog","Benjamin"))
</pre>
{{omit from|360 Assembly}}
{{omit from|6502 Assembly|Depends on assembler. Some have a -nocase command line argument that ignores sensitivity of labels.}}
|