1. Oh, I may have a big problem with Euphoria

If I build a deeply-nested data structure of arbitrary size, say for example
a tree:

(view using a fixed font)
a
b       c
e   f   g   h
i j k l m n o p
qrstuvwxyz123456

where z is root[RIGHTCHILD][LEFTCHILD][LEFTCHILD][RIGHTCHILD][VALUE] (follow
that?), then is there any way of modifying z without hardcoding that
particular expression? There does not appear to be a way of "aliasing" that
nasty expression, or saving some sort of bookmark to z that I can use later
to access it.

The word "pointer" springs to mind, but maybe there is another way.

Just as an example, show me a routine, for an arbitrary tree represented by
nested sequences, to change all instances of "g" to "w". Suppose the tree is
built at runtime by user action, and has gaps in it....

Then, what if the user bookmarks nodes in the tree? Must I save the bookmark
information in the nodes, to be able to identify it later? If I do this, it
seems that searching the tree for bookmarks would be incredibly inefficient
and ugly, compared to having external bookmarks.

Do I have to use dynamic allocation and pointers, after all?

When we sing the praises of sequences vs. pointers, are we sweeping this
sort of difficulty under the rug?

George
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

new topic     » topic index » view message » categorize

2. Re: Oh, I may have a big problem with Euphoria

Thanks, Mike.

More snippets. 8^)

George

----Original Message Follows----
From: Michael Nelson <MichaelANelson at WORLDNET.ATT.NET>

<snip>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

new topic     » goto parent     » topic index » view message » categorize

3. Re: Oh, I may have a big problem with Euphoria

George Henry wrote:

<snip>

> If I build a deeply-nested data structure of arbitrary size, say for
example
> a tree:
>
> (view using a fixed font)
> a
> b       c
> e   f   g   h
> i j k l m n o p
> qrstuvwxyz123456
>
> where z is root[RIGHTCHILD][LEFTCHILD][LEFTCHILD][RIGHTCHILD][VALUE]
(follow
> that?), then is there any way of modifying z without hardcoding that
> particular expression? There does not appear to be a way of "aliasing"
that
> nasty expression, or saving some sort of bookmark to z that I can use
later
> to access it.

sequence bookmark

-- then to retrieve:

function subscript(sequence Param,sequence subsc)
   object returnValue
   returnValue=Param
   for i=1 to length(subsc) do
      returnValue=returnValue[subsc[i]]
   end for
   return returnValue
end function

object val
val=subscript(root,bookmark)


>
> The word "pointer" springs to mind, but maybe there is another way.
>
> Just as an example, show me a routine, for an arbitrary tree represented
by
> nested sequences, to change all instances of "g" to "w". Suppose the tree
is
> built at runtime by user action, and has gaps in it....

function sequence_replace_all(sequence seq,object old,object new)
    for i=1 to length(seq) do
        if equal(seq[i],old) then
            seq[i]=new
        elsif sequence(seq[i]) then
            seq[i]=sequence_replace_all(seq[i],old,new)
        end if
    end for
    return seq
end function

-- x is the sequence where you want to do the replacement
x=sequence_replace_all(x,"g","w")
-- or
x=sequence_replace_all(x,'g','w')

--remember that "g" is a one-element sequence (a String in C++/Java) while
-- 'g' is an atom (char in C++/Java)

-- Mike Nelson

new topic     » goto parent     » topic index » view message » categorize

4. Re: Oh, I may have a big problem with Euphoria

On 24 Dec 2000, at 17:26, George Henry wrote:

> If I build a deeply-nested data structure of arbitrary size, say for example a
> tree:
>
> (view using a fixed font)
> a
> b       c
> e   f   g   h
> i j k l m n o p
> qrstuvwxyz123456
>
> where z is root[RIGHTCHILD][LEFTCHILD][LEFTCHILD][RIGHTCHILD][VALUE] (follow
> that?), then is there any way of modifying z without hardcoding that
> particular expression? There does not appear to be a way of "aliasing" that
> nasty expression, or saving some sort of bookmark to z that I can use later to
> access it.
>
> The word "pointer" springs to mind, but maybe there is another way.
>
> Just as an example, show me a routine, for an arbitrary tree represented by
> nested sequences, to change all instances of "g" to "w". Suppose the tree is
> built at runtime by user action, and has gaps in it....
>
> Then, what if the user bookmarks nodes in the tree? Must I save the bookmark
> information in the nodes, to be able to identify it later? If I do this, it
> seems that searching the tree for bookmarks would be incredibly inefficient
> and ugly, compared to having external bookmarks.

Did you look at Jiri's associated lists code?

Kat

new topic     » goto parent     » topic index » view message » categorize

5. Re: Oh, I may have a big problem with Euphoria

>Did you look at Jiri's associated lists code?

>Kat

No, but I should.

I programmed an ADT a week or two ago that is implemented as an associative
list. I am familiar with the technique, and it occurred to me that it could
be applied to this problem.

Thanks for the suggestion.

George

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu