Re: Eu improvements (part 3)

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

c.k.lester wrote:

> > }}}
<eucode>
> >     sequence Point is
> >         integer x, y
> >     end sequence
> >     Point.x = 5
> > 
> >     Point my_point  -- create my_point as a copy of Point
> >     ? my_point    -- => '5' 
> > </eucode>
{{{

> > The newly created sequence is initialized.
> 
> You should probably include some mechanism for defining default values,
> because really the '? my_point' command above should return something
> like { 5, ? }, where the '?' indicates the y value hasn't been initialized
> or there is no default value.
OOps! typo.
that was intended to be:
? mypoint.x    --=> '5'

I would like that the elements of a structured sequence always be
initialized (to 0, 0.0 or {})
But note that mypoint is a copy of Point and its values are the same.

> 
> }}}
<eucode>
> sequence Point is
>     integer x = 0, y = 0 -- set default values
> end sequence
> Point.x = 5
> 
> Point my_point  -- create my_point as a copy of Point
> ? my_point    -- => { 5, 0 }
> </eucode>
{{{

>
Even better, but initialization on declaration should be added, someday,
all at once, everywhere.
 
> I was also thinking about this:
> 
> }}}
<eucode>
> sequence Line is
>    point start, fini
> 
>    where
>       start != fini
>    end where
> 
> end sequence
> </eucode>
{{{

> 
> Or do you think it should be up to the application to manage that?
> It would be nice to bundle it, but I don't see how you'd manage exceptions.
> 
Interesting idea, but too advanced for the Eu community's focus on
simplicity, I think.

> }}}
<eucode>
> Line my_line
> my_line.x = {1,1}
> my_line.y = {1,1}
> </eucode>
{{{

> ex.err: Where fault for object Line
>
The assignment to my_line above would be an error because
my_line does not have an element named 'x'
my_line.start.x = 1
    my_line.start.y = 1
    -- or perhaps
    my_line.start = mypoint

Also
my_line.start = {1, 1}

is an error because '{1, 1}' is not a structured sequence.
Using {1, 1} requires 'inside knowledge' as to the layout of a Point.
Suppose the first element of a Point is a name??
Suppose you want to add a field a few years from now??

> Or use optional named where:
> 
> }}}
<eucode>
> sequence Line is
>    point start, fini
> 
>    where Is_A_Point
>       start != fini
>    end where
> 
> end sequence
> 
> Line my_line
> my_line.x = {1,1}
> my_line.y = {1,1}
> </eucode>
{{{

> 
> ex.err: Where Fault: Is_A_Point line XXX
> 
> I got to thinking about this because of the shape sequence:
> 
> sequence shape is
>    line one, two, three
> 
>    where
>       -- line one ends at line two's start
>       one.end.x = two.start.x
>       one.end.y = two.start.y
> 
>       -- line two ends at line three's start
>       two.end.x = three.start.x
>       two.end.y = three.start.y
> 
>       -- line three ends at line one's start
>       three.end.x = one.start.x
>       three.end.y = one.start.y
> 
>    end where
> 
> end sequence
> 
> It's a stricter definition of the 'type' or 'sequence.' Of course, this could
> always be managed outside the object's definition, but
> why not put it inside?
>
IMHO because we must keep it Euphoric (simple).
 
> I'm all for a structure datatype, and I think this approach is great.
> 
> One concern I have is for working with databases. If I have a table that has
> about 20 fields (this is an actual case), and I want to import a record from
> it, how could this be done best using a structured sequence?
> 
> my_record = get_db_record( 3 )
> 
> -- options
> my_record.field1 (field1, field2, etc.) -- no likey this much
> my_record.Field_Name -- better, but what about fields with spaces in them?
> my_record.'Field Name'
> my_record['Field Name'] -- very nice
> 
> etc...
Are you trying to allow the name of an element of a structured sequence
to have a space in it?? Bad idea, I think.

sequence custRecord is
        sequence name
        integer zip_code
    end sequence

    sequence custDbase

    procedure addcust(sequence name, integer zip)
        custRecord rec  -- rec is init'ed to whatever is in custRecord
        rec.name = name
        rec.zip_code = zip
        append(custDbase, rec)
    end procedure

    function get_name(integer rec_num)
        return custDbase[rec_num].name
    end function

    custRecord myrec
    myrec = custDbase[3]
    ? myrec.name
    ? get_name(3)


Note that the structured sequence is data only.(no functions are attached)
Many elaborations are possible, initializers, verifiers, properties etc
but this is a simple language -- only the basic functionality should be
provided.

KtB

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

Search



Quick Links

User menu

Not signed in.

Misc Menu