[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: When does ADJUST-ARRAY cons?

William James

9/1/2015 9:39:00 PM

Edi Weitz wrote:

> (defun foo ()
> (with-open-file (strm "/tmp/test.big")
> (loop as line = (read-line strm nil nil)
> while line
> summing (length line))))

Gauche Scheme:

(define (foo)
(with-input-from-file "words"
(cut generator-fold
(^(line sum) (+ sum (string-length line)))
0
read-line)))

Another way:

(use srfi-42 :only (sum-ec))

(define (foo)
(with-input-from-file "words"
(cut sum-ec (:generator line read-line)
(string-length line))))

--
The report card by the American Society of Civil Engineers showed the national
infrastructure a single grade above failure, a step from declining to the point
where everyday things simply stop working the way people expect them to. ---
washingtonpost.com/local/trafficandcommuting/us-infrastructure-gets-d-in-annual-report/2013/03/19/c48cb010-900b-11e2-9cfd-36d6c9b5d7ad_story.html
1 Answer

William James

10/31/2015 4:33:00 PM

0

WJ wrote:

> Edi Weitz wrote:
>
> > (defun foo ()
> > (with-open-file (strm "/tmp/test.big")
> > (loop as line = (read-line strm nil nil)
> > while line
> > summing (length line))))
>
> Gauche Scheme:
>
> (define (foo)
> (with-input-from-file "words"
> (cut generator-fold
> (^(line sum) (+ sum (string-length line)))
> 0
> read-line)))
>
> Another way:
>
> (use srfi-42 :only (sum-ec))
>
> (define (foo)
> (with-input-from-file "words"
> (cut sum-ec (:generator line read-line)
> (string-length line))))

MatzLisp (Ruby):

IO.foreach('words').reduce(0){|sum,line| sum + line.strip.size}
==>595785

--
In Sweden, the leadership seems to show Europe's most extensive cultural
self-denial, or rather -- a deeply felt self-loathing, which many feel is the
perfect recipe for driving a peaceful nation to destruction.
fjordman.blogspot.ca/2005/05/is-swedish-democracy-collapsing.html