dollabs / pamela

Probabalistic Advanced Modeling and Execution Learning Architecture
Apache License 2.0
233 stars 15 forks source link

Field references as symbols, Modes as keywords #136

Closed dcerys closed 6 years ago

dcerys commented 7 years ago

Clarify (and restrict) the Pamela syntax such that:

This will certainly impact many of our test cases.

If it's simple, it may be worthwhile to provide a compatibility mode that permits legacy use of a keyword field reference. E.g., (:car1.drive :current-speed-limit)

This should be implemented before Issue #81

tmarble commented 7 years ago

Due to the wide sweeping nature of this change it's not possible to retain a simple compatibility mode switch: the associated PR represents a change from fields as keywords to symbols. This is both a PAMELA source and IR breaking change.

Changes in the grammar

-field-expr = keyword symbol +field-expr = symbol symbol ( pclass field )

- The introduction of the `field-of` operator allows an unambiguous
  reference to a field of this class (or another pclass, e.g.
  `:field-reference-field`).
- An example of the "new look" can be found in this snippet
  of `cannon.pamela`:
  * before
          (parallel :bounds [1 60]
            (whenever (= :box-f.:ball-in-motion true)
              (tell (= all-clear true))) ;; all-clear is a state variable
            (whenever (= :cannon-f.:ready true)
              (unless (= :cannon-f.:ammunitions 0)
                (try :bounds [2 20]
  * after
          (parallel :bounds [1 60]
            (whenever (= (field-of box-f ball-in-motion) true)
              (tell (= all-clear true))) ;; all-clear is a state variable
            (whenever (= (field-of cannon-f ready) true)
              (unless (= (field-of cannon-f ammunitions) 0)
                (try :bounds [2 20]

- A new tool has been added `./bin/check-all` which will do a syntatic
  (parsing only) check on all pamela source files and store the result
  in `test/pamela{,/regression}/IR/<PAMELA-FILE-NAME>.txt`. Having
  this parse tree readily available can help understanding of
  how the grammar is implemented.
- The railroad diagram has been regenerated

Changes in the IR
- For details on the IR charges including a new tool (and associated output)
  to help analyze the changes please see doc/IR-CHANGELOG.md

Updating rubrics
- Most of the changed IR rubrics have only keyword -> symbol
  changes for fields.
- The test/pamela/OLD/ directory has been removed
- NOTE: The source file statements.pamela is an initial attempt to
  represent conditional expressions. While the IR generation is now
  ready, the HTN/TPN implementation is blocked on
  #139 Design desired HTN/TPN output for PAMELA statements with conditions.
  Thats why the HTN/TPN rubric for this file have changed, but are
  not yet in their final form.
dcerys commented 7 years ago

Instead of introducing the new syntax of field-of, I was assuming that we'd continue to use the existing dotted notation, where the period acts as a separator between pclass instance symbol (i.e., a reference to either a arg or a local field). For example:

             (parallel :bounds [1 60]
                (whenever (= box-f.ball-in-motion true)
                  (tell (= all-clear true))) ;; all-clear is a state variable
                (whenever (= cannon-f.ready true)
                  (unless (= cannon-f.ammunitions 0)
                    (try :bounds [2 20]

This provides:

  1. a cleaner syntax, analogous to the existing (box-f.method-name 1 2) syntax. (Note, we currently support both (:box-f.method-name 1 2) and (box-f.method-name 1 2) for a pclass instance field named :box-f)
  2. multi-level dereferencing (if we choose to support it). E.g., (foo my-field.his-field.her-field)

NOTE: This Issue was intended to cover all 3 different uses of field references:

  1. field references contained within a condition. Ex: (= cannon-f.ready true)
  2. field references contained as an method arg reference. Ex: (foo my-field.his-field)
  3. method references to a method of a field (which is a pclass instance). Ex: (box-f.method-name 1 2)

What are the issues (positive and negative) of changing the syntax to this dotted notation?

tmarble commented 7 years ago

@dcerys the positive impact is the syntax is much simpler (you drop one set of parens), the negative is that when we see symbolA '.' symbolB we have to figure out if symbolA is a method arg, pclass arg or field, then we need to figure out of symbolB is a method or field of symbolA, and finally we have to extend the IR to handle the generic case of multiple dereferencing A.B.C.D.....

Please advise on how you'd like to proceed. The next probably step is to add an example Pamela source file that exercises this behavior (since this PR is in flight it may be best to attach it here -or- add it to test/pamela/pending in the master branch).