1. Euphoria types of the POLL
Peter Robinson explicit asked to post comments outside of the POLL thread
and to that I am posting the comments here.
Peter Robinson wrote:
> Variation A2:
>
> type customer( sequence x )
> fields
> integer x[1] id
> sequence x[2] name
>
> Variation B2:
>
> type customer( sequence x )
> fields
> integer id -- x[1] is assumed
> 4. Regardless of your answer to the previous question:-
>
> (a) which variation do you prefer? {ANSWER A2 or B2]
>
> (b) would you support the introduction of both together?
> [ANSWER YES OR NO]
>
Does A2 allow you to put arbitrary expressions like
java methods?
For example:
type customer( sequence x )
fields
integer x[1] id
sequence x[2] name
sequence x[3] address
sequence x[2] & x[3] nameAndAddress
end fields
end type
> 5. Regardless of your previous answers, if syntax with naming were introduced,
> would you prefer the elements in an object declarded with this type to be
> accessible
> by:- [ANSWER a or b]
>
> (a) dot access e.g. customer_x.name; or
>
> (b) subscript/indexes e.g. customer_x[name]
>
As long as 'name' is of a limited bracket scope I would be happy. I think
5b may be more flexible. This is what C++ and Java has over EUPHORIA. We
have to declare big scope integer constants like D_NAME which function as
field names and therefore
we need to prepend things like D_ and hope they are not taken already.
This proposed change will mean a lot less constant declarations as
well as shorter field names. As long as the scope is more limited.
What happens inside the brackets? Is name of global scope or will there be
a special bracket scope that only goes for indexing a instance of that type
where name is declared in the field.
object x1
customer customer_x
customer_x[name] = "Sam"
x1[name] = "Who" -- should give an error message
sequence name -- Is there a problem now?
Can we do things like customer_x[name..$] or customer_x[name+1]?
Will name conflict with name space outside? Will I be unable to
use a variable called name?
Right now if you declare 'boolean b' the interpreter will take that
as meaning 'call boolean( b ) each time b changes.' Assuming you
have defined type boolean( ) somewhere in your program. I would
extend this as follows:
Allow type to have more than one argument as the arguments preceeding
the last would all be routine ids to other types.
type map( integer keytype_t, integer itemtype_t, sequence x )
...
end type
Then you could declare several maps like:
map of sequences and integers nametoAgeMap
array of maps of integers and sequences OtherStructure
If the interpreter could take things like
'array of integers ai'
as to mean 'Call array( ai, routine_id("integer") ) on each change'
If a type routine declaration could also accept other routine ids as
extra arguments and the type syntax handling could be modified as just
described then you keep more code of in the .e files and less in the
interpreter backend and have even more flexibility:
type array( atom typeid, object x )
if not sequence(x) then return 0 end if
for i = 1 to length(x) do
if not call_func( typeid, {x[i]} ) then
return 0
end if
end for
return 1
end type
type map( atom preimaget, atom imaget, sequence s )
fields
sequence keys
sequence items
end fields
for i = 1 to length(s) do
if not call_func( preimaget, {s[keys][i]} ) or not call_func( imaget,
{s[items][i]} ) then
return 0
end if
end for
return 1
end type
array of customers customer_list
map of sequences and integers name_to_customer_index_lookup_table
Shawn Pringle
2. Re: Euphoria types of the POLL
- Posted by Hayden McKay <hmck1 at d?do.com.?u>
Sep 02, 2007
-
Last edited Sep 03, 2007
Could you show me how you would define a nested sequence, or an object pls
ie:
type this(object x) ; where x could be an atom or sequence
type that(sequence s) ; where s is an array of nested sequences and atoms
3. Re: Euphoria types of the POLL
Shawn wrote:
Peter Robinson wrote:
> Variation A2:
>
> type customer( sequence x )
> fields
> integer x[1] id
> sequence x[2] name
>
> Variation B2:
>
> type customer( sequence x )
> fields
> integer id -- x[1] is assumed
> 4. Regardless of your answer to the previous question:-
>
> (a) which variation do you prefer? {ANSWER A2 or B2]
>
> (b) would you support the introduction of both together?
> [ANSWER YES OR NO]
>
Shawn wrote at this point:
>>Does A2 allow you to put arbitrary expressions like
>>java methods?
>>For example:
>> type customer( sequence x )
>> fields
>> integer x[1] id
>> sequence x[2] name
>> sequence x[3] address
>> sequence x[2] & x[3] nameAndAddress
>> end fields
>>end type
The simple answer is NO, the last field above is not a variation within the
questions. Of course, adding sequence x[4] nameAndAddress would be OK, but you
would have to perform any concatenation action or test separately.
I know Java (or thought I did!) but I had difficulty working out what your
variation - sequence x[2] & x[3] nameAndAddress - was intended to represent in
Java. I thought you meant this Euphoria equivalent, which could be added to the
type block:-
if not equal( nameAndAddress, name & address ) return false
but even in that example, surely you would want to add spaces or other
delimiters between the two strings.
Or do you mean:-
sequence of sequence nameAndAddress
Your example has the expression on the LHS of a declaration, which is confusing
me a little. Do you intend it to mean:-
test for concatentation
or
perform concatentation when initialising
or
perform concatentation at some other time ????
Initialising variables is another question. It's not in the poll.
The poll questions primarily address declaring elements inside a sequence in the
same way as they are declared outside a sequence (obviously, a form of
identification of the elements, either implicit or explicit must be added or
assumed).
The poll said:
> 5. Regardless of your previous answers, if syntax with naming were introduced,
> would you prefer the elements in an object declarded with this type to be
> accessible
> by:- [ANSWER a or b]
>
> (a) dot access e.g. customer_x.name; or
>
> (b) subscript/indexes e.g. customer_x[name]
>
Shawn wrote:
>> As long as 'name' is of a limited bracket scope I would be happy. I think
>> 5b may be more flexible. This is what C++ and Java has over EUPHORIA. We
>> have to declare big scope integer constants like D_NAME which function as
>> field names and therefore
>> we need to prepend things like D_ and hope they are not taken already.
>> This proposed change will mean a lot less constant declarations as
>> well as shorter field names. As long as the scope is more limited.
>> What happens inside the brackets? Is name of global scope or will there be
>> a special bracket scope that only goes for indexing a instance of that type
>> where name is declared in the field.
>> object x1
>> customer customer_x
>> customer_x[name] = "Sam"
>> x1[name] = "Who" -- should give an error message
>> sequence name -- Is there a problem now?
>> Can we do things like customer_x[name..$] or customer_x[name+1]?
>> Will name conflict with name space outside? Will I be unable to
>> use a variable called name?
I think the questions leave this open for discussion and future polling if
necessary. On the one hand, you could say, why allow named subsripts within a
type block unless they are limited to that type? On the other hand, you could
say, we now allow named constants outside the type block that are actually only
intended to apply to a particular type of object, with no syntax (other than
comments or some naming convention like the one you suggest) to distinguish them.
So there are issues either way. But those issues may become irrelevant if the dot
notation is preferred.
Shawn, your remaining post relates to ideas going beyond the current poll, so
I'll leave it to others to respond to those. In running the poll I try not to mix
my own views with the form of the questions. I hope the comments above clarify
where possible.
Regards
Peter Robinson
4. Re: Euphoria types of the POLL
Hayden McKay wrote:
>
> Could you show me how you would define a nested sequence, or an object pls
>
> ie:
> type this(object x) ; where x could be an atom or sequence
> type that(sequence s) ; where s is an array of nested sequences and atoms
Hi Hayden
The first variation is not specifically covered by the questions, so it would be
open for others to argue a different usage, BUT I think the same issue arises
here as with the "sequence of sequence" syntax.
The purpose of the syntax in the poll is to declare elements within a sequence.
So the base object must be a sequence. If the object could be either an atom or a
sequence, then you can't "declare" its elements to have a particular type or
name, since it may not have any.
In the second example, assuming the sequence of sequence syntax is implemented,
you could do this:-
type that( sequence of sequence x ) -- or
type array( sequence of sequence x )
If you wanted to constrain the array in some other way, you would need to add
code within the type block. The poll questions don't affect that.
If you wanted the base type to be a UDT array defined elsewhere, the same issues
wuld arise as with allowing a UDT on the LHS of an "of" expression, which I
commnented on in my "Postscript" to the last poll. Neither poll addresses this
issue, so it is open for you to argue it and perhaps make it the subject of a
future poll. The questions in the poll are limited to the idea of typing and/or
naming subscripts of an object of base type sequence.
I hope this clarifies.
Regards
Peter Robinson
5. Re: Euphoria types of the POLL
Hi Shawn
It took me a while, but I figured out what you meant by this syntax:
sequence x[2] & x[3] nameAndAddress
I guess you are saying you want it to work like a class method, called by the
identifier x[nameAndAddress] (or dot notation) and returning a concatentation of
x[name] and x[address].
Class methods are certainly outside the scope of the poll and the discussion on
which the poll was based.
Your reference to "expressions" in Java confused me because expressions in Java
class declarations represent initialisation code, not methods. As far I know,
Java doesn't provide any method shorthand like the one you propose for Euphoria,
does it? You would have to declare and define the method in its own block.
Also, such syntax seems confusing in the context because in the previous 2
lines, x[2] and x[3] identify elements you want to declare by type and name,
whereas in the line above, the type and name attach to something else (a method
which I presume you intend to put in x[4] - not sure on that), and the x
references are an expression to be evaluated. I wonder how this would parse, but
it's outside the current poll in any event.
Cheers
Peter Robinson
6. Re: Euphoria types of the POLL
I have another idea, not releated to the the question though.
maybee rob should consider something like this:
-- define some standard euphoria types
type myInteger (integer i) return integer (i) end type
type myAtom (atom a) return atom (a) end type
type mySequence (sequence s) return sequence(s) end type
-- now here's the idea
global record myArray -- create a namespace called myArray
age as myInteger -- define some fields for da myArray
name as mySequence
other as myAtom
end record
-- now myArray could be accessed like this with full typecheck
myArray:name = "Hayden" -- assign some variables
myArray:age = 28
? myArray:name -- print them to screen
? myArray:age
footnotes:
Labels defined inside the record should be private, that means that
access to record variables like so would be illegal...
? myArray[1] -- should generate an illegal error
? myArray[name] -- should generate an illegal error
name = 1 -- generate attempt to redefine 'name' error
7. Re: Euphoria types of the POLL
Hayden McKay wrote:
>
> Could you show me how you would define a nested sequence, or an object pls
>
> ie:
> type this(object x) ; where x could be an atom or sequence
> type that(sequence s) ; where s is an array of nested sequences and atoms
For my proposed syntax you would need to have multiple arguments for type.
What you are describing to me are objects and sequences which are already
defined in EUPHORIA. These would simply be object() and sequence()
respectively. Why would you want to define another name for them?
Shawn Pringle
8. Re: Euphoria types of the POLL
Shawn wrote:
>
> Hayden McKay wrote:
> >
> > Could you show me how you would define a nested sequence, or an object pls
> >
> > ie:
> > type this(object x) ; where x could be an atom or sequence
> > type that(sequence s) ; where s is an array of nested sequences and
> > atoms
>
> For my proposed syntax you would need to have multiple arguments for type.
> What you are describing to me are objects and sequences which are already
> defined in EUPHORIA. These would simply be object() and sequence()
> respectively. Why would you want to define another name for them?
>
> Shawn Pringle
I think you missed my point here, check out my previous post, it explains better
the idea of creating objects by linking types...
Here is link to the post: http://www.openeuphoria.org/EUforum/m16476.html
9. Re: Euphoria types of the POLL
Hayden McKay wrote:
>
> I have another idea, not releated to the the question though.
> maybee rob should consider something like this:
> }}}
<eucode>
>
> -- define some standard euphoria types
>
> type myInteger (integer i) return integer (i) end type
> type myAtom (atom a) return atom (a) end type
> type mySequence (sequence s) return sequence(s) end type
>
You lost me straightaway. I cannot see why you would need or want to do that.
> -- now here's the idea
>
> global record myArray -- create a namespace called myArray
>
> age as myInteger -- define some fields for da myArray
> name as mySequence
> other as myAtom
>
> end record
>
Why would that differ from (say):
record myArray
integer age
sequence name
atom other
end record
Were you to introduce a new "record" construct, the compiler could deduce
exactly the information wanted, without any need to "wrap" the builtin types or
introduce a new "as" syntax. This seems no different to fiddling with the "type"
construct as discussed in the recent poll (variation B2) and remains a pitifully
poor imitation of OOEU-style classes.
Am I mising something here?
Regards,
Pete
10. Re: Euphoria types of the POLL
Pete Lomax wrote:
>
> Hayden McKay wrote:
> >
> > I have another idea, not releated to the the question though.
> > maybee rob should consider something like this:
> > }}}
<eucode>
> >
> > -- define some standard euphoria types
> >
> > type myInteger (integer i) return integer (i) end type
> > type myAtom (atom a) return atom (a) end type
> > type mySequence (sequence s) return sequence(s) end type
> >
> You lost me straightaway. I cannot see why you would need or want to do that.
>
I do this on a regular basis, because atom() and friends don't have a
routine_id().
CChris
[snip]
>
> Regards,
> Pete
11. Re: Euphoria types of the POLL
- Posted by Hayden McKay <hmck1 at dod?.com.?u>
Sep 11, 2007
-
Last edited Sep 12, 2007
This post seemed to have confused some people, I'll try to explain better, but
first please review my previous post here...
Hayden McKay wrote:
>
> I have another idea, not releated to the the question though.
> maybee rob should consider something like this:
> }}}
<eucode>
>
> -- define some standard euphoria types
>
> type myInteger (integer i) return integer (i) end type
> type myAtom (atom a) return atom (a) end type
> type mySequence (sequence s) return sequence(s) end type
>
> -- now here's the idea
>
> global record myArray -- create a namespace called myArray
>
> age as myInteger -- define some fields for da myArray
> name as mySequence
> other as myAtom
>
> end record
>
> -- now myArray could be accessed like this with full typecheck
>
> myArray:name = "Hayden" -- assign some variables
> myArray:age = 28
>
> ? myArray:name -- print them to screen
> ? myArray:age
>
> </eucode>
{{{
>
> footnotes:
> Labels defined inside the record should be private, that means that
> access to record variables like so would be illegal...
> }}}
<eucode>
>
> ? myArray[1] -- should generate an illegal error
> ? myArray[name] -- should generate an illegal error
>
> name = 1 -- generate 'name' not defined error
>
> </eucode>
{{{
Useing the above for a reference, the 'record' myArray is an 'object'
hence...
? myArray -- produces -> {28,"Hayden",1.1}
-- actualy, note that in the previous post myArray:myAtom has not been
-- defined so..
? myArray -- produces -> myArray:myAtom not defined error
are you following me here ?
further more, note that 'records' would be 'object'
hence...
global record myVar
junk as integer
end record
myVar:junk = 1
? myVar -- produces -> 1
-- variable myVar is an integer 'cause that's the only definition in
-- that record
-- however if we had...
global record myVar
junk as integer
this as integer
end record
-- then 'myVar' would be a sequence consisting of 2 intergers
myVar:junk = 1
myVar:this = 1
? myVar -- produces -> {1,1}
I hope this better explained my idea of linking types useing namespace
there would probably be a few hurdles trying to implement it, but it's
only an amusing idea