1 / 26

Simple Introduction to Clojure with Analysis By: Shannon Birchell

Simple Introduction to Clojure with Analysis By: Shannon Birchell. Foundation. First Class Functions Inherits concepts from Lisp Every expression is a function Functions attempt to be pure (not possible) Concurrency is very stable Software Transaction Memory(STM) Uses JVM Hybrid

chibale
Download Presentation

Simple Introduction to Clojure with Analysis By: Shannon Birchell

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. Simple Introduction to Clojure with Analysis By: Shannon Birchell

  2. Foundation • First Class Functions • Inherits concepts from Lisp • Every expression is a function • Functions attempt to be pure (not possible) • Concurrency is very stable • Software Transaction Memory(STM) • Uses JVM • Hybrid • Dynamically run code • REPL • Inherits all Java classes (4k+)

  3. Types • Primitives Not so interesting: Number, String, Boolean and char • Coercion takes place on the JVM in byte code • Interesting Lisp primitives • List: Linked List without element removal capacities • Vector: like linked list but more efficient (less capabilities) • Keyword: used for Map as key • Map: equivalent to Hashmap • Set: same as mathematics

  4. Variables • Dynamic type binding • Variable Scope • Stack Dynamic • Explicitly stated global scopes • Value bindings are immutable • Values cannot be changed • Mapping areused to transform variables • Enhanced stability and reliability

  5. Functions • Function Declaration • Anonymous function (fn [<parameters>]( <element> <element> … )) • Explicit function (defn <name> [<parameters>] ( <element> <element…)) • Functions can be self documented using • Function closure • A function and all its current values can be stored as a variable. It is said, “The function is closed over”

  6. Function Cont. • Some functions • String: (str“hello” “world”) -> hello world • (cons 4 ‘(1 2 3)) -> 1 2 3 4 • (first ‘(1 3 5)) ->1 • (doc someFunct) -> description • First class functions • Parameters can be functions (* (+ 1 1) (+ 1 1)) = (* 2 (+ 1 1))=(* 2 2)=4 • Return values can be functions • (defn f1 [p1] (fn [p2] ( str p1 p2)))

  7. Java integration • Java integration • (javax.swing.JOptionPane/showMessageDialog nil (str "Hello Everyone")) • Is equivalent to java code: javax.swing.JOptionPane.showMessageDialog(null, "Hello Everyone“); • Dot operator “.” performs java functinality (. String split “,”) -> String.split(“,”); • Most java objects do not work in the dynamic environment

  8. Demonstration

  9. Characteristics • Readability • Orthogonal structures. (. String contains “hi”) -> String.contains(“hi”); • iteration is done through recursion and is cryptic • Writeability • Highly nested structures require substantial forethought (if(< (+ 1 1) (3/4) “write”)) • Highly nested structures unify code into cohesive chunk. • Cost • Different than main stream – learning curve • Free software with good libraries

  10. Overview and analysis of R By Shannon Birchell

  11. Foundation • Domain specific • Statistical and numerical analysis • Used as a scripting language • Run commands real time in R environment • R Based on S syntax • Created by Bell Laboratories in 1976 • Alternative to Fortran • Static scoped • Imperative language • Class Oriented • Like OO but uses predefined classes

  12. Variables • Primitives • Vectors logical, integer, double, complex, character, or raw • Coercion is used for different vectors of different size <1,2> + <1,3,5,7> = <1+1,2+3,1+5,2+7> Logical Error checking reduced!!! • Type coercion is character, integer, double, logic • Implicit type binding • Lists • Behave like a vector without enforcing a type • Keys/Names can be associated with entries • Use brackets with name string to accesses elements

  13. Variables cont. • Matrix • Is a vector that is mapped to the specified dimensions • Coercion done when dim doesn’t match • An associated array • Indexes start with 1  • Tables • Matrix with elaborate row and column names • Inherits additional methods: colnames & rownames

  14. Objects and functions • Objects are black box • unlike Java • Objects are implicitly associated with a class • Auto inherit mode and Attribute methods • More that one class may be inherited • There are many built in functions • Associated with classes but for all practical purposes act completely like functions

  15. Operations • Important Functions • Function c() creates a vector • Function list() creates a vector of generic types • Function dim() maps vector to an array • Function plot() graphs a dataset • Creating a objects • “<-” assign to an object • Can assign values, functions or other objects • Creating a vector: x <-c(1,2,3,4) • Creating a list x <- list( “one”, 1, three= ”three” )

  16. Expressions • Creating a matrix • array( c(1,0,0,1), dim=c(2,2))-> a : 1 0 0 1 • Creating a function • Default values as parameters x <- function(a , b = 1 ){ return( a + b );} x(1,2) is 3 x(4) is 5 • Creating a graph • Plot, box plot, density… etc

  17. Demonstration

  18. Characteristics • Readability • Black box objects make it difficult to understand what objects can do • Familiar syntax • Writeability • Large number of operators make full language use difficult • Large number of keywords is problematic • Consistent use of expressions make tasks easy • Cost • Syntax is familiar to C and C++ • Software and packages are free

  19. References • Micheal J. Crawley, “The R Book” , Wiley, 2007 • The R Project, www.r-project.org

  20. Simple Introduction to Prolog with Analysis By: Shannon Birchell

  21. Foundation • Languages is based on first order logic • Queries perform complex analysis on truth statements • Can display true of false at the simplest level • Can display all values that are true

  22. Data • Atom • A string of characters that is tokenized as an id • Has no other purpose • Scope is global • Numbers • Floats and Integers only • Variables • Starts with a capital letter • Anonymous variable “_” • Scope is rule

  23. Rules • An Axiom is a statement of truth • Immutable – always true “There is a dog call red” • There must be an animal dog : animal(dog). • There must be a name red: name(red). • Rules are axioms with relationships Given the previous example “There is a dog called red” • The relationship that bind “dog” and “red” the verb called Therefore called(x):= name(x), animal(x).

  24. Unification & Backtracking • Unification is how prolog derives the truth of a query • This is done by checking all axioms against rules Object is to make the implication query equal: axiom1, axiom2 axiomN…. rule1, rule2… query ? Rule LHS <- rule RHS <- axioms • Backtracking is the process of performing unification over all possibilities

  25. Demonstration

  26. Characteristics • Readability • Difficult to understand the relationships • But this is the point!!! • Writeability • Simple statements of fact • Simple syntax • Reliability • Bad query catastrophically fail • Unintended consequences of statements unrealized

More Related