1 / 36

Programming Languages: Prolog, Clojure, F#

Programming Languages: Prolog, Clojure, F#. Jared Wheeler. Prolog. 1972 Development Declarative Language No Algorithms Define the Problem It finds the answer. Parts. Knowledge Base Facts Basic Assertions Rules Inferences about Facts Queries. Naming. constant Variable or _variable

althea
Download Presentation

Programming Languages: Prolog, Clojure, F#

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. Programming Languages:Prolog, Clojure, F# Jared Wheeler

  2. Prolog • 1972 Development • Declarative Language • No Algorithms • Define the Problem • It finds the answer

  3. Parts • Knowledge Base • Facts • Basic Assertions • Rules • Inferences about Facts • Queries

  4. Naming • constant • Variable or _variable • List – [1, 2, 3] • Tuple – (1, 2, 3) • Fixed Length

  5. Unification • No Assignments • Prolog tries to make variables and constants equal • If succeeds, an inference can be made

  6. Results • Yes • No • Answers unasked question of if execution completed

  7. Recursion • Call Rule from within Rule • Tail-Recursion Optimization • Put Recursive call at End • Prolog keeps memory use steady

  8. Uses • Solving Systems within Constraints • Puzzles • Natural Language Processing • AI

  9. Weaknesses • Utility • Scaling to Large Data Sets • Depth First Search for Answers • Learning Curve

  10. Prolog Demo • Knowledge Base File • Execution

  11. Clojure • Lisp for JVM • Scheme, lisp-1, not Common Lisp, lisp-2 • Difference in namespacing functions and data • Data As Code

  12. Variables • (defvariableName item) • Prefix notation • (let value variableBound) • Temporary binding of value to a variable

  13. Data Structures • List – Ordered Collection () • Hold Code • First element is always executed as a function • Vector – Ordered Collection [] • Hold Data • Map – Key-value Pairs {} • Clojure allows comma delimitations • Keys can be used as functions to retrieve the value • Set – Unordered Collection #{} • Can be used as a function to find if an item is included

  14. Functions • (defn name [parameters] body) • Parameters within a vector • (fn [parameters] body) • Anonymous function

  15. Recursion • No Tail-Recursion Optimization • Working around JVM too much • (loop [parameter1 boundVariable, …] (recur (parameter1In)))

  16. Sequences • Common Parent to Most Data Structures • Comes with many default functions • every?, some?, filter, map, reduce, sort • (for [x seq] function) • Binds each member of the seq to x one at a time

  17. Lazy Evaluation • (repeat 1) • Repeats 1 until the process is killed • (take 5 (repeat 1)) • Repeats 1 five times • Lazy Evaluation means infinite sets can be computed • Evaluations only occur once needed

  18. Concurrency • Software Transactional Memory • Inspired by database transactions • (def reference (ref “some data”)) • @reference gives “some data” • Cannot change without a dosync function

  19. Interfaces • defprotocol • Define a contract • defrecord • Implements the protocol • Records are immutable

  20. Macros • Two stages of Clojure Execution • Macro Expansion • Execution • defmacro to Create

  21. Strengths • Powerful and Flexible • Use of JVM • Lisp minus parenthesis and reader macros • Concurrency • Lazy Evaluations

  22. Weaknesses • Complex • Prefix Notation • Readability • Complex Recursion Optimization • Compared to other Functional Languages

  23. Clojure Demo • General Form

  24. F# • Built by Microsoft Research • Runs on the .NET Framework

  25. Variables • Assignments by Let statements • Immutable unless ‘modifiable’ attribute at declaration • Statically Typed • Strong Type Inferencing

  26. Functions • Let functionName Parameters = body • Whitespace-sensitive • Parameters have type inferencing • Sometimes require (variableName:type) • Functions can be Passed as Parameters

  27. Anonymous Functions • Lambda Expressions • (fun params -> body)

  28. Lists • [ 1; 2; 3] = [1..4] • Ranges allowed • List.map (function) listName • Applies a function to all members • List.filter (function) listName • Returns members that the function returns true for

  29. Array • [| 1; 2; 3|]

  30. Record • Grouped Data with Member Names • Immutable • Defines data types • Keyword type to define • Mutate using with • Members can be optional

  31. Discriminating Joins • Enumeration Type object = | Option1 | Option2

  32. Forward Pipe Operator List.sum (List.map (fun x -> x * 2) (List.filter (fun x -> x % 2 = 0) [0..100])) • Into this: [0..100] |> List.filter (fun x -> x % 2 = 0) |> List.map (fun x -> x * 2) |> List.sum

  33. Currying • Functions Have One Parameter • Return a function asking for the next • Repeats until all parameters are accounted for • Parameter order matters • Allows for New Operators Easier • Also allows for different form of overloading

  34. Operators • Overload Only a Select set of Operators • Otherwise overwrites • Unless done within a type • Define new Operator For One Parameter • Works due to currying

  35. Sublanguages • Active Patterns • Pattern Matching • Customizable • Allows labels within a pattern to call a function • Quotations <@ … @> • Stores code fragments • Type Checks, but no execution • F# 3.0 has Type Provider that can execute • Together, they allow Sublanguages or Cross-Compilation

  36. F# Demo • General Form • Record Creation • Record Mutation

More Related