[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: list formats

William James

6/13/2015 1:52:00 PM

Barry Margolin wrote:

> >I think the way I posed the question was too complicated in latter
> >postings (under the name loop problem) so I try to samplify it:
> >
> >we have this list:
> >
> >(("car ((noun automoblie sks hui)(noun vehicle sks hui)) is ((verb hji
> >ska) (noun ako hui)) blue ((adj hji hui))" "strong ((adj hji hui) (adv
> >ly hui)) is ((verb hji ska) (verb kos hji)) man ((noun ako hui) (prop
> >hui))"))
> >
> >
> >and want to convert it to this format:
> >
> >(("car" ((noun automoblie sks hui)(noun vehicle sks hui))
> > "is" ((verb hji ska) (noun ako hui))
> > "blue" ((adj hji hui)))
> > ("strong" ((adj hji hui) (adv ly hui))
> > "is" ((verb hji ska) (verb kos hji))
> > "man" ((noun ako hui) (prop hui))))
>
> Here's my solution. It's untested and doesn't do any error checking.
>
> (defun parse-my-list (list)
> (loop for string in (car list)
> collect (parse-my-string string)))

Why didn't he say

(mapcar #'parse-my-string (car list))

It seems that he has no affinity whatsoever for Lispy
programming. Worshippers of LOOP never do.


>
> (defun parse-my-string (string)
> "Parse a string of repeating "<name> <list-of-attributes> ..."

A quote within quotes.


> (loop with end = (length string)
> with last-end
> for start = 0 then last-end
> while (start < end)

Infix?

Worshippers of LOOP have no affinity whatsoever for Lispy
programming.


> collect (let* ((space-pos (position #\space string :start start))
> (word (subseq string start space-pos)))
> (setq start (1+ space-pos))
> word)
> collect (multiple-value-bind (list end-pos)
> (read-from-string string t nil :start start)
> ;; skip over whitespace after the list
> (setq last-end
> (position #\space string :start end-pos :test #'char/=))
> list)))

There are two ways of constructing a software design: One way is
to make it so simple that there are obviously no deficiencies,
and the other way is to make it so complicated that there are no
obvious deficiencies. --- Charles Antony Richard Hoare

Common Lisp is a significantly ugly language. --- Dick Gabriel

The good news is, it's not Lisp that sucks, but Common Lisp.
--- Paul Graham


Gauche Scheme:

(define sentences
'(("car ((noun automoblie sks hui)(noun vehicle sks hui))
is ((verb hji ska) (noun ako hui))
blue ((adj hji hui))"
"strong ((adj hji hui) (adv ly hui))
is ((verb hji ska) (verb kos hji))
man ((noun ako hui) (prop hui))")))

(define (parse-sentence input)
(with-input-from-string input
(lambda ()
(generator-map
(lambda (x) (if (list? x) x (symbol->string x)))
read))))

(define (parse-list input)
(map parse-sentence (car input)))


(parse-list sentences)
===>
(("car" ((noun automoblie sks hui) (noun vehicle sks hui))
"is" ((verb hji ska) (noun ako hui))
"blue" ((adj hji hui)))
("strong" ((adj hji hui) (adv ly hui))
"is" ((verb hji ska) (verb kos hji))
"man" ((noun ako hui) (prop hui))))

--
Africans gang-rape and clitorectomize Finnish girl; government arrests Finn
whom they accuse of complaining:
conservative-headlines.com/2009/03/another-european-awaits-extradition-for-hate-speech
1 Answer

tristan

6/15/2015 7:38:00 PM

0