[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: Beginner - Function Critique

William James

9/4/2015 9:43:00 AM

Pascal Bourguignon wrote:

> You could try to write a recursive function that is tail-recursive, to
> give a chance to a TCO implementation. Note that not all CL
> implementations do TCO, so you still may want to write an iterative solution.


Note that although CL (COBOL-Like) sometimes pretends to be a
Lispy language, it has very poor support for recursion.

As a rule, worshippers of CL have nothing but contempt for
Lispy programming and for McCarthy, the inventor of Lisp.


>
>
> > (defun read-file (filename delimiter)
> > "Return a list of lists containing strings in pathname FILENAME
> > delimited by character DELIMITER."
> > (let ((output '()))
> > (with-open-file (in filename)
> > (do ((line (read-line in nil) (read-line in nil)))
> > ((null line))
> > (push (line-split line delimiter) output))
> > (nreverse output))))
>
>
> Good. Eventually, I switched to loop:
>
> (defun read-file (filename delimiter)
> "Return a list of lists containing strings in pathname FILENAME
> delimited by character DELIMITER."
> (with-open-file (in filename)
> (loop
> :for line = (read-line in nil)
> :while line
> :collect (line-split line delimiter))))

Note that there is no "line-split" in CL (COBOL-Like).

Gauche Scheme:

(define (read-file filename delimiter)
(with-input-from-file filename
(cut generator-map
(cut string-split <> delimiter)
read-line)))

--
Empires do not create nations. Empires corrupt, degenerate, and pervert
nations. All empires end their days ethnically hollow. The worst enemy of any
empire is its own citizens challenging the power of the imperial elite.
Therefore, a dying empire and its fearful elite is always willing to resort to
massive violence against the citizens of the empire in order to turn them into
slaves. www.kolumbus.fi/aquilon/america-middle-class-and-the-end-of-growth.htm