1. Why Types?

Can Euphoria be a scripting or shorthand lanaguage?
consider this;
 in EUPHORIA;
 integer s
s=rand(100)

in QBasic;
a%  = INT(RND * 100)

In this dummy Qbasic statement %A = int(RND) , %A is an integer type yet
we still had to declare the value of (RND) as an INT type , duh...
(some BASIC will let you do "%A=5" but others make you "defTYPE")

Before you can use a variable most "languages"
 Require/Demand that you;
  1. declare the type
  2. assign a value
For short hand  or scripting language this is
just not needed.

 in JAVAscript;
 VAR  D="yes"    ;   assigns VALUE and indirectly declares TYPE

To make Euphoria "user friendly" why not "ASSUME object"

>From what I see ( I am very new to euphoria) anything that is a sequence
can be an integer or string...?big question mark
if I change
 integer s          to ;   sequence s
  s=65                   ;   s=65                 --doe it not work?

No it does not ,  I get ;  type_check failure, s is 65'A'
if I attempt a 1 element array  or sequence will it work?
s=(65)
puts(1,s[1])  ; No again, it will not . ok try object?

object s
s=65
yes it works  ie.. "? S"-outputs 65 and "puts(1,s)" outputs A

Can it handle "any" arbritary assignment?
s=a65       no
s=(A 65)    no
s=("A" 65) no
s can not be both 65 and A in Euphoria?
( I think the manual says that too, atoms are numeric only)

You should be able to declare TYPE and METHOD in the way
You choose to implement it .. ie s=A and 65  then s=65 for numeric
expressiona and s= A for text expression. Is this "forward referencing?"
if A=900  not a printable charactor ,then I could understand.
I would expect Ex.err to say  "s TYPE 900 is invalid TEXT", but only
if I attempt to "use" it as TEXT.

Its at this point I entered "point" into GURU (very handy ! )
but all I get is mouse pointer and c_pointer info but there is one mention
under
"performance" about euphoria using pointers in sequence type structures...
but from the reference manual I get;
 "Euphoria does not have pointers and does not need them." ? blink blink

I kinda like the fact that a number can be a value OR the pointer to a
value,
I even like assembly's 0100h or [0100h].

Can I PEEK a pointer? i = peek(A) .A is a linear address or seg:reg type?
I just have a problem with basic's use of peek , maybe this one is better.
Anyone upto speed on using peek ? help... (yet another learning curve)

new topic     » topic index » view message » categorize

2. Re: Why Types?

On Wed, 13 Dec 2000 08:08:57 -0500, John wrote:

>From what I see ( I am very new to euphoria) anything that is a sequence
>can be an integer or string...?big question mark

A sequence contains objects, (which can be atoms, integers, or sequences).
If it contains integers that are printable ANSI characters, then you might
think of it as a string (even though it's just a sequence of numbers that
represent characters).

>if I change
> integer s          to ;   sequence s
>  s=65                   ;   s=65                 --doe it not work?
>
>No it does not ,  I get ;  type_check failure, s is 65'A'
>if I attempt a 1 element array  or sequence will it work?
>s=(65)
>puts(1,s[1])  ; No again, it will not . ok try object?

s=65 does not work if s is declared as a sequence because 65 is an atom
(more specifically, an integer)

likewise, s=(65) is the same as s=65 because (65)=65

but if you had said
s={65} (notice curley brackets, not parentheses) then you would *not* get
an error.
puts(1,s) would print the character 'A'

>object s
>s=65
>yes it works  ie.. "? S"-outputs 65 and "puts(1,s)" outputs A
>
>Can it handle "any" arbritary assignment?
>s=a65       no

not unless a65 is an already-defined variable or constant

>s=(A 65)    no

you aren't using the correct notation (parentheses instead of curley
brackets, and no commas separating elements)

if s is declared to be an object, then
s = {'A',65} would be OK. this is the same as s = {'A','A'} or s = {65,65}

>s=("A" 65) no
>s can not be both 65 and A in Euphoria?
>( I think the manual says that too, atoms are numeric only)

s = {"A",65} would be OK this is the same as
s = {{'A'},65} which is the same as
s = {{65},65}


>Can I PEEK a pointer? i = peek(A) .A is a linear address or seg:reg type?
>I just have a problem with basic's use of peek , maybe this one is better.
>Anyone upto speed on using peek ? help... (yet another learning curve)

Yes, 'peek' is usually used to fetch data from a pointer when working with
C data structures.  There are plenty of examples of this usage in Win32Lib.

Hope I cleared up some data type confusion for you.

-- Brian

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

3. Re: Why Types?

Hi John,

Most built-in Euphoria built-in functions and procedures work on either
atoms or sequences. Personally, I tend to write code that treats atoms and
one-element sequences the same (so essentially, I have eliminated atoms and
"everything's a sequence"), but I consider this somewhat experimental, and
to a certain extent it may be a function of the particular application I'm
writing. In other words, it might make less sense in other contexts.

Type checking helps prevent subtle errors in programs.

My personal philosophy, based on more than decade of experience producing
commercial software, is that *clarity* is the most important quality a
program can have. If the author is perfectly clear on what the program, and
each component thereof (down to the level of individual statements), must BE
and DO, and if the program presents its functionality in a clear and
"intuitive" manner to the user, and the documentation is clear and explicit,
then "magically" everything works !!! and everyone is happy !!!

Any language feature that promotes clarity is a good one, in my book. I
think Euphoria's definition of type does that, without being overly
restrictive.

Try programming in a typeless language, a strongly-typed one, and a
loosely-typed one. Doubtless you will find situations in which any given
approach is advantageous. Euphoria's type system is very flexible. I like
it.

George Henry

----Original Message Follows----
From: John
Reply-To: Euphoria Programming for MS-DOS
To: EUPHORIA at LISTSERV.MUOHIO.EDU
Subject: Why Types?
Date: Wed, 13 Dec 2000 08:08:57 -0500
Can Euphoria be a scripting or shorthand lanaguage?
consider this;
in EUPHORIA;
integer s
s=rand(100)
in QBasic;
a% = INT(RND * 100)
In this dummy Qbasic statement %A = int(RND) , %A is an integer type yet
we still had to declare the value of (RND) as an INT type , duh...
(some BASIC will let you do "%A=5" but others make you "defTYPE")
Before you can use a variable most "languages"
Require/Demand that you;
1. declare the type
2. assign a value
For short hand or scripting language this is
just not needed.
in JAVAscript;
VAR D="yes" ; assigns VALUE and indirectly declares TYPE
To make Euphoria "user friendly" why not "ASSUME object"
>From what I see ( I am very new to euphoria) anything that is a sequence
can be an integer or string...?big question mark
if I change
integer s to ; sequence s
s=65 ; s=65 --doe it not work?
No it does not , I get ; type_check failure, s is 65'A'
if I attempt a 1 element array or sequence will it work?
s=(65)
puts(1,s[1]) ; No again, it will not . ok try object?
object s
s=65
yes it works ie.. "? S"-outputs 65 and "puts(1,s)" outputs A
Can it handle "any" arbritary assignment?
s=a65 no
s=(A 65) no
s=("A" 65) no
s can not be both 65 and A in Euphoria?
( I think the manual says that too, atoms are numeric only)
You should be able to declare TYPE and METHOD in the way
You choose to implement it .. ie s=A and 65 then s=65 for numeric
expressiona and s= A for text expression. Is this "forward referencing?"
if A=900 not a printable charactor ,then I could understand.
I would expect Ex.err to say "s TYPE 900 is invalid TEXT", but only
if I attempt to "use" it as TEXT.
Its at this point I entered "point" into GURU (very handy ! )
but all I get is mouse pointer and c_pointer info but there is one mention
under
"performance" about euphoria using pointers in sequence type structures...
but from the reference manual I get;
"Euphoria does not have pointers and does not need them." ? blink blink
I kinda like the fact that a number can be a value OR the pointer to a
value,
I even like assembly's 0100h or [0100h].
Can I PEEK a pointer? i = peek(A) .A is a linear address or seg:reg type?
I just have a problem with basic's use of peek , maybe this one is better.
Anyone upto speed on using peek ? help... (yet another learning curve)
_____________________________________________________________________________________
Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu