[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

Re: Lisp benefits against other functional programming languages

William James

8/16/2015 6:36:00 AM

Pascal Bourguignon wrote:

> CL-USER> (make-array (list 8 12) :element-type 'bit :initial-element 0)
> #2A(#*000000000000
> #*000000000000
> #*000000000000
> #*000000000000
> #*000000000000
> #*000000000000
> #*000000000000
> #*000000000000)
>
> CL-USER> (defparameter b1 (make-array (list 8 12)
> :element-type 'bit :initial-element 0))
> B1
> CL-USER> (defparameter b2 (make-array (list 8 12)
> :element-type 'bit :initial-element 0))
> B2
> CL-USER> (loop for i from 0 below 8 do
> (loop for j from 0 below i do
> (setf (aref b1 i j) 1 (aref b2 i (- 11 j)) 1)))
> NIL
> CL-USER> b1
> #2A(#*000000000000
> #*100000000000
> #*110000000000
> #*111000000000
> #*111100000000
> #*111110000000
> #*111111000000
> #*111111100000)
> CL-USER> b2
> #2A(#*000000000000
> #*000000000001
> #*000000000011
> #*000000000111
> #*000000001111
> #*000000011111
> #*000000111111
> #*000001111111)
> CL-USER> (bit-ior b1 b2)
> #2A(#*000000000000
> #*100000000001
> #*110000000011
> #*111000000111
> #*111100001111
> #*111110011111
> #*111111111111
> #*111111111111)

Gauche Scheme:

(define b1 (make-vector 8 0))
(define b2 (make-vector 8 0))
(dotimes (i 7)
(vector-set! b2 (+ 1 i) (copy-bit-field 0 -1 0 (+ 1 i)))
(vector-set! b1 (+ 1 i) (copy-bit-field 0 -1 (- 11 i) 12)))

(define (show vector)
(vector-for-each (pa$ format #t "~12,'0B\n") vector))

(show b1)

000000000000
100000000000
110000000000
111000000000
111100000000
111110000000
111111000000
111111100000

(show b2)

000000000000
000000000001
000000000011
000000000111
000000001111
000000011111
000000111111
000001111111

(show (vector-map logior b1 b2))

000000000000
100000000001
110000000011
111000000111
111100001111
111110011111
111111111111
111111111111

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