Open fendor opened 4 months ago
@inariksit I think you are likely the best person to answer this question?
My initial ambition was to adopt Haskell where
semantics. I think the narrowing to RelationalPredicates
was due entirely to limitations at the time, so we went with a simplified implementation. To fully support Haskell where
semantics required a fuller notion of scope. We are only now beginning to address that issue. This past week we have tentatively agreed on Module-style semantics for binding scope.
I believe we had some discussion on whether a GIVETH would make sense in a WHERE, and the results were inconclusive. GIVEN would make sense: this is the (very ad hoc) syntax I/we established for functions last spring, fully based on the PAU case.
GIVEN x IS A Number ;
y IS A Number
DECIDE x `discounted by` y IS `x * (1 - y)`
Or in a table form, it looks like
GIVEN | x | IS A | Number | ||
---|---|---|---|---|---|
y | IS A | Number | |||
DECIDE | x | discounted by | y | IS | x * (1 - y) |
Is x * (1 - y)
supposed to be a function or the bnfc equivalent MUL(x, MINUS(1, y))
?
Regarding the semantics of GIVETH
, if we treat as GIVETH
as a declaration of output variables, then rules in WHERE
clauses may have a GIVETH
. For example;
GIVEN x DECIDE f x IS SUM(y, z)
WHERE
GIVETH y, z
DECIDE y IS 5;
z IS 7
Even though, it is possible to write this in two separate Rules, I think it makes sense to support this syntax. Especially, since we decided WHERE
should have Haskell-like where
semantics, then the rules in WHERE
clauses could be allowed to be full blown Hornlike
rules. However, I am unsure how this interacts with UPON
and other temporal rules.
Is x * (1 - y) supposed to be a function or the bnfc equivalent MUL(x, MINUS(1, y))?
Yes, it is! The GML transpiler uses an expression parser inside the cells, but for other targets MUL(x, MINUS(1, y))
should be used.
So in conclusion, should I amend the BNFC parser to accept full Rules in the WHERE clause? (In a way that doesn't break existing examples, of course.)
should I amend the BNFC parser to accept full Rules in the WHERE clause?
For now, I believe so, yeah :)
The recently added BNFC #591 parser for a fragment of natural4 has some seeming inconsistencies with the csv-based language.
This issue is for tracking these differences and discussing parts of the syntax and informal semantics.
One thing I found a bit confusing is the where clauses of a
Hornlike
rule. For example take:The
Hornlike
rule has awwhere :: [Rule]
field, but according to #591, theWHERE
part can only containRelationalPredicates
. Is this an intentional difference to natural4 or actually the status-quo of how the natural4 parser works right now?Note, I am omitting (ignoring) a discussion from the 25.7.2024 where it sounded like
WHERE
should mirror Haskell'swhere
, allowing the declaration and definition of arbitrary rules.