spark 0.8 david morley, nov 2005. core data types includes values most often used by spark primitive...
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 Valuesfrom 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: )