Page 1 of 1

Arrays

PostPosted: March 20th, 2015, 11:55 pm
by Alekz
I think the idea of implementing arrays appears in various forums from time to time. AIML is pretty much useless here, also v2. I wonder if it can be implemented using custom tags, e.g. <array>.

Another possibility is to extend the current variable implementation to support checking if a variable defined and "loose" <set> arguments. For example:

<set hobby="1">fishing</set>
<set hobby="2">jumping</set>
<set hobby="3">music</set>

or:

<set hobby="music">classical</set>

or:

2D arrays:

<set <get hobby="3"/>="1">jazz</set>

To get all elements:

<get hobby />

The length can be automatically saved in the length variable:

<get hobby="length" />

Search through all elements:

<condition hobby="*">
<li value="music">You like the following kinds of music: <get music /> </li>
</condition>

Just an idea ;)

Re: Arrays

PostPosted: March 20th, 2015, 11:58 pm
by Alekz
Or to keep the compatibility:

<array hobby="1"> music </array>
<array hobby="length" />

etc...

Re: Arrays

PostPosted: March 21st, 2015, 6:16 am
by GeekCaveCreations
In your first post, you used a lot of things that are either invalid XML, or attributes that Program O just isn't designed to use. For example, this:

Code: Select all
<set <get hobby="3"/>="1">jazz</set>


is simply not valid XML, and is not possible to parse that way. The rest of your examples use a HOBBY attribute, which isn't provided for in any way within Program O. You could certainly create a function to handle an <array> tag, but I don't think it would be a good idea to use a custom attribute the way you're using it, because if you did you'd have to write code to handle an unknown quantity of "special" attributes, and that's prohibitively difficult. Instead, I would use the NAME and INDEX attributes that are already in use in the script. An example of what I'm referring to would look like this:

Code: Select all
<array name="hobby" index="1"/>


The only thing here is how you would set these arrays. For that, perhaps the best way would be to actually have two custom AIML tags:

Code: Select all
<arrayset name="hobby" index="1">some value here</arrayset> <!-- to set the array - the index attribute would be optional, and doesn't have to be numeric -->
<array name="hobby" index="1"/> <!-- to get the value of the array at index #1 -->


There are other methods of obtaining the same results for setting the array, but this would be the simplest and most elegant.

Re: Arrays

PostPosted: March 21st, 2015, 3:58 pm
by Alekz
GeekCaveCreations wrote:In your first post, you used a lot of things that are either invalid XML, or attributes that Program O just isn't designed to use.
. . .
The rest of your examples use a HOBBY attribute, which isn't provided for in any way within Program O.


Oh yes, I know. That was mainly a brain dump, just a bunch of ideas to tweak Program O in compliant and non-compliant ways ;)

GeekCaveCreations wrote:There are other methods of obtaining the same results for setting the array, but this would be the simplest and most elegant.

Looks neat, indeed. And what can be the way to get the length of the array?

But in any case, I think it is important to provide a way to check if a variable is defined. This is covered in this topic. That would greatly simplify AIML programs and make them more flexible. And still within AIMLv1 ;)

Re: Arrays

PostPosted: March 21st, 2015, 6:10 pm
by GeekCaveCreations
And what can be the way to get the length of the array?


That would depend a lot on how you intended to use it, and where. To be honest, I don't quite see yet how this could have a tangible, "real world" benefit.

Re: Arrays

PostPosted: March 22nd, 2015, 12:06 am
by Alekz
For example, to add a new element: array[length]=value or array[length+1]=value (depends on the implementation), to count all items (you have 4 friends, your named 5 reasons, I know only 6 colors, you carry 3 items, you do not have so many pockets, your logbook contains 132 entries, etc).

Also, your new <math> tag can help here, especially if it can do comparisons.