AmpersandTarski / prototype

Prototype framework that transforms your Ampersand model into a web application
MIT License
1 stars 2 forks source link

Feature request: result variables in {EX} statements #81

Open RieksJ opened 5 years ago

RieksJ commented 5 years ago

Currently, we use the text _NEW in violation statements to refer to the atom that was created by the InsAtom function. This way of working prevents one from creating multiple atoms in a single VIOLATION statement and create a link between such atoms.

More general, we see the need for (user-defined) functions where the result is to become an atom in a pair that is to be InsPaired in some relation. An example might be the computation of a hash over an OBJECT.

This ticket suggests syntax and semantics for this, as follows, that extends the {EX} syntax, which currently is {EX} <function>;<arg1>;<arg2>; ... ;<argn>, to the following:

{EX} _$<varname> = <function>;<arg1>;<arg2>; ... ;<argn>

where <varname> is an arbitrary text (consisting of alphanumeric characters) representing the variable in which function will leave its result. The scope of <varname> is the VIOLATION statement in which it is used. Here is an example of what a VIOLATION might look like in which two atoms of type SomeConcept are created and linked in the relation scPair [ SomeConcept * SomeConcept ] [SYM]

VIOLATION (TXT "{EX} _$newSC1 = InsAtom;SomeConcept"
          ,TXT "{EX} _$newSC2 = InsAtom;SomeConcept
          ,TXT "{EX} InsPair;scPair;SomeConcept;_$newSC1;SomeConcept;_$newSC2
          ,TXT "{EX} InsPair;scPair;SomeConcept;_$newSC2;SomeConcept;_$newSC1
          )

The reason for keeping _ in this proposal is that it reduces the likelihood of ambiguous interpretation of texts in which $ appears (similar to why we sometimes use _; as separator). Specification of the _; separator remains as it is now, i.e. it should be specified immediately behind the {EX} (as in {EX}_;.

hanjoosten commented 5 years ago

Related to AmpersandTarski/Ampersand#800