Character codes: Difference between revisions

Content added Content deleted
No edit summary
Line 522:
<lang smalltalk>($a asInteger) displayNl. "output 97"
(Character value: 97) displayNl. "output a"</lang>
 
=={{header|SNOBOL4}}==
 
{{works with|Macro Spitbol}}
{{works with|Snobol4+}}
{{works with|CSnobol}}
 
Modern Snobols have built-in char( ) but not asc( ) or ord( ). Rolling either one is easy. These are based on examples in the Snobol4+ tutorial, and work with the native (1-byte) charset.
 
<lang SNOBOL4> define('chr(n)') :(chr_end)
chr &alphabet tab(n) len(1) . chr :s(return)f(freturn)
chr_end
 
define('asc(str)c') :(asc_end)
asc str len(1) . c
&alphabet break(c) @asc :s(return)f(freturn)
asc_end
 
* # Test and display
output = char(65) ;* Built-in
output = chr(65)
output = asc('A')
end</lang>
 
Output:
<pre>A
A
65</pre>
 
=={{header|Standard ML}}==