Idiomatically determine all the lowercase and uppercase letters: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Perl}}: look beyond just ASCII)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(9 intermediate revisions by 8 users not shown)
Line 40:
Lower case: abcdefghijklmnopqrstuvwxyz
Upper case: ABCDEFGHIJKLMNOPQRSTUVWXYZ
</pre>
 
=={{header|8080 Assembly}}==
Code assumes the CP/M operating system and the ASCII character set
<syntaxhighlight>
;------------------------------------------------------
; useful equates
;------------------------------------------------------
bdos equ 5h ; BDOS entry
wboot equ 0 ; BDOS warm boot function
conout equ 2 ; BDOS write character to console function
prtstr equ 9 ; BDOS write string to console function
cr equ 13 ; ASCII carriage return
lf equ 10 ; ASCII line feed
;------------------------------------------------------
; main code begins here
;------------------------------------------------------
org 100h ; entry point under CP/M
lxi sp,stack ; set a local stack
;
; show upper case alphabet
;
lxi d,ucmsg
call message
mvi a,'A'
ucloop: push a
call putchr
pop a
inr a
cpi 'Z'+1
jc ucloop
call crlf
;
; show lower case alphabet
;
lxi d,lcmsg
call message
mvi a,'a'
lcloop: push a
call putchr
pop a
inr a
cpi 'z'+1
jc lcloop
call crlf
;
; we're finished; exit to operating system
;
jmp wboot
;-------------------------------------------------------
; console output of $-terminated string pointed to by DE
;-------------------------------------------------------
message:
push b
push d
push h
mvi c,prtstr
call bdos
pop h
pop d
pop b
ret
;-------------------------------------------------------
; output CRLF to console
;-------------------------------------------------------
crlf: push b
push d
push h
mvi e,cr
mvi c,conout
call bdos
mvi e,lf
mvi c,conout
call bdos
pop h
pop d
pop b
ret
;-------------------------------------------------------
; console output of char in A register
;-------------------------------------------------------
putchr: push b
push d
push h
mov e,a
mvi c,conout
call bdos
pop h
pop d
pop b
ret
;------------------------------------------------------
; messages and data area
;------------------------------------------------------
ucmsg: db 'Upper case: $'
lcmsg: db 'Lower case: $'
stack equ $+128 ; 64-level stack is sufficient
;
end
</syntaxhighlight>
{{out}}
<pre>
Upper case: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Lower case: abcdefghijklmnopqrstuvwxyz
</pre>
 
Line 525 ⟶ 629:
<pre>Upper case: ABCDEFGHIJKLMNOPQRSTUVWXYZAAAAÄÅÆÇEÉEEIIIIDÑOOOOÖOUUUÜY_AAACCCCDDEEEEEGG...
Lower case: abcdefghijklmnopqrstuvwxyzµßàáâaäåæçèéêëìíîïdñòóôoöoùúûüy_ÿaaaccccddeeee...</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
for i = strcode "a" to strcode "z"
write strchar i
.
print ""
for i = strcode "A" to strcode "Z"
write strchar i
.
</syntaxhighlight>
 
 
=={{header|F_Sharp|F#}}==
Line 576 ⟶ 692:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
int i
 
for i = asc("a") to asc("z") : print chr$(i); : next
print
for i = asc("A") to asc("Z") : print chr$(i); : next
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
</pre>
 
 
=={{header|Go}}==
Line 779 ⟶ 912:
𝜹𝜺𝜻𝜼𝜽𝜾𝜿𝝀𝝁𝝂𝝃𝝄𝝅𝝆𝝇𝝈𝝉𝝊𝝋𝝌𝝍𝝎𝝐𝝑𝝒𝝓𝝔𝝕𝝰𝝱𝝲𝝳𝝴𝝵𝝶𝝷𝝸𝝹𝝺𝝻𝝼𝝽𝝾𝝿𝞀𝞁𝞂𝞃𝞄𝞅𝞆𝞇𝞈𝞊𝞋𝞌𝞍𝞎𝞏𝞪𝞫𝞬𝞭𝞮𝞯𝞰𝞱𝞲𝞳𝞴
𝞵𝞶𝞷𝞸𝞹𝞺𝞻𝞼𝞽𝞾𝞿𝟀𝟁𝟂𝟄𝟅𝟆𝟇𝟈𝟉𝟋</pre>
 
=={{Header|Insitux}}==
 
<b>Approach One</b>
 
<syntaxhighlight lang="insitux">
(let chars-between (comp range (map char-code) (... str)))
 
(str "Upper-case: " (chars-between 65 91) "
Lower-case: " (chars-between 97 123))
</syntaxhighlight>
 
<b>Approach Two</b>
 
<syntaxhighlight lang="insitux">
(let ascii (map char-code (range 127)))
 
(.. str "Upper-case: " (filter upper? ascii) "
Lower-case: " (filter lower? ascii))
</syntaxhighlight>
 
{{out}}
for both approaches
 
<pre>
Upper-case: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Lower-case: abcdefghijklmnopqrstuvwxyz
</pre>
 
=={{header|J}}==
Line 793 ⟶ 954:
<syntaxhighlight lang="j"> (#~ tolower ~: toupper) u: i.65536
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</syntaxhighlight>
 
=={{header|Jakt}}==
<syntaxhighlight lang="jakt">
fn main() {
mut lower = StringBuilder::create()
// Iteration as code points (u32)
for code_point in 'a'..('z' + 1) {
lower.append(code_point)
}
println("{}", lower.to_string())
 
mut upper = StringBuilder::create()
// Iteration as ASCII bytes (u8), same result
for b in b'A'..(b'Z' + 1) {
upper.append(b)
}
println("{}", upper.to_string())
}
</syntaxhighlight>
 
=={{header|Java}}==
Line 926 ⟶ 1,106:
<pre>abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
sublist(makelist(unicode(i),i,0,127),lowercasep);
sublist(makelist(unicode(i),i,0,127),uppercasep);
</syntaxhighlight>
{{out}}
<pre>
["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
</pre>
 
=={{header|MiniScript}}==
Line 946 ⟶ 1,137:
Nim has a <code>char</code> type whose values are contained in a single bit. The values from 0 to 127 are the ASCII characters. Strings are composed of char values but they are considered to be encoded in UTF-8. So accessing an individual character of a string may have no meaning when not working in ASCII.
 
The following program displays the lowercase and uppercase letters. Note that Nim allows to work with full Unicode, either by using strings encoded in UTF-8 (but with limited possibilities) or by using the runes of the module “unicode”. Identifiers may contain Unicode letters or digits as in “θ₁”, “â”, “x₁”, “x³”.
 
The following program displays the lowercase and uppercase ASCII letters.
 
<syntaxhighlight lang="nim">import sequtils, strutils
Line 1,230 ⟶ 1,423:
Lowercase letters: abcdefghijklmnopqrstuvwxyz
Uppercase letters: ABCDEFGHIJKLMNOPQRSTUVWXYZ
</pre>
 
=={{header|S-BASIC}}==
S-BASIC has been implemented only for computers using the Z80 CPU and the CP/M operating system and only
supports the ASCII character set. In S-BASIC, CHAR is equivalent to BYTE, and variables declared as such
may be treated in most contexts simply as small integers, avoiding the need to use conversion functions
such as ASC() and CHR$() needed in many other BASIC dialects (though S-BASIC does support them also).
<syntaxhighlight lang = "BASIC")>
var c = byte
print "Upper Case: ";
for c = 'A' to 'Z'
print c;
next c
print
print "Lower Case: ";
for c = 'a' to 'z'
print c;
next c
print
 
end
</syntaxhighlight>
{{out}}
<pre>
Upper Case: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Lower Case: abcdefghijklmnopqrstuvwxyz
</pre>
 
Line 1,261 ⟶ 1,480:
=={{header|Wren}}==
Wren doesn't have a separate character class but it is easy enough to generate the lower and upper case Latin alphabet from the raw bytes.
<syntaxhighlight lang="ecmascriptwren">for (i in 97..122) System.write(String.fromByte(i))
System.print()
for (i in 65..90) System.write(String.fromByte(i))
9,476

edits