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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

notas de aula -<br />

Jerônimo C. Pellegrini<br />

( define-syntax when<br />

( syntax-rules ()<br />

((_ test body ...)<br />

(if test<br />

( begin body ...)))))<br />

A macro unless é semelhante a when, a não ser pela negação do teste.<br />

( define-syntax unless<br />

( syntax-rules ()<br />

((_ test body ...)<br />

(if ( not test )<br />

( begin body ...)))))<br />

A macro while é também muito simples:<br />

( define-syntax while<br />

( syntax-rules ()<br />

((_ test body ...)<br />

( let loop ()<br />

(if test<br />

( begin body ...<br />

( loop )))))))<br />

7.3.5 Exemplo: framework para testes unitários<br />

7.3.6 Sintaxe local<br />

Versão Preliminar<br />

Definições de macro (válidas para todo o programa) são feitas <strong>com</strong> define-syntax.<br />

Definições locais de macro podem ser feitas <strong>com</strong> let-syntax e letrec-syntax, que<br />

funcionam exatamente <strong>com</strong>o define-syntax, exceto por definirem macros visíveis apenas<br />

no escopo onde estiverem.<br />

No próximo exemplo, a macro vezes é introduzida apenas para uso em um procedimento<br />

(e não poderá ser usada fora dele):<br />

( define linha<br />

( lambda (n)<br />

( let-syntax (( vezes<br />

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

177

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

Saved successfully!

Ooh no, something went wrong!