Scolring - Forum

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.

#1 11-Nov-2014 01:04:10

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

can scol step through fields of a struct?

Colleagues..
can scol step through fields of a struct in a loop or recursive function of some sort?

Offline

#2 11-Nov-2014 02:07:07

Bob Le Gob
Scol language & Scol applications developer
Registered: 9-Apr-2009
Posts: 26

Re: can scol step through fields of a struct?

Hello,

If uou're trying to explore a structure field by field, then the answer is: this is not possible.

Bob

Offline

#3 11-Nov-2014 03:12:57

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 4,821
Website

Re: can scol step through fields of a struct?

yep it's not possible since each field have different types.
for this you must have a list or a tab.

Offline

#4 11-Nov-2014 10:31:34

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: can scol step through fields of a struct?

Why do you want explore these fields ?

Offline

#5 11-Nov-2014 13:56:00

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: can scol step through fields of a struct?

iri wrote:

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

#6 11-Nov-2014 19:55:34

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: can scol step through fields of a struct?

arkeon wrote:

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

#7 11-Nov-2014 20:41:55

Bob Le Gob
Scol language & Scol applications developer
Registered: 9-Apr-2009
Posts: 26

Re: can scol step through fields of a struct?

Not automatically...

And manually, it really depends on what you want to do, and how you organized your data in your app.

Offline

#8 11-Nov-2014 21:20:32

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: can scol step through fields of a struct?

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

#9 11-Nov-2014 22:04:40

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: can scol step through fields of a struct?

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

#10 11-Nov-2014 23:39:24

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: can scol step through fields of a struct?

Bob Le Gob wrote:

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

#11 11-Nov-2014 23:52:39

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: can scol step through fields of a struct?

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.

Offline

#12 12-Nov-2014 01:33:33

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: can scol step through fields of a struct?

iri wrote:

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

#13 12-Nov-2014 07:56:17

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: can scol step through fields of a struct?

Can you get an example ? i don't really see what you wish.

Offline

#14 12-Nov-2014 16:49:59

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: can scol step through fields of a struct?

iri wrote:

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

#15 12-Nov-2014 17:23:36

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: can scol step through fields of a struct?

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

#16 12-Nov-2014 17:41:58

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,477
Website

Re: can scol step through fields of a struct?

iri wrote:

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

Board footer

Powered by FluxBB