ASCII Lookup Utility in Ada
7 comments
·April 12, 2025kqr
> A full-scale Unicode lookup utility would be great, but I haven't found one, or even looked very hard for one.
Emacs! There's probably a quicker way but interactive insert-char takes codepoint numbers and then describe-char gets all sorts of useful information.
kazinator
TXR Lisp program:
(defvarl ch-name (relate (rlist 0..32 127)
'#"NUL SOH STX ETX EOT ENQ ACK BEL BS \
HT LF VT FF CR SO SI DLE DC1 DC2 DC3 \
DC4 NAK SYN ETB CAN EM SUB ESC FS GS \
RS US SPC DEL"
nil))
(defun print-row (ch)
(format t "~,3d ~,02x ~,07b ~,03o ~a\n"
ch ch ch ch (or [ch-name ch] (chr-num ch))))
(match-case *args*
(@(require @(or @(with (`0x@{dig #/[\dA-Fa-f]+/}`) base 16)
@(with (`0b@{dig #/[01]+/}`) base 2)
@(with (`0o@{dig #/[0-7]+/}`) base 8)
@(with (`@{dig #/\d+/}`) base 10))
(let ((val (toint dig base)))
(if (<= 0 val 127)
(print-row val)))))
(() [mapdo print-row 0..128])
(@else (put-line "error in argument") (exit nil)))
kazinator
No need to use a word list literal in definition of ch-name; symbols will do:
(defvarl ch-name (relate (rlist 0..32 127)
'(NUL SOH STX ETX EOT ENQ ACK BEL BS
HT LF VT FF CR SO SI DLE DC1 DC2 DC3
DC4 NAK SYN ETB CAN EM SUB ESC FS GS
RS US SPC DEL)
nil))
Mountain_Skies
Happy to see Ada still gets some interest outside of MIC. When I went off to university, I was a Perl snob but my school used Ada as its primary teaching language. It was a great way of expanding my knowledge across the horizon to understand the value in strong typing.
After nearly half a century, I still don't have ASCII memorized either but usually just use asciitable.com to do a quick lookup. Having a system utility like this one would be handy in situation without internet access. Plus like he noted, it was a good way to learn more about Ada.
bmn__
Obligatory Perl snobbery: Perl wins the day by being shorter and better output and already installed on your computer.
perl -C -M5.032 -MUnicode::UCD=charprop -e \
'# https://www.unicode.org/Public/MAPPINGS/VENDORS/MISC/IBMGRAPH.TXT
my @cp437 = qw(
0 263a 263b 2665 2666 2663 2660 2022 25d8 25cb 25d9 2642 2640 266a 266b 263c
25ba 25c4 2195 203c b6 a7 25ac 21a8 2191 2193 2192 2190 221f 2194 25b2 25bc
);
printf "%3u %02x %07b %3o %s %s %s\n",
($_) x 4,
$_ == 127 ? chr(0x2421) : $_ <= 32 ? chr(0x2400+$_) : chr,
$_ == 127 ? chr(0x2302) : 0 < $_ < 32 ? chr hex $cp437[$_] : chr,
charprop($_, "Name") || charprop($_, "NameAlias") =~ s/: \w+//gr
for @ARGV ? oct $ARGV[0] : 0..127'
ayastrebov2
man ascii
Standard ML program. I fear it does not contribute much to the conversation but I cannot abstain from calling attention to my favourite pragmatic programming language that is presently on what seems to be a neverending life support.