1. type or func?!?

How should I define this routine? Is there any difference?

Example 1
type seq8(sequence x)
if length(x)=8 then return 1 else return 0 end if
end type


Example 2
function seq8(sequence x)
if length(x)=8 then return 1 else return 0 end if
end function


Regards,

Salix

new topic     » topic index » view message » categorize

2. Re: type or func?!?

Salix wrote:

> How should I define this routine? Is there any difference?
>
> Example 1
> }}}
<eucode>
> type seq8(sequence x)
> if length(x)=8 then return 1 else return 0 end if
> end type
> </eucode>
{{{

>
> Example 2
> }}}
<eucode>
> function seq8(sequence x)
> if length(x)=8 then return 1 else return 0 end if
> end function
> </eucode>
{{{


Yes, there is a difference, see http://www.rapideuphoria.com/refman_2.htm#43

How you should define it depends on how you want to use it.
If you *only* want to call it like this:

sequence s
integer f
s = "ABCDEFGH"
f = seq8(s)
-- or
if seq8(s) then ...

then it doesn't matter.

But if you want to use 'seq8' to declare variables, like
seq8 s
s = "ABCDEFGH"

then you must define seq8 as type.

Regards,
   Juergen

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

3. Re: type or func?!?

defining it as a type would probably be is better 'cause you can you
can use }}}
<eucode> without type_check </eucode>
{{{
 in the top level of your
prog when you want to turn type checking off. even with type chack turned
off you can still use }}}
<eucode> bool=seq8(array) </eucode>
{{{


Juergen Luethje wrote:
> 
> Salix wrote:
> 
> > How should I define this routine? Is there any difference?
> >
> > Example 1
> > }}}
<eucode>
> > type seq8(sequence x)
> > if length(x)=8 then return 1 else return 0 end if
> > end type
> > </eucode>
{{{

> >
> > Example 2
> > }}}
<eucode>
> > function seq8(sequence x)
> > if length(x)=8 then return 1 else return 0 end if
> > end function
> > </eucode>
{{{

> 
> Yes, there is a difference, see <a
> href="http://www.rapideuphoria.com/refman_2.htm#43">http://www.rapideuphoria.com/refman_2.htm#43</a>
> 
> How you should define it depends on how you want to use it.
> If you *only* want to call it like this:
> 
> }}}
<eucode>
> sequence s
> integer f
> s = "ABCDEFGH"
> f = seq8(s)
> -- or
> if seq8(s) then ...
> </eucode>
{{{

> then it doesn't matter.
> 
> But if you want to use 'seq8' to declare variables, like
> }}}
<eucode>
> seq8 s
> s = "ABCDEFGH"
> </eucode>
{{{

> then you must define seq8 as type.
> 
> Regards,
>    Juergen
> 
>

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

4. Re: type or func?!?

Salix wrote:
> 
> function seq8(sequence x)
> if length(x)=8 then return 1 else return 0 end if
> end function

this can be written:

function seq8(sequence x)
   return length(x)=8
end function

-=ck
"Programming in a state of EUPHORIA."
http://www.cklester.com/euphoria/

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

5. Re: type or func?!?

Hayden McKay wrote [quoting order re-arranged]:

> Juergen Luethje wrote:
>>
>> Salix wrote:
>>
>>> How should I define this routine? Is there any difference?
>>>
>>> Example 1
>>> }}}
<eucode>
>>> type seq8(sequence x)
>>> if length(x)=8 then return 1 else return 0 end if
>>> end type
>>> </eucode>
{{{

>>>
>>> Example 2
>>> }}}
<eucode>
>>> function seq8(sequence x)
>>> if length(x)=8 then return 1 else return 0 end if
>>> end function
>>> </eucode>
{{{

>>
>> Yes, there is a difference, see http://www.rapideuphoria.com/refman_2.htm#43
>>
>> How you should define it depends on how you want to use it.
>> If you *only* want to call it like this:
>>
>> }}}
<eucode>
>> sequence s
>> integer f
>> s = "ABCDEFGH"
>> f = seq8(s)
>> -- or
>> if seq8(s) then ...
>> </eucode>
{{{

>> then it doesn't matter.
>>
>> But if you want to use 'seq8' to declare variables, like
>> }}}
<eucode>
>> seq8 s
>> s = "ABCDEFGH"
>> </eucode>
{{{

>> then you must define seq8 as type.
>
> defining it as a type would probably be is better 'cause you can you
> can use }}}
<eucode> without type_check </eucode>
{{{
 in the top level of your
> prog when you want to turn type checking off. even with type chack turned
> off you can still use }}}
<eucode> bool=seq8(array) </eucode>
{{{


Yes, he can do so. But he can do so anyway, regardles whether his
routine is defied as type or as function. So defining it as type
isn't an advantage in this regard. It's s another point that makes
the difference, as I explained previously.

HTH,
   Juergen

-- 
A: Because it considerably reduces the readability of the text.
Q: Why?
A: Top posting.
Q: What is annoying in e-mail and news?

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

Search



Quick Links

User menu

Not signed in.

Misc Menu