intfiction.org

The Interactive Fiction Community Forum
It is currently Fri Nov 24, 2017 2:10 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Tue Nov 01, 2016 9:20 am 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5117
Location: Burlington, VT
Sorry for being flip about that! The thing is, I know so little about the sub-I7 level that what you said sort of reads to me like "Instead of cooking this finicky recipe, it might be simpler to genetically alter yourself so you can photosynthesize nutrients from sunlight." If anyone wants to try the filter IO method I'd be happy to look at it, but given my other adventures in I6 I'm trying to do as much at the I7 level as I can.

Anyway, I figured out that I wasn't clearing the cumulative buffer when I needed to--when you push something onto the stack you should clear it (because the old buffer has been pushed onto the stack), and when you stop capturing text after popping the last thing off the stack (because you've cleared the stack completely and aren't capturing text at all).

Also, thinking about the second half of the popping code, you really shouldn't be able to reach the case where the stack is nonempty and you're not capturing text; if your only interaction with the text is pushing and popping it, those will always start capturing text again unless you have popped the last text off the stack.

So here's what I have, with a couple new test cases and an option to pop the stack "loudly" (pop the stack and say the captured text):

Code:
Lab is a room.

Include Text Capture by Eric Eve.

The text capture stack is a list of texts that varies. The popped text is a text that varies. The cumulative buffer is a text that varies.

To clear the text capture stack: truncate the text capture stack to 0 entries.

To push the text capture stack:
   if text capturing is active:
      stop capturing text;
      let T be the substituted form of "[cumulative buffer][captured text]"; [not sure if substituted form is necessary]
      add T at entry 1 in the text capture stack;
      now the cumulative buffer is ""; [we pushed the buffer onto the stack, so we clear it]
   start capturing text.
   
To pop the text capture stack, loudly:
   if text capturing is active:
      stop capturing text;
      now the popped text is the substituted form of "[cumulative buffer][captured text]";
      if the number of entries in the text capture stack is greater than 0:
         now the cumulative buffer is entry 1 of the text capture stack; [reload the top of the stack back into the buffer]
         remove entry 1 from the text capture stack;
         start capturing text;
      otherwise: [we've emptied the stack and stopped capturing text, so we clear the buffer]
         now the cumulative buffer is "";
   otherwise if the number of entries in the text capture stack is greater than 0: [I'm not sure any of this is needed, or works]
      now the popped text is entry 1 of the text capture stack;
      remove entry 1 from the text capture stack;
   otherwise:
      now the popped text is "";
   if loudly and the popped text is not "":
      say the popped text.

To say start reversing:
   push the text capture stack.

To say finish reversing:
   pop the text capture stack;
   say "[popped text in reverse]".

To decide what text is (T - a text) in reverse:
   let output string be some text;
   let N be the number of characters in T;
   repeat with index running from 1 to N:
      now output string is "[character number index in T][output string]";
   decide on output string.

When play begins:
   say "[start reversing]Foo[start reversing]bar[finish reversing]baz[finish reversing].";
   say "[start reversing]Foo[start reversing]bar[finish reversing]bop[start reversing]bam[finish reversing]baz[finish reversing].";
   clear the text capture stack;
   now the cumulative buffer is "";
   push the text capture stack;
   say "Foo ";
   push the text capture stack;
   say "bar ";
   pop the text capture stack, loudly;
   say "bam ";
   push the text capture stack;
   say "bop ";
   pop the text capture stack, loudly;
   say "baz";
   pop the text capture stack, loudly;
   say "."


Output:

Quote:
zabbarooF.
zabbampobbarooF.
Foo bar bam bop baz.


I'm not quite sure exactly what the desired behavior in the last two cases should be, but this output isn't obviously wrong!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Nov 01, 2016 9:40 am 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 2433
Quote:
Sorry for being flip about that!

No worries! It wouldn't be a breeze for me either, I'd have to go dig into the Glulx spec to do it myself. I just thought from a technical perspective it might be simpler because you'd only have one stack rather than both memory streams and a stack. But code that works is always better than code that doesn't exist!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Nov 01, 2016 11:08 am 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 5117
Location: Burlington, VT
Ah, it would be simpler under the hood, that seems right. Beyond me, though! By a similar light, it'd probably be simpler if I could load the text that pops off the stack back into the buffer instead of using the cumulative buffer as a workaround, but I keep failing to reset critical counters when messing around with I6 buffers, so I'll keep it I7.

So right now I have the above wrapped up in an extension, which might just need some documentation before being ready to upload:

Spoiler: show
Code:
Recursive Text Capture by Matt Weiner begins here.

Section 1 - Dependency

Include Text Capture by Eric Eve.

Section 2 - Variables

The text stack is a list of texts that varies.

The popped text is a text that varies. [The thing that gets popped off the stack at the end. Basically the equivalent of "[captured text]" in Text Capture.]

The cumulative buffer is a text that varies. [The text that has already been written to the buffer in the current layer of text capturing. Probably best restricted to internal use only.]

Section 3 - Pushing, Popping, and Clearing the Stack

To push the text stack:
   if text capturing is active:
      stop capturing text;
      let T be the substituted form of "[cumulative buffer][captured text]"; [not sure if substituted form is necessary]
      add T at entry 1 in the text stack;
      now the cumulative buffer is ""; [we pushed the buffer onto the stack, so we clear it]
   start capturing text.
   
To pop the text stack, loudly:
   if text capturing is active:
      stop capturing text;
      now the popped text is the substituted form of "[cumulative buffer][captured text]";
      if the number of entries in the text stack is greater than 0:
         now the cumulative buffer is entry 1 of the text stack; [reload the top of the stack back into the buffer]
         remove entry 1 from the text stack;
         start capturing text;
      otherwise: [we've emptied the stack and stopped capturing text, so we clear the buffer]
         now the cumulative buffer is "";
   otherwise if the number of entries in the text stack is greater than 0: [I'm not sure any of this is needed, or works]
      now the popped text is entry 1 of the text stack;
      remove entry 1 from the text stack;
   otherwise:
      now the popped text is "";
   if loudly and the popped text is not "":
      say the popped text.

To clear the text stack: truncate the text stack to 0 entries.

Recursive Text Capture ends here.


And it actually seems to be working on the case I wanted it for:

Spoiler: show
Code:
Include Recursive Text Capture by Matt Weiner.

Lab is a room.

To say a-an of -- beginning a-an_of:
   push the text stack.

To say end a-an -- ending a-an_of:
   pop the text stack;
   if "[popped text]" starts with a vowel sound:
      say "an [popped text]";
   otherwise:
      say "a [popped text]".
   
To say uppercase A-An of -- beginning uppercase_A-An_of:
   push the text stack.

To say end uppercase A-An -- ending uppercase_A-An_of:
   pop the text stack;
   if the popped text starts with a vowel sound:
      say "An [popped text]";
   otherwise:
      say "A [popped text]".

To decide whether (string - a text) starts with a vowel sound:
   let the first word be word number 1 in string;
   if the first word is a word listed in the Table of Words That Start With Vowel Sounds, yes;
   if the first word is a word listed in the Table of Words That Don't Start With Vowel Sounds, no;
   if character number 1 in the first word is a vowel, yes;
   no.
   
To decide whether (letter - a text) is a vowel:
   if letter exactly matches the regular expression "a|e|i|o|u|A|E|I|O|U", yes;
   no.
   
Table of Words That Start With Vowel Sounds
word
"hour"
"hourglass"
"honest"
"yttrium"

Table of Words That Don't Start With Vowel Sounds
word
"uniform"
"unicorn"
"united"
"United"

Color is a kind of value. The colors are red, orange, yellow, green, blue, indigo, and violet.

The light is in the lab. For writing a paragraph about the light: say "[Uppercase A-an of][light][end uppercase A-an] is visible."

The light has a color called primary color. The light has a color called secondary color.

Before printing the name of the light: say "[primary color of the light] ".
After printing the name of the light: say " with [a-an of][secondary color of the light][end a-an] tint".

Every turn:
   now the primary color of the light is a random color;
   now the secondary color of the light is a random color.


There was a fair amount of testing that went into that because I forgot to put "light" in brackets and thought that the text capture stuff was swallowing up the before/after printing the name of the light rules, when they were never getting called in the first place. (Hard to use debug text to see what's getting called her, since the debug text winds up in the buffers.)


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group