2014년 12월 4일 목요일

Complex variables

I would like to see how to create complex variables or variables made with elements of different type. Maybe the easiest example is the complex number, which has real and imaginary part. In Pascal you use the "record" to create such structure, in C "struct", in Java object... I don't see a clear conceptually way to do that with app inventor. In this way is easy to make the methods or functions that provide math operations of complex numbers, specially if you need a vector (array) of complex numbers.

Another example can be the Quiz. It's needed to keep two separate lists with questions and answers and manage both at time. I think it should be more clear a unique list in which each item contains two elements, question and answer. Also imagine you need a number for each question representing the number of points according difficulty of the question. Thus in this way you need a third list with those numbers. By putting this new element as part of each item of the list you have grouped the question, answer and difficulty level, which is in my opinion easy to manage. 

If you say you could use lists of lists, I don't think this is correct cause each item can have different number of elements and all of them are of same type. What I would like to have is that all items have same elements and these elements can be of different type.

At least I missed something, I'm searching something like a variable block able to contain another variable/s block.



Your "complex" variable could be a list...



Thank you for your answer. However lists are conceptually different from what Im' looking for (maybe it doesn't exist in app inventor). For sure I can work with lists or separate variables or lists of lists as said, but this is different. Basically in a list you can add or eliminate elements. So when you have an array of "complex" each one could have different number of elements and this is not what I want.

Imagine you have a small data base with three fields. You can have let's say 10 rows, 10 items in your database, Each item has same elements, for instance, name, age, favorite_color. For this case the natural way (in my opinion) is build a complex variable with the elements name, age and color and then a list of those complex variable to represent the whole database. For sure you can build the same with separate variables and/or lists of lists but I think this is less appropriate. 



You could certainly build variables like that, with the values separated by commas, and parse them every time you read them.  I think you're trying to make this more "complex" than it has to be.  A list... each element has your three items, separated by commas... 10 items in the list  That's your database of variables... 10 items, of three elements each.



Some people use XML to store multi-part data.
Here's a link to some examples ...

You can do it a little more compactly in JSON, too.

And here's a link to a doc of mine if you want to use lists of lists...



ok. Thanks to all for the ideas and hints. 
Time to check them carefully ans decide what better suits my needs.


댓글 없음:

댓글 쓰기