Re: Pointer work around

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

On Thu, 7 Jan 1999 09:47:27 -0600, Paul Martin <twilight at WCC.NET> wrote:

>Hello all,
>
>I still kinda interested in porting Doom to Euphoria, and overwhelming
>response was that pointers would pose a problem. Well I've enclosed a short
>C++ program that uses pointers and a ported Euphoria version.

Looks good to me. I would make a function to get the input values,
as below, to save space.

include get.e -- to handle value()

-- Code to setup structure for point
sequence point, pt1, pt2, median
constant point_x = 1, point_y = 2
point = {0,0}
pt1 = point
pt2 = point

function getMedian( sequence p1, sequence p2)
    -- set-up new structure for result
    sequence result
    result = point
    -- do the actual business
    result[point_x] = (p1[point_x]+p2[point_x])/2
    result[point_y] = (p1[point_y]+p2[point_y])/2
    return result
end function

function getXY (atom pt)
sequence xy
   xy = point
   printf(1,"Enter the X and Y coordinates for point # %d : ",pt)
   xy[point_x] = gets(0)
   xy[point_x] = value (xy[point_x])
   xy[point_x] = xy[point_x][2]
   printf(1,"%d\t",xy[point_x])

   xy[point_y] = gets(0)
   xy[point_y] = value (xy[point_y])
   xy[point_y] = xy[point_y][2]
   printf(1,"%d\n",xy[point_y])
return xy
end function

pt1 = getXY(1)
pt2 = getXY(2)
median = getMedian(pt1,pt2)
printf (1,"Mid point in (%g, %g)\n", {median[point_x],median[point_y]})

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

Search



Quick Links

User menu

Not signed in.

Misc Menu