Capitalize Lisp

Discussion of Common Lisp

Capitalize Lisp

Postby 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
samohtvii
 
Posts: 12
Joined: Thu Aug 23, 2012 11:49 pm

Re: Capitalize Lisp

Postby 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.")
User avatar
Kohath
 
Posts: 53
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia

Re: Capitalize Lisp

Postby 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
User avatar
Kompottkin
 
Posts: 94
Joined: Mon Jul 21, 2008 7:26 am
Location: München, Germany

Re: Capitalize Lisp

Postby 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
samohtvii
 
Posts: 12
Joined: Thu Aug 23, 2012 11:49 pm

Re: Capitalize Lisp

Postby 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).
User avatar
Goheeca
 
Posts: 199
Joined: Thu May 10, 2012 12:54 pm


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 1 guest

cron