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
|
Not Categorized, Please Help
|
|