[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: [LISP Beginner] Recursion Problem

William James

6/7/2015 7:17:00 AM

M. Pitman wrote:

> Erik Naggum <erik@naggum.net> writes:
>
> > (defun get-elements (sequence)
> > (loop
> > for start = 0 then (1+ end)
> > for end = (position #\Space sequence :start start)
> > collect (subseq sequence start end)
> > until (not end)))
>
> Or
>
> (defun get-elements (sequence)
> (loop with len = (length sequence)
> for start = 0 then (1+ end)
> for end = (position #\Space sequence :start start)
> unless (eql start (or end len))
> collect (subseq sequence start end)
> until (not end)))
>
> which is more tolerant of strings like " foo bar baz ".

Gauche Scheme:

(use srfi-13 :only (string-tokenize))

(define (get-elements text)
(string-tokenize text #[\S]))

(get-elements " foo bar baz ")
===>
("foo" "bar" "baz")

--
The urge to save humanity is almost always only a false face for
the urge to rule it. --- H. L. Mencken
1 Answer

William James

11/28/2015 6:41:00 AM

0

WJ wrote:

> M. Pitman wrote:
>
> > Erik Naggum <erik@naggum.net> writes:
> >
> > > (defun get-elements (sequence)
> > > (loop
> > > for start = 0 then (1+ end)
> > > for end = (position #\Space sequence :start start)
> > > collect (subseq sequence start end)
> > > until (not end)))
> >
> > Or
> >
> > (defun get-elements (sequence)
> > (loop with len = (length sequence)
> > for start = 0 then (1+ end)
> > for end = (position #\Space sequence :start start)
> > unless (eql start (or end len))
> > collect (subseq sequence start end)
> > until (not end)))
> >
> > which is more tolerant of strings like " foo bar baz ".

Ocaml:

#load "str.cma";;
Str.split (Str.regexp " +") " foo bar baz ";;
===>
["foo"; "bar"; "baz"]

--
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