Inform 7 - same grammar but a phrase is rejected?

Hi,

I’ve been playing around with Inform 7 a lot recently, as it’s an intriguing language to me. I’ve even found that it can be better at expressing database concepts than some actual database software (has it ever been considered to make an Inform 7 to SQL compiler? :slight_smile: )

You can see below one of my attempts at writing up a database structure using Inform 7. It’s based on the modular programme rules of my University.

"InformTest" by Moose

A student is a kind of person.
A student has some text called the name.
A student is either undergraduate or postgraduate.

A module is a kind of thing.
A module has some text called the name.
A module is either basic, advanced, or honours.
A module is either undergraduate or postgraduate.

A field is a kind of thing.
A field has some text called the name.

Enrolment relates various students to various fields.
Studying relates various students to various modules.
Acceptability relates various modules to various fields.
Compulsoriness relates various modules to various fields.
Prerequisition relates various modules to various modules.

The verb to study (he studies, they study, he studied, it is studied, he is studying) implies the studying relation.
The verb to take (he takes, they take, he took, it is taken, he is taking) implies the studying relation.
The verb to be acceptable on implies the acceptability relation.
The verb to be compulsory on implies the compulsoriness relation.
The verb to be a prerequisite of implies the prerequisition relation.
The verb to be enrolled on implies the enrolment relation.

To check (target field - a field) for hidden compulsories:
	repeat with compulsory running through modules that are compulsory on target field:
		repeat with prerequisite module running through modules that are a prerequisite of compulsory:
			if prerequisite module is not compulsory on target field, say "[prerequisite module] is a hidden compulsory on [target field] via [compulsory].  "

To check if (target student - a student) has a complete programme:
	if the number of basic modules studied by target student is less than 8:
		say "Too few basic modules.";
		stop;
	if the number of modules studied by target student is less than 24:
		say "Too few modules.";
		stop;
	repeat with target field running through fields target student is enrolled on:
		say "Test".

My problem is that Inform barfs on the phrase “target field running through fields target student is enrolled on”, saying that it doesn’t understand it but not giving any idea why not. The earlier “check for hidden compulsories” process compiles fine even though it seems to use the same grammar so I’m not sure what the problem could be. I’ve tried rewording it in various ways (“target field running through fields on which target student is enrolled”, and even “target field running through fields related to target student by enrolment”) but every time I get the same completely opaque error. What am I doing wrong? Is there a way to get Inform to show me the part of the parse tree it’s having a problem with?

Does this addition/replacement do what you want? It seems to, but I’m not sure how much was snipped from your example code.

[code]The verb to enroll (he enrolls, they enroll, he enrolled, it is enrolled, he is enrolling) implies the reversed enrolment relation.

To check if (target student - a student) has a complete programme:
if the number of basic modules studied by target student is less than 8:
say “Too few basic modules.”;
stop;
if the number of modules studied by target student is less than 24:
say “Too few modules.”;
stop;
repeat with target field running through the fields enrolling the target student:
say “Test”.[/code]

Thanks - this did work, but being a codey type I’m bothered that I don’t understand why…

Your problem is this bit:

“fields target student is enrolled on”

– and the trouble is the reversed grammar you’re using here. Inform can understand syntax of the form X {relation} Y, whether that’s “students {who are studying} maths” or “subjects {which are studied by} Josephine”. It does not handle syntax of the form X Y {relation}, as you have here. (It would also not understand “chairs the dog is on”, “boxes a coin is in”, etc.)

That makes sense, but is there any syntax to loop through the range of a relation implied by a predicate without specifying an verb for the reverse? Or even using a non-verb syntax (“fields related to target student by enrolment” was also rejected?) It seems really contradictory if you can only loop through the domain of a relation…

Why not specify a verb for the reverse? I don’t remember the syntax, but something like “the verb to be studied by implies the reversed enrolment relation” seems like it would be very handy. Except that I forgot you already used the “study” verb.

I think you can also say “fields related to target student by reverse enrolment.”

Well, that puts the finger on what’s bothering me.

It seems that although I’ve said, “Enrolment relates various students to various fields”, in fact, I can’t - using that relation - calculate which fields a student is taking. That would require the forbidden syntax “the fields John is enrolled on”. What I can do is to calculate, given a field, which students are taking it - so “students enrolled on Computer Games”.

In other words, the enrolment relation created by “Enrolment relates various students to various fields” actually relates fields to students, not students to fields.

Having to use the “reversed enrolment relation” to access the mapping from students to fields, when that is actually what I asked for the enrolment relation to be in the first place, just makes it more confusing :slight_smile:

Maybe it will be helpful to think of it this way:

Inform doesn’t have an implicit way of distinguishing nouns. It doesn’t know that there isn’t a noun called fields students, or fields students enrolled, or whatever. Verbs are amongst the tools necessary to indicate where the breaks are, so it’s not looking to repeat through the imaginary value fields students are enrolled in but the fields (which enroll) (some student X).

Given the vagaries of English, it’s probably safer all around this way. BTW, I’ve always heard “enrolled in”, as in “John is enrolled in Computer Science.” Can I ask what part of the world you’re from? Just curious.

That isn’t the issue - it’s that when I want to add that verb “which enrolls”, I have to add it corresponding to the reversed enrolment relation. But I want that verb to relate students to fields which is what I originally specified that enrolment should do in the forward direction.

The UK. I think “enrolled on” is fairly standard here. Interesting! :slight_smile:

Ah, missed the problem originally. Sorry.

The verb you want is relating students to fields, but only in the sense that all the relations are going to assign students to fields.

Consider :

In the first instance, the subject is the student, the primary “target” of your relation. Various students relate to various subjects. So your verb without reversals, “to be enrolled on” is useful for that straightforward declatory sentence. Whatever verb you’d use to complete the sentence “John ___________ computer science” is the enrollment relation verb without reversal; any verb you’d use to complete the sentence “Computer science _______ John” is the reversed.

But you’re not writing a straightforward declarative statement, so it seems backwards; your goal is to look at a particular student’s fields (John to his fields). This makes total sense, but the actual sentence you have to construct is actually in the frame of fields to a particular student (fields _______ John), so you need the reversed verb. The sentence form dictates the verb form.

I eventually hit on the same solution as gravel for this, but I wonder if either of these would make things easier in this kind of situation:

(Probably pretty ambitious): Treat “that” as a delimiter which allows the construction that moose originally wanted (“repeat with target field running through fields target student is enrolled on”). As gravel said, the Inform compiler doesn’t know that “fields” and “target student” are two nouns; it could be “fields target” and “student,” or “fields target student” as one noun. But if you allowed “that” as a delimiter in this kind of declaration, could you have “repeat with target field running through fields that target student is enrolled on”? The “that” would provide an unambiguous break between nouns. I guess what I’m thinking of is something like “X that Y Z” translates into “X bearing the reversed Z relation to Y” whenever X and Y are nouns and Z is a verb.

(Maybe less ambitous? Probably more helpful in general): One of the issue here is that the compiler error message isn’t that helpful: “I was expecting to read a description, but instead found some text that I couldn’t understand - ‘fields target student is enrolled in’.” The thing is, we don’t know why the compiler couldn’t understand the text. So would it be possible to have the message explain how the compiler is trying to break down the text – “I tried to understand ‘fields target student’ as a noun and ‘is enrolled in’ as a verb, but that didn’t work”? Something like that.

Actually, now that I think of it, the latter suggestion may be absurdly ambitious. So I won’t put these in the suggestion forum yet. But any thoughts?

The “noun that noun verb” construction was actually my first try, and I half-expected it to work, so I think it’s at least worth a suggestion.

Edit: Also, “which” or “[preposition] which”, as in “fields in which the target is enrolled.” (That one’s tricky because it would require moving the preposition from the verb form to before the which, so maybe it should be left out? Or I could live with “field in which the target is enrolled in” despite the grammatical tangle.)

I think I’ll just suggest “that” and “which.” [preposition] “which” seems like it’d probably be a compiler’s nightmare; the compiler would have to know where the preposition went, and for that matter it’d have to know that it was a preposition. At least I take it that when we define a verb “to be enrolled in” “in” doesn’t have any special status – it could just as well be “to be enrolled frooble.” Also I like to stand up for the preposition at the end of the sentence. Or the preposition at the end of the sentence is something I like to stand up for.