Lisp (LISt Processing) is a very old language (1958).
; for line commenting
script extension is .lisp
CLisp is common lisp.
terpri function outputs a newline to output-stream. (TERminate PRInt line)
...........................................
String printing
(write-line "Autumn leaves make me happy")
(write-line "I love picking them.")
(write-line "His authored a book titled \"Eternal peace.\"")
Case-sensitive comparison
(write (string= "hi" "Hi"))
(terpri)
(write (string> "hi" "Hi"))
(terpri)
String case conversion
(write-line (string-upcase "winter is almost here."))
(write-line (string-capitalize "sun sets very early."))
(write-line (string-downcase "PLUMERIA FLOWER IS VERY FRAGRANT."))
(write-line (string-capitalize "seaweeds are algae."))
Stripping the spaces
(write-line (string-trim " Its a cold night "))
(write-line (string-left-trim " Owls are hooting."))
(write-line (string-right-trim "Bats are flying "))
(write-line (string-trim " "I" I an scared."))
---------------------
Finding length of string
(write (length "Chaparral flora"))
(terpri)
; pull all characters except the number 1 character
(write-line (subseq "Chaparral" 1))
; pull the character only at index 1
(write (char "Chaparral" 1))
Sorting the strings (ascending, descending order)
(write (sort (vector "milk" "egg" "fruits" "vegetables") #'string<))
(terpri)
(write (sort (vector "milk" "egg" "fruits" "vegetables") #'string<))
(terpri)
#("egg" "fruits" "milk" "vegetables")
#("vegetables" "milk" "fruits" "egg")
---------------------
Joining strings (order of strings vary based on < or > symbol used).
(write(merge'vector(vector "tulip" "hibiscus")(vector "rose" "jasmine")#'string<))
(terpri)
(write(merge'vector(vector "tulip" "hibiscus")(vector "rose" "jasmine")#'string>))
Reversing a string
(write-line (reverse "Calley pear blooms are spectacular."))
Joining strings
(write-line (concatenate 'string "I like hiking." "Nature fascinates me."))
---------------------
; for line commenting
script extension is .lisp
CLisp is common lisp.
terpri function outputs a newline to output-stream. (TERminate PRInt line)
...........................................
String printing
(write-line "Autumn leaves make me happy")
(write-line "I love picking them.")
(write-line "His authored a book titled \"Eternal peace.\"")
Autumn leaves make me happy
I love picking them
His authored a book titled "Eternal peace."
---------------------Case-sensitive comparison
(write (string= "hi" "Hi"))
(terpri)
(write (string> "hi" "Hi"))
(terpri)
NIL
0
---------------------String case conversion
(write-line (string-upcase "winter is almost here."))
(write-line (string-capitalize "sun sets very early."))
WINTER IS ALMOST HERE.
Sun Sets Very Early.
(write-line (string-downcase "PLUMERIA FLOWER IS VERY FRAGRANT."))
(write-line (string-capitalize "seaweeds are algae."))
plumeria flower is very fragrant.
Seaweeds Are Algae.
---------------------Stripping the spaces
(write-line (string-trim " Its a cold night "))
(write-line (string-left-trim " Owls are hooting."))
(write-line (string-right-trim "Bats are flying "))
(write-line (string-trim " "I" I an scared."))
---------------------
Finding length of string
(write (length "Chaparral flora"))
(terpri)
; pull all characters except the number 1 character
(write-line (subseq "Chaparral" 1))
; pull the character only at index 1
(write (char "Chaparral" 1))
15
haparral
#\h
---------------------Sorting the strings (ascending, descending order)
(write (sort (vector "milk" "egg" "fruits" "vegetables") #'string<))
(terpri)
(write (sort (vector "milk" "egg" "fruits" "vegetables") #'string<))
(terpri)
#("egg" "fruits" "milk" "vegetables")
#("vegetables" "milk" "fruits" "egg")
---------------------
Joining strings (order of strings vary based on < or > symbol used).
(write(merge'vector(vector "tulip" "hibiscus")(vector "rose" "jasmine")#'string<))
(terpri)
(write(merge'vector(vector "tulip" "hibiscus")(vector "rose" "jasmine")#'string>))
#("rose" "jasmine" "tulip" "hibiscus")
#("tulip" "rose" "jasmine" "hibiscus")
---------------------Reversing a string
(write-line (reverse "Calley pear blooms are spectacular."))
Joining strings
(write-line (concatenate 'string "I like hiking." "Nature fascinates me."))
---------------------
No comments:
Post a Comment