1. Programmatic use for 'type'

While coding some data conversion routines this week I realized that it was
possible to use Euphoria 'type' routines in the whole process. Essentially
the type routines contain code to convert the single parameter and add the
new value to a public variable ( which will eventually contain all converted
elements). Each individual parameter to be converted is automatically passed
through the 'type' code when an empty procedure with the corresponding types
in its parameter list is called. There are some boundaries to observe: no
native types will work, all calls to the 'type' must return 1 on exit and
updating the public variable must be managed in each 'type' . In my code I
have a global function that calls each empty procedure as required - this
function could be omitted and instead the public variable be returned on
exit from the/an empty procedures(now functions - and not empty!)

Below is some dummy code to demonstrate:

Feedback is welcome.

Yours Truly
Mike

vulcan at win.co.nz

-------------------------------------------------------
-- example 1
-- NMEA.e convert NMEA sentences into Euphoria sequence
--
include get.e

with type_check -- this line must not be moved or altered
without warning

object NMEASENTENCE -- this is the public variable

integer ERROR -- error flag


type FLOAT (sequence x)
object c c=value(x)    -- code conversion here
if c[1]=GET_SUCCESS then
  c=c[2]
  if atom(c) then   NMEASENTENCE &= c -- PV updated here
  else   ERROR += 1  end if
end if
return 1
end type

-- other types can be put here say CHAR, STRING etc..

procedure APAconvert
(CHAR a, CHAR b, FLOAT c, CHAR d, CHAR e, CHAR f, CHAR g, FLOATINT h, CHAR
i, STRING j)
end procedure

-- other 'empty' procedures can go here

global function ConvertNMEAsentence(sequence s)
-- will convert a 'raw' nmea sentence to euphoria specific sequence
-- if error occurs then will return 0

-- <SNIP>

if headertype=APA then
  APAconvert(s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10])

elsif headertype=APB then
  APBconvert(s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10],
s[11], s[12], s[13], s[14])

elsif headertype=BWC then......

-- <SNIP>
    return NMEASENTENCE
    end function
-------------------------------------------------------

-- example 2
-- NMEA.e convert NMEA sentences into Euphoria sequence
include get.e

with type_check -- this line must not be moved or altered
without warning

object NMEASENTENCE, junk -- this is the public variable
NMEASENTENCE = {}

integer ERROR -- error flag

type FLOAT (sequence x)
object c c=value(x)    -- code conversion here
if c[1]=GET_SUCCESS then
  c=c[2]
  if atom(c) then   NMEASENTENCE &= c -- PV updated here
  else   ERROR += 1  end if
end if
return 1
end type

-- other types can be put here say CHAR, STRING etc..

global function APAconvert -- user program will call this directly
    (CHAR a, CHAR b, FLOAT c, CHAR d, CHAR e, CHAR f, CHAR g,
    FLOATINT h, CHAR i, STRING j)
    object junk
    junk=NMEASENTENCE
    NMEASENTENCE={}
    return junk
    end function

-------------------------------------------------------

new topic     » topic index » view message » categorize

2. Re: Programmatic use for 'type'

On Fri, 25 Feb 2000 21:05:56 +1300, Mike <vulcan at WIN.CO.NZ> wrote:

>Feedback is welcome.


>-------------------------------------------------------
>-- example 1
>-- NMEA.e convert NMEA sentences into Euphoria sequence
>--
>include get.e
>
>with type_check -- this line must not be moved or altered
>without warning
>
>object NMEASENTENCE -- this is the public variable

  Mike:

  I am sorry but I have no idea of what you are trying to explain.

  I dont know what NMEA sentences are or what you are trying to do

  in your example. It might help if you used an example that is

  more generic and not so specialized. I am sure that this information

  is valuable.

  Thanks Bernie

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

3. Re: Programmatic use for 'type'

OK. So my examples are not clear. Well it serves me right for simply copying
the code I was working on. I will try to explain it in generically.

When a type routine is written (and typecheck) is on then the interpereter
will call the 'type' whenever it finds a parameter with a type of the same
name, ie:

type CHAR(object x)
.. code etc..
end type

function PrintAt(CHAR c)
-- Before any code is executed in this routine the 'c' variable is sent
-- to the CHAR type
--
-- code etc
end function

Thus a routine with several parameters will be processed in the same way,
ie:

function test(CHAR c, FLOAT f, INT i)
-- A call is made to each type routine as is named
-- in the parameter list before any other execution occurs
--void=CHAR(c)
--void=FLOAT(f)
--void=INT(i)

-- normal code
end function

Therefore my idea was to convert each var_sent_to_each_type_routine within
the actual type routine and store the result in some accessible variable.
This last variable could be then sent back to the calling routine as a list
of converted elements.

At the top level a programmer could write a single line of code to convert a
sequence of data that needed it. I suppose one use would be in the situation
where some database info required conversion to a native format but where
the information is currently in text format, ie

sequence s
s={
"Brown",
"Charlie",
"555-4567",
"20.0"
"12"
"44 Eastern Park Parade",
"Hampton",
"New jersey",
"",
""
}

type STRING etc...
type FLOAT..


function convertFromDatabaseformat(
STRING firstname,
STRING lastname,
TELEPHONENUMBER phonenumber,
FLOAT weight,
INT age,
ADDR addressfirstline,
ADDR addresssecondline,
ADDR addressthirdline,
ADDR addressfourthline,
ADDR addressfifthline
)

s=convertFromDatabaseformat(
s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10])

--s will now have the data in a native(or whateverelse) format

I hope this explains what i meant

yours truly
Mike

vulcan at win.co.nz


-----Original Message-----
From: Bernie Ryan <LockCityData at CS.COM>
To: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU>
Date: Friday, 25 February 2000 22:36
Subject: Re: Programmatic use for 'type'


>On Fri, 25 Feb 2000 21:05:56 +1300, Mike <vulcan at WIN.CO.NZ> wrote:
>
>>Feedback is welcome.
>
>
>>-------------------------------------------------------
>>-- example 1
>>-- NMEA.e convert NMEA sentences into Euphoria sequence
>>--
>>include get.e
>>
>>with type_check -- this line must not be moved or altered
>>without warning
>>
>>object NMEASENTENCE -- this is the public variable
>
>  Mike:
>
>  I am sorry but I have no idea of what you are trying to explain.
>
>  I dont know what NMEA sentences are or what you are trying to do
>
>  in your example. It might help if you used an example that is
>
>  more generic and not so specialized. I am sure that this information
>
>  is valuable.
>
>  Thanks Bernie
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu