SPARK 0.8 David Morley, Nov 2005. Core Data Types Includes values most often used by SPARK Primitive –Integer, e.g. 1 –Float, e.g., 1.0 –String, e.g.,

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

C Language.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
Chapter 5 ( ) of Programming Languages by Ravi Sethi
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Road Map Introduction to object oriented programming. Classes
VBA Modules, Functions, Variables, and Constants
Topics of Lecture Structural Model Procedures Functions Overloading.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
SchemeCOP Introduction to Scheme. SchemeCOP Scheme Meta-language for coding interpreters –“ clean ” semantics Scheme = LISP + ALGOL –simple.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Context-Free Grammars and Parsing 1.
Basic Elements of C++ Chapter 2.
Introduction to scripting
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages
CIS Computer Programming Logic
Introduction to Python
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Introduction to Computational Linguistics Programming I.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Class Example - Rationals Rational numbers are represented by the ratio of two integers, a numerator and a denominator, e.g., 2/3. This is opposed to irrational.
Slide: 1 Copyright © AdaCore Subprograms Presented by Quentin Ochem university.adacore.com.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
PPL Applicative and Normal Form Verification, Type Checking and Inference.
“Education is a Treasure that follows you everywhere.” – Chines Proverb Methods and Functions.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Expressions Methods if else Statements Loops Potpourri.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Expressions and Data Types Professor Robin Burke.
Introduction to programming in java Lecture 21 Arrays – Part 1.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 4.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Java Primer 1: Types, Classes and Operators
2.5 Another Java Application: Adding Integers
Introduction to Scheme
Basic Elements of C++.
Types and Values.
Parameter passing Module 12.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Principles of programming languages 4: Parameter passing, Scope rules
Organization of Programming Languages
Chapter 7: Introduction to CLIPS
Introduction to Functional Programming in Racket
Basic Elements of C++ Chapter 2.
CMPE 152: Compiler Design October 2 Class Meeting
Introduction to Functional Programming in Racket
CS 432: Compiler Construction Lecture 11
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Common Lisp II.
CMPE 152: Compiler Design March 7 Class Meeting
Presentation transcript:

SPARK 0.8 David Morley, Nov 2005

Core Data Types Includes values most often used by SPARK Primitive –Integer, e.g. 1 –Float, e.g., 1.0 –String, e.g., “one” –Symbol, e.g., one –Variable designator, e.g., $var (new in 0.8) Compound –Structure, e.g., (foo 1 2 3) - has functor symbol foo –List, e.g., [1 2 3]

SPARK-L Source Represented by core data values (cf. Lisp, Prolog) SPARKL source to generate a value usually different from the value: –(+ 1 2) ⇒ 3, (- 4 1) ⇒ 3, 3 ⇒ 3 –[(+ 1 2) 3] ⇒ [3 3] “one”) ⇒ one “foo” 1 2 3) ⇒ (foo 1 2 3) “bar” (+ 1 1) (+ 2 2)) ⇒ (bar 2 4)

Backquote and comma Used for easy construction of basic values (cf. Lisp) Backquote ` prevents evaluation –`one ⇒ one –`(foo 1 2 3) ⇒ (foo 1 2 3) Comma, performs evaluation within backquote –`(bar,(+ 1 1),(+ 2 2)) ⇒ (bar 2 4)

File Contains –Package statement –Identifier declarations –Import statements –Export statements –Require statements –Facts to be loaded Every identifier (unquoted symbol or functor) used in the file must have a visible declaration. –Declarations in the file are visible –Imported declarations are visible –Any declaration visible to the package is visible

Package A Package is –A “bucket” that accumulates declarations, imports, exports from files –A means of communicating declarations between files Files can use identifiers from their package Files import identifiers from other packages into their package Files export identifiers from their package Unlike old concept of module: –Not a fixed set of files –New files can add identifiers to a package

Specifying the Package of a File “package: P” For backward compatibility: –“module: P” = “package: P” –If no package statement, package = filename

File-Local Names Not all declarations are shared with the package Identifiers starting with underscore are only visible in the file –_foo, _LocalPredicate, _Procedure1 It is conceivable (but no syntax exists) to import an identifier foo as a different identifer _foo. That import would not be visible to the package.

Identifiers and Symbols Identifers are local names –interpreted with respect to a file To distinguish identifiers in different files we associate a symbol with every identifier: For identifiers declared in file F in package P: –Id maps to symbol P.Id –_Id maps to symbol F._Id When an identifier declared as a functor appears instead as a symbol, it evaluates to the corresponding symbol: –Given {defpredicate (Id $x)} {defpredicate (_Id $y)} –Id ⇒ P.Id, _Id ⇒ F._Id (cf. `Id ⇒ Id and `_Id ⇒ _Id) –Useful for passing as an argument to applyfun, etc. –Less need for “(qent Id)”

Importing from a package Q. When you say “importfrom: P” which files do you get declarations from? Ans. All files in the transitive closure of the “requires” relation that are in package P. –F requires F’ if F contains requires: F’ –F requires P if F contains importfrom: P … –F requires P if F is in package P –P requires F if F has the same name as P

Usage SPARKL source expressions can be used in different ways Each way designated by a usage character: + evaluate term [set: $x (+ 1 2)] - match term (= [$x $y] [1 2]) s solve predicate [context: (P $x) ] u update predicate [conclude: (P 7) ] r retract predicate [retract: (P 4) ] … SPARKL source processing assigns a usage to each expression in source

Mode declaration for a functor Specifies argument usages Used for static mode checking of action/predicate usages before file is loaded Prefix inputs with “+”, outputs with “-” –{defaction (act +$x $y -$z)} In any use of this action: $x must be evaluable (I.e., is an input) $y need only be matchable (I.e., can be an output) $z must not be evaluable (I.e, must be output)

Formal parameters Richer formal parameters for: –defprocedure cues –task closure parameters –pred closure parameters Parameter may be one of: –+X - at start, match X to the actual parameter value –-X - at end, match actual parameter to the value of X –$x - at start, constrain $x to match actual parameter Examples: –+[$x $y] - match input parameter to [$x $y] Less need for Ground

Accessing Core Values from Python See Python module spark.internal.parse.basicvalues Core data types are called: String, Float, Integer, Symbol, Variable, Structure, List –Symbol(“foo”), List((1,2,3)), isinstance(x,List) Structure args/List elements access: –myStruct[0], len(myStrict), myList[1:2] Structure functor access: –myStruct.functor Symbol name access: –mySym.name or str(mySym) Construct Structure: –Structure(functorSym, argsSequence) or functorSym.structure(arg0, arg1, …)

Random Bits “precondition: X” is now optional No distinction between task modifiers and basic tasks –[context: X do: Y] is a special case of using […] for sequential composition (technically contiguous: rather than seq: )