1. type or func?!?
- Posted by Salix <salix at freemail.hu> Mar 02, 2005
- 492 views
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
2. Re: type or func?!?
- Posted by "Juergen Luethje" <j.lue at gmx.de> Mar 02, 2005
- 462 views
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
3. Re: type or func?!?
- Posted by Hayden McKay <hmck1 at dodo.com.au> Mar 02, 2005
- 460 views
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 > >
4. Re: type or func?!?
- Posted by cklester <cklester at yahoo.com> Mar 02, 2005
- 470 views
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/
5. Re: type or func?!?
- Posted by "Juergen Luethje" <j.lue at gmx.de> Mar 02, 2005
- 552 views
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?