1 / 13

5COP101 Linguagens de Programação

Aula 2 Clojure/LISP Prof. Dr. Sylvio Barbon Junior. 5COP101 Linguagens de Programação. Sylvio Barbon Jr – barbon@uel.br. 1. Sumário. 1) Razões para Estudar Clojure; 2) Obtendo a Clojure; 3) REPL; 4) Iniciando com a Clojure;. Sylvio Barbon Jr – barbon@uel.br. 2.

Download Presentation

5COP101 Linguagens de Programação

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. Aula 2 Clojure/LISP Prof. Dr. Sylvio Barbon Junior 5COP101 Linguagens deProgramação Sylvio Barbon Jr – barbon@uel.br 1

  2. Sumário 1) Razões para Estudar Clojure; 2) Obtendo a Clojure; 3) REPL; 4) Iniciando com a Clojure; Sylvio Barbon Jr – barbon@uel.br 2

  3. Razões para Estudar Clojure - A Clojure utiliza os recursos da JVM (Swing, SWT, “reliability”); - É um dos dialetos mais populares do LISP; - Foco em programação funcional em ambientes de desenvolvimento corporativo; - A Clojure oferece soluções de ambiente concorrentes e paralelização; - “Mistura” de Ruby + Python + Java + LISP Sylvio Barbon Jr – barbon@uel.br 3

  4. Obtendo a Clojure 1) Java Runtime 2) clojure-1.4.0.jar 3) IDE: Leiningen ou Eclipse * Versão atual é a 1.6 Sylvio Barbon Jr – barbon@uel.br 4

  5. REPL - Ambiente de híbrido de implementação e execução; - R: Read (código lido como entrada) - E: Eval (avaliação do código) - P: Print (saída da interpretação é escrita) - L: Loop (controles para retornar ao passo “read”) Sylvio Barbon Jr – barbon@uel.br 5

  6. Iniciando com a Clojure % java -cp clojure-1.4.0.jar clojure.main Clojure 1.4.0 user=> public static double average (double[] numbers) { double sum = 0; for (int i = 0; i < numbers.length; i++) { sum += numbers[i]; } return sum / numbers.length; } (defn average [numbers] (/ (apply + numbers) (count numbers)) (defn average [numbers] (/ (apply + numbers) (count numbers))) Sylvio Barbon Jr – barbon@uel.br 6

  7. Iniciando com a Clojure (average [60 80 100 400]) ;= 160 (println (average [60 80 100 400])) ; 160 ;= nil Sylvio Barbon Jr – barbon@uel.br 7

  8. Iniciando com a Clojure Sylvio Barbon Jr – barbon@uel.br 8

  9. Iniciando com a Clojure - Scalar Literals: • String: • Booleans: true/false • nil: null (Java) • Characters: • Keywords: "hello there" ;= "hello there" \o41 ;= \! (def person {:name "Sandra Cruz" :city "Portland, ME"}) ;= #'user/person (:city person) ;= "Portland, ME" Sylvio Barbon Jr – barbon@uel.br 9

  10. Iniciando com a Clojure - Scalar Literals: • Symbols: • Numbers: • Expressão Regular: (average [60 80 100 400]) ;= 160 (re-seq #"(\d+)-(\d+)" "1-3") ;= (["1-3" "1" "3"]) Sylvio Barbon Jr – barbon@uel.br 10

  11. Iniciando com a Clojure - Scalar Literals: • Comentário: “;” ou “#_(xxxxx)” • Espaço e vírgula: mesma função separar itens. (= [1 2 3] [1, 2, 3]) ;= true Sylvio Barbon Jr – barbon@uel.br 11

  12. Iniciando com a Clojure // Java public void hello(String name) { System.out.println("Hello, " + name); } ; Clojure (defn hello [name] (println "Hello," name)) Sylvio Barbon Jr – barbon@uel.br 12

  13. 1- Sebesta, R. Conceitos de Linguagens de Programação. 5ª Edição. Porto Alegre. Bookman, 2003. 2 – Chas Emerick, Brian Carper, Christophe Gand, Clojure Programming., O'really, 2012. Referências

More Related