Re: Coming From QBasic
- Posted by "Lynn Kilroy" <leks_transportation at hotmail.com> Jan 17, 2006
- 543 views
I see nothing wrong with passing an argument to a subroutine/procedure {to me, these are really the same thing}, and allowing that subroutine to alter it. In QBasic, if I said: >DECLARE SUB Inke (a AS STRING) > >SUB Inkey (a AS STRING) >a = INKEY$ >END SUB what I'm saying is Inkey requires the argument 'a,' which passes data to and can also extract data from the subroutine. If I included a local variable in that subroutine: >DECLARE SUB Inke (a AS STRING) > >SUB Inkey (a AS STRING) > >DIM Variable AS DOUBLE > >Variable = RND > >a = INKEY$ > >END SUB then Variable is only remembered by Inkey. but is never seen by the rest of the program. In this case, it is a useless excercise becuase nothing is done with it. As you say, local versus global. Also, in both cases above, the line >SUB Inkey (a AS STRING) means you *MUST* pass it an argument. That argument can be either a variable pointer or a constant hard coded as an argument. In the case of Inkey, you could pass it arguments the following way, and they would all work. >DIM KeyPress AS STRING > >Inkey KeyPress -Or- >Inkey X$ -Or- >Inkey " " The first two are variables. I never use the signed variables. Poor form, and rather tasteless to me, anymore, so the middle one is out. But I use variations of the top and bottom lines quite frequently, although in the case of Inkey, calling Inkey with " " as the argument {a hard coded constant} rather defeats the purpose. In Euphoria, the sub would look different. I'm going to use your code and take a whack at it. >Procedure Inkey(Integer Key) > Key = get_key() >End Procedure > >Integer Key > >Inkey(Key) Would this work? If not this precisely, then how would it be coded, precisely? The difference isn't so much that I use a global variable for it {Blech!} but that I pass a variable to it, and the variable is altered by the Subroutine/Procedure and then passed back to the main program {if the main program had a variable pointer in the first place}. Love & Friendship & Blessed Be! Lynn Erika Kilroy >From: "D. Newhall" <guest at RapidEuphoria.com> >Reply-To: EUforum at topica.com >To: EUforum at topica.com >Subject: Re: Coming From QBasic >Date: Mon, 16 Jan 2006 09:16:46 -0800 > > >posted by: D. Newhall <derek_newhall at yahoo.com> > >Lynn Kilroy wrote: > > > > Does the Global function thingy have to be included in the main body of >the= > > code, even if the function is in an included file? And how about the > > subroutines? How do I call them? > > > > Love & Friendship & Blessed Be! > > Lynn Erika Kilroy >(snip) > >As you've probably seen Euphoria doesn't have BASIC/COBOL style >subroutines. However, you can kind of replicate this with procedures using >global variables. > >integer key > >procedure inkey() > key = get_key() >end procedure > >inkey() > > >When you declare something as global in an include file that means that >when you include it everything declared as global becomes available in the >main file. For example: > >-- Inside some include file >constant BLAH = "stuff" > >global integer foo > >global function bar() > ... >end function > >procedure baz() > ... >end procedure > > >When this file is included foo and bar can be used in the code whereas baz >and blah can not. > > >The Euphoria Standard Library project : > http://esl.sourceforge.net/ >The Euphoria Standard Library mailing list : > https://lists.sourceforge.net/lists/listinfo/esl-discussion > > > >