1 / 15

Implementing Lists in Functional Language II Project I - PLP

This project aims to extend functional language II by implementing lists. Lists are sequences of expressions and can contain abstract and concrete values. Various operators like cons, concat, head, and tail are implemented. Comparison with other languages like Haskell is made with examples.

kacia
Download Presentation

Implementing Lists in Functional Language II Project I - PLP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Implementar Listas emLinguagem Funcional II Projeto I - PLP Prof. Augusto Sampaio Equipe : Aliny Figueirêdo Meira Ana Cristina Freitas César Danuza Ferreira Santana Neiva Mario Godoy Neto

  2. Agenda • Contexto • Projeto Proposto • Comparação com outras linguagens • BNF • Classes Implementadas • Exemplos

  3. Contexto • Linguagem Funcional • Mapeamento direto dos valores de entrada em valores de saída • Ausência de Estados • Linguagem Funcional 1 (LF1) e Linguagem Funcional 2 (LF2) • LF2 • Estende LF1 • Função passa a ser um valor • Função pode ser argumento ou resultado de uma outra expressão • Um programa é uma expressão • Não implementa Lista

  4. Projeto Proposto • Estender a linguagem funcional II • Implementar Listas • Uma lista é uma seqüência de expressões; • Listas • Funções • Expressões unárias • Expressões binárias • Outros • Listas poderão conter valores abstratos e concretos; • Listas são homogêneas

  5. Projeto Proposto • Representação de Listas: • [] -> Lista vazia • [e1,e2,...,en] - lista de n expressões • Implementação dos Operadores: • cons (e, L), adicionar o elemento “e” no início da lista “L”. • concat (L1, L2), concatena lista “L1” com a lista “L2”. • Head(L), retorna o primeiro elemento da lista “L”. • Tail(L), retorna a lista “L” sem o primeiro elemento.

  6. LF2 cons concat head tail LISP cons cat car cdr Comparação com outras Linguagens • Haskell • : • union • Tails* *Difere o conceito

  7. Exemplo Lisp cat([1,2], [3,4])= cons(1, cat([2], [3,4]))= cons(1, cons(2, cat([], [3,4])))= cons(1, cons(2, [3,4]))= cons(1, [2,3,4])= [1,2,3,4]

  8. Exemplo Haskell • Concatenação union [1,2,3] [4,5,6] = [1,2,3,4,5,6] • “:” 1:(2:(3:(4:[]))) = [1,2,3,4] • Tails tails [1,3,5] = [[1,3,5],[3,5],[5],[]]

  9. Programa ::= Expressao Expressao ::= Valor | ExpUnaria| ExpBinaria| ExpDeclaracao| Id| Aplicacao| IfThenElse Valor ::= ValorConcreto | ValorAbstrato ValorAbstrato ::= ValorFuncao ValorConcreto ::= ValorInteiro | ValorBooleano | ValorString | ValorLista ValorFuncao ::= "fn" Id LisId "." Expressão ValorLista ::= “[]” | “[” Expressão (“,” Expressão)* “]” ExpUnaria ::= "-" Expressao | "not" Expressao | "length" Expressao | “tail” Expressao | “head” Expressao ExpBinaria ::= Expressao "+" Expessao | Expressao "-" Expressao| Expressao "and" Expressao| Expressao "or" Expressao| Expressao "==" Expressao| Expressao "++" Expressao | Expressao “concat” Expressao | Expressao “cons” Expressao ExpDeclaracao ::= "let" DeclaracaoFuncional "in" Expressao DeclaracaoFuncional ::= DecVariavel | DecFuncao| DeclaracaoFuncional "," DeclaracaoFuncional DecVariavel ::= "var" Id "=" Expressao DecFuncao ::= "fun" ListId "=" Expressao ListId ::= Id  |  Id “,” ListId Aplicacao:= Expressao"(" ListExp ")" ListExp ::= Expressao  |  Expressão “,” ListExp BNF

  10. Classes Implementadas • Novas classes: • ValorListaExpConcatListaExpConsExpTailExpHead TipoListaListaVaziaException

  11. Classes Implementadas • Classes alteradas: • valorFuncao (funcional 2)Funcional2.jj (funcional 2)Tipo (expressao 1)ValorConcreto (expressao 2) Aplicacao (funcional 2) • http://www.cin.ufpe.br/~mgn

  12. Exemplos ... Exemplo 1 let fun f xy = x + y, fun g ab = a*b in [f(1,2)] concat [f(5,2), f(1,1), g(2,2)] Exemplo 2 let fun f l = (if l == [] then [] else head l concat f(tail l)) in f ([[1,2],[3,4],[5,6]])

  13. Exemplos ... • Exemplo 3 • let var z = 7, • var x = [1,2,3,4], • fun f w = 1 cons w • in f(x) • Exemplo 4 • let fun soma x = fn y . x + y in • head [soma(5), soma(6), soma(7)]

  14. Referências • WATT, David A. Programming Language Concepts and Paradigms, 2004 • Haskell reference. Disponível em: http://www.zvon.org/other/haskell/Outputsyntax/index.html. Último Acesso: 20 de junho de 2007. • Rangel, J. L.Linguagens de Programação. Disponível em: http://www-di.inf.puc-rio.br/~rangel/lp.html. Último Acesso: 21 de junho de 2007.

  15. Implementar Listas emLinguagem Funcional II Projeto I - PLP Prof. Augusto Sampaio Equipe : Aliny Figueirêdo Meira Ana Cristina Freitas César Danuza Ferreira Santana Neiva Mario Godoy Neto

More Related