08.02.2015 Views

Programação Funcional e Concorrente com Scheme

Programação Funcional e Concorrente com Scheme

Programação Funcional e Concorrente com Scheme

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

notas de aula -<br />

Jerônimo C. Pellegrini<br />

(n ( matrix-cols mat )))<br />

( write n out )<br />

( display #\ space out )<br />

( write m out )<br />

( newline out )<br />

(do ((i 0 (+ 1 i )))<br />

((= i m))<br />

(do ((j 0 (+ 1 j )))<br />

((= j n))<br />

( write ( matrix-ref mat i j) out )<br />

( display #\ space out ))<br />

( newline out )))))<br />

Assim <strong>com</strong>o fizemos <strong>com</strong> listas, strings e vetores, criaremos procedimentos matrix-map<br />

e matrix-map! para aplicar um procedimento em cada elemento de uma sequência de<br />

matrizes. A implementação destes procedimentos é semelhante à de seus análogos para<br />

vetores.<br />

( define matrix-map<br />

( lambda ( proc . mats )<br />

( let (( cols ( matrix-cols ( car mats )))<br />

( rows ( matrix-rows ( car mats ))))<br />

( let (( mat-new ( make-matrix rows cols )))<br />

(do ((i 0 (+ i 1)))<br />

((= i rows ) mat-new )<br />

(do ((j 0 (+ j 1)))<br />

((= j cols ))<br />

( matrix-set ! mat-new i j<br />

( apply proc ( map ( lambda (x)<br />

( matrix-ref x i j))<br />

mats )))))))))<br />

Versão Preliminar<br />

( define matrix-map !<br />

( lambda ( proc . mats )<br />

( let (( cols ( matrix-cols ( car mats )))<br />

( rows ( matrix-rows ( car mats ))))<br />

( let (( mat-new ( car mats )))<br />

(do ((i 0 (+ i 1)))<br />

((= i rows ) mat-new )<br />

[ 27 de outubro de 2010 at 15:47 ]<br />

117

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!