Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology
Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered
You are not logged in.
Pages: 1
Colleagues..
can scol step through fields of a struct in a loop or recursive function of some sort?
Offline
Hello,
If uou're trying to explore a structure field by field, then the answer is: this is not possible.
Bob
Offline
Why do you want explore these fields ?
To destroy resources/objects with typedef. Let's say i have a struct with 100 fields of ten types. If I step through the fields when the app shuts down, that's less lines of code since typedef dispatches each field to its proper destruction function.
Last edited by hebdemnobad (11-Nov-2014 19:57:52)
Offline
yep it's not possible since each field have different types.
for this you must have a list or a tab.
Hmmm....is there a way to extract a list from a struct?
Offline
Not automatically...
And manually, it really depends on what you want to do, and how you organized your data in your app.
Offline
Same thing than Bob.
Basically, to destroy an object defined by a typedef, you could write something like that :
typedef MyType =
MT_Win ObjWin
| MT_Bitmap ObjBitmap
| MT_Font ObjFont
| MT_Other;;
fun destroy (myMTobject) =
match myMTobject with
(MT_Win win -> (_fooS "Window destroying"; _DSwindow win))
| (MT_Bitmap bmp -> (_fooS "Bitmap destroying"; _DSbitmap bmp))
| (MT_Font font -> (_fooS "Font destroying"; _DSfont font))
| (_ -> (_fooS "Nothing to destroy"; 0));;
Offline
If your variable is a global, you should set it explicitely to nil after the object destroying (as i tell in another thread).
If you need it again after, you are sure that it is at nil. Then, you can safely reuse it and thus initialize it again.
Offline
Not automatically...
And manually, it really depends on what you want to do, and how you organized your data in your app.
I think this would be a good addition to the core api..it could save coding destruction calls for each field.
But I can manage ok as things are now.
Offline
This seems difficult : in fact each field is seen as a function by the VM and they can be of any type.
But I can manage ok as things are now.
You could group some fields in sub structures. This may be easier.
Offline
This seems difficult : in fact each field is seen as a function by the VM and they can be of any type.
hebdemnobad wrote:But I can manage ok as things are now.
You could group some fields in sub structures. This may be easier.
Perhaps the struct declaration can at the same time create a polymorphic list automatically?
Answer at your leisure I'm just conjecturing.
Offline
Can you get an example ? i don't really see what you wish.
I have to look into your example involving animals and typedef...once I understand that I will be able to make my question answerable. But something like:
structtolist (struct), returns a list [u0-x r1]
takes a struct, returns a list of fields. each field may be of a different type. scol runs through the list recursively, and figures out what the type of each field is. once the vm know the type of the field, it can call a function that is the correct function in order to destroy it (or create it as well, now that i think of it)
Offline
No.
First, a list can not contain several types.
fun A ()= 12 :: "e" :: 12.3 :: _channel :: 0 :: nil;;
fun A ()= 12 :: "e" :: 12.3 :: _channel :: 0 :: nil??;;
>>> ERROR - Type mismatch (detail):
Found: [Chn [I r1]]
Expected: [Chn [Chn r1]]
<<<
It would have a recursive level too high (rn, not r1). In practice, we can not manage a such list.
Next, the VM knows the type of each field when the compiling time. After, when running, these informations are lost, the VM does not need it.
Maybe get the field from its position ?
I'll see if I can do something but it is not clearly a priority.
Offline
I'll see if I can do something but it is not clearly a priority.
I agree, it is not a priority, it was just something I was thinking about while reviewing some old books on vbscript and javascript.
Offline
Pages: 1