Im learning Common Lisp and writing a simple password generator as an intro project.
Here is my code:
(setq chars
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
(print (nth (random (length chars)) chars))
But using CLISP I just get
*** - NTH: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" is not a list
I thought every string in Lisp was a list? How can I "cast" the string to a list?
NTH works only for lists. Strings are not lists, but vectors of characters.
Here is the dictionary for strings. CHAR is an accessor for strings.
CL-USER 7 > (char "abc" 1)
#\b
Since strings are also sequences, all sequence operations apply. See: Sequence dictionary.
CL-USER 8 > (elt "abc" 1)
#\b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With