How to resolve the algorithm Generate lower case ASCII alphabet step by step in the Common Lisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Generate lower case ASCII alphabet step by step in the Common Lisp programming language

Table of Contents

Problem Statement

Generate an array, list, lazy sequence, or even an indexable string of all the lower case ASCII characters, from a to z. If the standard library contains such a sequence, show how to access it, but don't fail to show how to generate a similar sequence. For this basic task use a reliable style of coding, a style fit for a very large program, and use strong typing if available. It's bug prone to enumerate all the lowercase characters manually in the code. During code review it's not immediate obvious to spot the bug in a Tcl line like this contained in a page of code:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Generate lower case ASCII alphabet step by step in the Common Lisp programming language

Source code in the common programming language

(defvar *lower*
  (loop with a = (char-code #\a)
        for i below 26
        collect (code-char (+ a i))))


(defvar *lowercase-alphabet-string*
  (map 'string #'code-char (loop
			      for c from (char-code #\a) to (char-code #\z)
			      collect c))
  "The 26 lower case letters in alphabetical order.")


(assert (= 26 (length *lowercase-alphabet-string*) (length *lower*)))
(assert (every #'char< *lowercase-alphabet-string* (subseq *lowercase-alphabet-string* 1)))
(assert (apply #'char< *lower*))
(assert (string= *lowercase-alphabet-string* (coerce *lower* 'string)))


  

You may also check:How to resolve the algorithm Anti-primes step by step in the 11l programming language
You may also check:How to resolve the algorithm Date format step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Roots of unity step by step in the Scala programming language
You may also check:How to resolve the algorithm Sorting algorithms/Radix sort step by step in the Rust programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the COBOL programming language