lambdaway
::
ASCII
6
|
list
|
login
|
load
|
|
_h1 ASCII _ul [[http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet| http://rosettacode.org/wiki/Generate_lower_case_ASCII_alphabet]] _ul [[https://rosettacode.org/wiki/Show_ASCII_table|https://rosettacode.org/wiki/Show_ASCII_table]] _p Task: Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. _p We need two functions to translate any character to its ASCII code and reverse but currently no {code code2char & char2code} are defined as primitives. So: _ul 1) let's add them to the dictionary: {pre '{script LAMBDATALK.DICT["char2code"] = function() { var args = arguments[0].trim(); return args.charCodeAt(0); }; LAMBDATALK.DICT["code2char"] = function() { var args = arguments[0].trim(); return String.fromCharCode(args); }; } } _ul 2) and let's use them: {pre '{S.map code2char {S.serie {char2code a} {char2code z}}} -> {S.map code2char {S.serie {char2code a} {char2code z}}} '{S.map code2char {S.serie {char2code 0} {char2code 9}}} -> {S.map code2char {S.serie {char2code 0} {char2code 9}}} } _h2 table {pre '{def format {lambda {:i :c} {if {< :i 100} then {span {@ style="color:white;"}.}:i : :c else :i : :c}}} -> {def format {lambda {:i :c} {if {< :i 100} then {span {@ style="color:white;"}.}:i : :c else :i : :c}}} '{S.map {lambda {:i} {div} {S.map {lambda {:i} {if {= :i 32} then {format :i {span {@ style="color:#fff;"}.}} else {if {= :i 123} then {format :i left brace} else {if {= :i 125} then {format :i right brace} else {if {= :i 127} then {format :i del} else {format :i {code2char :i}}}}}}} {S.serie {+ 32 :i} 127 16}}} {S.serie 0 15}} {S.map {lambda {:i} {div} {S.map {lambda {:i} {if {= :i 32} then {format :i {span {@ style="color:#fff;"}.}} else {if {= :i 123} then {format :i left brace} else {if {= :i 125} then {format :i right brace} else {if {= :i 127} then {format :i del} else {format :i {code2char :i}}}}}}} {S.serie {+ 32 :i} 127 16}}} {S.serie 0 15}} } {script LAMBDATALK.DICT["char2code"] = function() { var args = arguments[0].trim(); return args.charCodeAt(0); }; LAMBDATALK.DICT["code2char"] = function() { var args = arguments[0].trim(); return String.fromCharCode(args); }; }
lambdaway v.20211111