parent.typename like self.typename?

Previous topic - Next topic

matchy

There's self. but how can I reference nested type referencing?   :-[
Logically, should there be parent. also?   :zzz:

Nested TYPE Example:
Code (glbasic) Select

TYPE _item
    id
    selected_id
    color
    size
    FUNCTION set:
         self.id = basket.item_id                    // absolute
//      self.id = parent.parent.item_id       // would prefer relative         
    ENDFUNCTION
ENDTYPE

TYPE _group
    apple AS _item
    banana AS _item
ENDTYPE

TYPE _base
    item_id
    fruit AS _group
ENDTYPE

GLOBAL basket as _base
basket.fruit.apple.set()


Kitty Hello

The child has no knowledge about the parent. (Unlike in real life) ;)

matchy

Ah. i was hoping it to be like Javascript, which is not real nor life either.  8)

bigsofty

#3
You could do it with a little ref passing workaround...

change...
   
Code (glbasic) Select
FUNCTION set:

to...
   
Code (glbasic) Select
FUNCTION set: parentRef as _base

then change...
   
Code (glbasic) Select
self.id = basket.item_id

   to...
Code (glbasic) Select
self.item_id = parentRef.item_id

Your call would need a change too...
   
Code (glbasic) Select
basket.fruit.apple.set(basket)

for another basket...
   
Code (glbasic) Select
basket2.fruit.apple.set(basket2)

Untested.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

matchy

I see what you mean bigS and I did have something like this. Pardon the complexity and I don't expect a complete solution, although the idea of any type parent was so that it could be generally called, well in this case the fruit may also be not in of basket type (eg. basket, box, bag have item_id).

Code (glbasic) Select


TYPE _container
    item_id
    fruit_sealed AS _group
    fruit_fresh AS _group
ENDTYPE

GLOBAL box as _container  // not the same as _base