kinds and lists

I have been posting about kinds and their specifics, but now I want to ask about kinds of lists. I want a spell book to contain a list of text (spells) that I can add to from a table, and read back to get a list of those spells. The parser is giving me a not-specific-enough error as before, but I don’t know. I create a rule for the very purpose of needing to know what specific item I am reading from.

[Define readable things.]
A readable thing is a kind of thing.
A readable thing has some text called inscription-text.
A readable thing can be read or unread. 

A spell book is a kind of readable thing. A spell book has a list of text.
A magical spell book is a kind of spell book.
A clerical spell book is a kind of spell book. 

[New READ COMMAND.]
Understand the command "read" as something new. 
Understand "read [something]" as reading. 
Reading is an action applying to one thing, requiring light. 
	
Carry out reading: 
	if noun is spell book:
		say "Within the contents of the spell book you find these spells:[line break]";
		say "Name     Cost     Notes[line break]";
		let L be list of text of spell book;
		say "[L]";
	otherwise:
		say "[inscription-text of noun]";	
	now noun is read;

[To add a spell to the book]
to learn (spell - text) in (book - spell book):
	let spelltbl be Table of Magical Spells;
	if book is clerical spell book:
		now spelltbl is Table of Clerical Spells;	
	let L be list of text of book;	
	add spell to L;

Problem. In the sentence ‘let L be list of text of spell book’, it looks as if you intend ‘list of text of spell book’ to be a property, but ‘a spell book’ is not specific enough about who or what the owner is.
There must be some simple syntax I am missing.

When you just say “spell book”, Inform doesn’t know which specific spell book you mean. In this case, the one you mean is the noun, so say “the noun” instead.

Yes, thank you. That did not give me a parer error. It seems (at least) nuanced to distinguish “noun” from “spell book”, but ok. (Noun is pretty general too.)
Secondly, there was nothing in the book. Didn’t the LEARN rule put something in that list of text?

Oh, here is some code about learning spells.

let myCSB be a random clerical spell book in GenerationSpace;
now player is carrying myCSB;|
learn "Cure Light Wounds" in myCSB;

I revised the code to follow the I7 docs section 16.5 Choosing Rows. All seems like it should work but I get a malformed choose error.

to learn (spell - text) in (book - spell book):
	let spelltbl be Table of Magical Spells;
	if book is clerical spell book:
		now spelltbl is Table of Clerical Spells;	
	let L be list of text of book;	
	add spell to L;
	say "Trying to put [spell] spell into [book] consulting [spelltbl][line break]";
	choose row with a name of spell in spelltbl:
		say "I found it!";
		say "[current table row]"; 
[		add name entry to L; 
		add cost entry to L; 
		add notes entry to L; 
]

Problem. You wrote ‘choose row with a name of spell in spelltbl’: but the punctuation here ‘:’ makes me think this should be a definition of a phrase and it doesn’t begin as it should, with either ‘To’ (e.g. ‘To flood the riverplain:’)…**

choose row is not a block statement. It should end with a semicolon, and the following code should not be indented.

Yes, that worked. (I feel foolish.) :man_facepalming:
However, the list of text in the spell book is still empty. Can you help?

Isn’t that because you added the spell to a local list variable instead of adding it to the spell book’s list?

I thought I DID add it to the book. Doesn’t

let L be list of text of book; do that?

I think that line is interpreted as:

let L be a list of text of book;

ie, L is a new empty list. Though, I’m not completely sure of this, as the of book suffix confuses the issue.

A spell book is a kind of readable thing. A spell book has a list of text.
A magical spell book is a kind of spell book.
A clerical spell book is a kind of spell book. 

I thought L would become the list of text in the spell book. How do I reference the list of text that already exists in the book?

I think list of test of book is the correct way to reference it, but let is a bit special about how its argument is interpreted, so that might be confusing things. What if you just say add spell to list of text of book?

Weird! That worked. Now I only need grab the other entries from the ref table to complete what is written in the spell book.

I think probably what happened is that L was a copy of the spell book’s list, so you added the spell to that copy but never put the copy back in the spell book.

OK. How would I fix that? I used L to shorten all the typing, which is going to occur a lot many more times.

You could probably do this:

	let L be list of text of book;	
	add spell to L;
	now list of text of book is L;

It may also help your typing to give a name to the property.

A spell book has a list of text called repertoire.

And then list of text of book becomes repertoire of book.

I’ll also note that you can still use the let L... without worry if you’re only reading the list and not editing it.

Thanks so much. I will be adding to the spell book list but not editing it.

I think you misunderstood… adding to it is a form of editing. I meant you wouldn’t need to worry about this issue in places where you’re just looking at the list.

OK. I have not been able to get the name of the list to work.

A spell book has a list of text called mana.

Mana throws an error for some reason in the LEARN rule.

EDIT: Never mind. Different error. Got it working.