[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Strings and lists

William James

5/21/2015 8:46:00 AM

Steve Gonedes wrote:

> Using loop, it could look like the following.
>
> (defun first-word (str)
> (or (loop for ch across str as idx upfrom 0
> when (char= ch #\Space)
> return (subseq str 0 idx))
> str))

Gauche Scheme:

The hard way:

(use srfi-42 :only (string-ec))
(string-ec (:while (: c "foo bar") (not (eq? c #\space))) c)
===>
"foo"

The easy way:

(car (string-split "foo bar" #\space))
===>
"foo"

Another way:

(use srfi-13 :only (string-tokenize))
(car (string-tokenize " foo bar"))
===>
"foo"

--
From the New York Times of October 11, 1991, page 15, we learn that ... a
committee of researchers at Boston University admitted that, "There is no
question but that Dr. King plagiarized in the dissertation." -- K.A. Strom
[Jesse Jackson] would spit into the food of white patrons he hated and then
smilingly serve it to them. He did this, he said, "because it gave me
psychological gratification." -- Life Magazine, 1969-11-29
1 Answer

William James

3/27/2016 5:46:00 AM

0

WJ wrote:

> Steve Gonedes wrote:
>
> > Using loop, it could look like the following.
> >
> > (defun first-word (str)
> > (or (loop for ch across str as idx upfrom 0
> > when (char= ch #\Space)
> > return (subseq str 0 idx))
> > str))
>
> Gauche Scheme:
>
> The hard way:
>
> (use srfi-42 :only (string-ec))
> (string-ec (:while (: c "foo bar") (not (eq? c #\space))) c)
> ===>
> "foo"
>
> The easy way:
>
> (car (string-split "foo bar" #\space))
> ===>
> "foo"
>
> Another way:
>
> (use srfi-13 :only (string-tokenize))
> (car (string-tokenize " foo bar"))
> ===>
> "foo"

OCaml:

#load "str.cma" ;;
Str.split (Str.regexp "[ \t]+") "CL isn't well-equipped." ;;

===>
["CL"; "isn't"; "well-equipped."]

--
The struggle of our time is to concentrate, not to dissipate: to renew our
association with traditional wisdom: to re-establish a vital connection between
the individual and the race. It is, in a word, a struggle against Liberalism.
--- T. S. Elliot