Re: Code War: Quick Structure Check

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Tue, 16 May 2000 14:16:27 -0400, Lucius L. Hilley III <lhilley at CDC.NET>
wrote:

>I was unaware the not length line was preventing negative dimensions.

That wasn't really what I put it there for. Consider the following run-
throughs of equal_dimension() (abbreviated as as eq_d()):

***
1.  eq_d(1,{5,7})
    -- check all elements for "1d less 1" compliance (0d)
1.1   => eq_d(0,5) -- 5 is an atom, atoms are 0d, return 1
1.2   => eq_d(0,7) -- 7 is an atom, atoms are 0d, return 1
2.  No zeroes found -- {5,7} must be 1d, return 1

***
1.  eq_d(1, {9})
    -- check all elements for "1d less 1" compliance (0d)
1.1   => eq_d(0,9) -- 9 is an atom, atoms are 0d, return 1
2.  No zeroes found -- {9} must be 1d, return 1

***
1. eq_d(1, {}) -- we know this is 1d by sight
    -- check all elements for "1d less 1" compliance (0d)
    -- but this time there are *no* elements, so we *must*
    -- check for {} and dimension=1 rather than recursing one
    -- more time to look for atoms at dimension=0.

>> On a lighter note, a fun question: What's the dimension of this sequence:
>>
>>     {{1,2,3},{{4,4},5,6}}
>      ^------^  ^---^ ^--^
>        2D       3D    2D
>
>It doesn't fit any one dimension setting.
>
>> For extra credit, use your answer to tell me why equal_dimension() is
>> implemented in the way that it is. smile
>
>  I guess I don't get extra credit.

You are close with what you say here:

>REASON: your code correctly defines equal dimension.

It could quite easily have been expected to somehow run like this:

function dimension_of(object x)
    -- Insert code here
    return dimension
end function

This would hiccup quite badly at things like a mixed dimension sequence,
though.

>I wanted to ask the question.  Is the data given suitable?
>suitable(3, {})-- the answer is yes.

Ah-ha! smile Now I see where your...

    if not length(x) return (dimension > 0) end if

...idea came from. You want to *loosely* define the dimension of the empty
sequence, so it can be expanded afterwards.

>{"Lucius", "Lamar", "Hilley", "III", "123456789abc"} -- is suitable data to
>this format.
>However, it doesn't perfectly fit.  It can be expanded to
>{{'L','u','c','i','u','s',0,0,0,0},
> {'L','a','m','a','r',0,0,0,0,0},
> {'I','I','I',0,0,0,0,0,0,0},
> {'1','2','3','4','5','6','7','8','9','a'}, --some of this was truncated to
>fit.
> {0,0,0,0,0,0,0,0,0,0}
>}

I think what you're wanting to do is to make an n-dimensional sequence into
a perfect 'block', am I right?

Carl

--
.sig still missing.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu