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 - Jerônimo C. Pellegrini<br />

( for-each do-it lst )))<br />

Precisaremos de um procedimento count-nonempty-sublists para contabilizar a<br />

quantidade de sublistas não vazias em uma lista.<br />

( define count-nonempty-sublists<br />

( lambda ( lst )<br />

(if ( null lst )<br />

0<br />

( let (( rest ( count-nonempty-sublists ( cdr lst )))<br />

( head (+ 1 (if ( list ( car lst ))<br />

(+ head rest )))))<br />

( count-nonempty-sublists ( car lst ))<br />

0))))<br />

Os operadores de mutação e cross-over escolherão um ponto aleatóreo na forma para<br />

fazer modificações. O procedimento nth-nonempty-sublist encontra este ponto, que é a<br />

n-ésima sublista não vazia.<br />

( define nth-nonempty-sublist<br />

( lambda ( the-list n)<br />

( let loop (( lst the-list )<br />

(n 0)<br />

( wanted n))<br />

( cond (( null lst )<br />

n)<br />

((> n wanted )<br />

’OVER )<br />

((= n wanted )<br />

lst )<br />

( else<br />

( let (( head (if ( list ( car lst ))<br />

( loop ( car lst ) (+ n 1) wanted )<br />

(+ n 1))))<br />

( cond (( symbol head )<br />

’OVER )<br />

(( list head )<br />

head )<br />

( else<br />

( loop ( cdr lst ) head wanted )))))))))<br />

Versão Preliminar<br />

144<br />

[ 27 de outubro de 2010 at 15:47 ]

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

Saved successfully!

Ooh no, something went wrong!