Capitalize Lisp

Discussion of Common Lisp
Post Reply
samohtvii
Posts: 12
Joined: Thu Aug 23, 2012 11:49 pm

Capitalize Lisp

Post by samohtvii » Thu Sep 20, 2012 10:08 pm

Is there any function to automatically make a string uppercase or lowercase or to capitalize the first letter?
I'm also looking to take a string and 'inspect' the first character so with : "example" i would want to get e as a variable.

THanks

Kohath
Posts: 61
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia
Contact:

Re: Capitalize Lisp

Post by Kohath » Thu Sep 20, 2012 10:27 pm

The closest *function* would probably be string-capitalize.

For just the behaviour, try format's case conversion:

Code: Select all

(format nil "~@(~A~)" "this is a senTENce.")

Kompottkin
Posts: 94
Joined: Mon Jul 21, 2008 7:26 am
Location: München, Germany
Contact:

Re: Capitalize Lisp

Post by Kompottkin » Thu Sep 20, 2012 11:38 pm

samohtvii wrote:I'm also looking to take a string and 'inspect' the first character so with : "example" i would want to get e as a variable.

Code: Select all

CL-USER> (char "example" 0)
#\e

samohtvii
Posts: 12
Joined: Thu Aug 23, 2012 11:49 pm

Re: Capitalize Lisp

Post by samohtvii » Sat Sep 22, 2012 9:32 pm

Thanks guys. Both really helpful. One last question. What is the easiest way to check if the letter i extracted is a vowel.
instead of writing a lot of if statements is there a way to check all vowels at one?
Thanks

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: Capitalize Lisp

Post by Goheeca » Sun Sep 23, 2012 12:44 am

I've found this document and in it is a function:

Code: Select all

(defun vowel-p (char) (find char "aeiou" :test #'char-equal))
I don't know if it is sufficient because vowels exist much more than only english vowels.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Post Reply