1. array(0, {800,600}) is easier.

Assume that you want a sequence of 8x10.  Maybe it is a sprite or FONT. :)
IE:
sequence s
s = {
     {0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0}
    }

--or currently we may use:
s = repeat(repeat(0,10), 8)

Notice that the dimension definitions are reversed to get the desired
arrangement.
This can easily lead to programming confusion.

function array(object obj, sequence dimensions)
  object x

  x = obj
  for A = length(dimensions) to 1 by -1 do
    x = repeat(x, dimensions[A])
  end for
  return x
end function

now you can use:
s = array(0, {8,10})

OR what the subject states.  I know this is simple just a simple little
thing that any of you can do at will when needed.   I think it would make a
nice addition to misc.e  A sort of tool to make some types of programming
easier.  In the mean time I will build and use it when needed.

OH,  I also think that array(0, {8, 10}) is more readable because of the
declaration isn't reversed.

        Lucius L. Hilley III
        lhilley at cdc.net
+----------+--------------+--------------+
| Hollow   | ICQ: 9638898 | AIM: LLHIII  |
|  Horse   +--------------+--------------+
| Software | http://www.cdc.net/~lhilley |
+----------+-----------------------------+

new topic     » topic index » view message » categorize

2. Re: array(0, {800,600}) is easier.

Lucius,

I wouldn't be surprised if I am woefully misunderstanding something really
basic, but it seems to me that neither your "repeat" example nor your array
function yield the 8x10 array you want.  Doesn't  "repeat(repeat(0,10), 8)"
give  a sequence of TEN zeroes, repeated 8 times, instead of the 8 zeroes
repeated 10 times you show in your example?

Ditto for your array function when I run it & display it with smart_print.
Looks to me like "for A = length(dimensions) to 1 by -1 do" should be "for A
= 1 to length(dimensions) do" ?

Dan Moyer


-----Original Message-----
From: Lucius L. Hilley III


>Assume that you want a sequence of 8x10.  Maybe it is a sprite or FONT. :)
>IE:
>sequence s
>s = {
>     {0,0,0,0,0,0,0,0},
>     {0,0,0,0,0,0,0,0},
>     {0,0,0,0,0,0,0,0},
>     {0,0,0,0,0,0,0,0},
>     {0,0,0,0,0,0,0,0},
>     {0,0,0,0,0,0,0,0},
>     {0,0,0,0,0,0,0,0},
>     {0,0,0,0,0,0,0,0},
>     {0,0,0,0,0,0,0,0},
>     {0,0,0,0,0,0,0,0}
>    }
>
>--or currently we may use:
>s = repeat(repeat(0,10), 8)
>
>Notice that the dimension definitions are reversed to get the desired
>arrangement.
>This can easily lead to programming confusion.
>
>function array(object obj, sequence dimensions)
>  object x
>
>  x = obj
>  for A = length(dimensions) to 1 by -1 do
>    x = repeat(x, dimensions[A])
>  end for
>  return x
>end function
>
>now you can use:
>s = array(0, {8,10})
>
>OR what the subject states.  I know this is simple just a simple little
>thing that any of you can do at will when needed.   I think it would make a
>nice addition to misc.e  A sort of tool to make some types of programming
>easier.  In the mean time I will build and use it when needed.
>
>OH,  I also think that array(0, {8, 10}) is more readable because of the
>declaration isn't reversed.
>
>        Lucius L. Hilley III
>        lhilley at cdc.net
>+----------+--------------+--------------+
>| Hollow   | ICQ: 9638898 | AIM: LLHIII  |
>|  Horse   +--------------+--------------+
>| Software | http://www.cdc.net/~lhilley |
>+----------+-----------------------------+

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

3. Re: array(0, {800,600}) is easier.

In the words of the great Homer Simpson. "DOH!"
It should have been repeat(repeat(0,8),10)--No reversal
Similarly it should be.

function array(integer filler, sequence dimensions)
  object x

  x = filler
  for A = 1 to length(dimensions) do
    x = repeat(x, dimensions[A])--corrected before sent to listserv
  end for

  return x
end function

The mixed up version of the routine, that I cooked up the first time,
properly served my purposes.  I guess that is why I didn't notice I had done
it all wrong.  Bells should have gone off when I tried to reverse it because
I knew I was handling the data backwards and then it would not work. :)

------Thanks again Dan.

        Lucius L. Hilley III
        lhilley at cdc.net
+--------------+--------------+
| ICQ: 9638898 | AIM: LLHIII  |
+--------------+--------------+
| http://www.cdc.net/~lhilley |
+-----------------------------+

----- Original Message -----
From: "Dan B Moyer" <DANMOYER at prodigy.net>
To: "Euphoria Programming for MS-DOS" <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Thursday, May 11, 2000 7:27 AM
Subject: Re: array(0, {800,600}) is easier.


> Lucius,
>
> It seems to me that neither your "repeat" example nor your array
> function yield the 8x10 array you want.

   <SNIP>

> Dan Moyer
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu