1. pass by reference
- Posted by Bernie Ryan <xotron at localnet.com> Feb 12, 2002
- 631 views
I keep reading that you can't use pass by reference in Euphoria. That is not true. You can use pass by reference on any variable or atom or any fixed length structure. The only thing you can't pass by reference is a sequence because it is dynamic and there is no way to control the errors that would be caused by a user. The way you pass by reference is to use allocates, peeks and pokes. Bernie
2. Re: pass by reference
- Posted by Irv Mullins <irvm at ellijay.com> Feb 12, 2002
- 600 views
On Tuesday 12 February 2002 12:07 pm, Bernie Ryan wrote: > > > I keep reading that you can't use pass by reference > in Euphoria. That is not true. You can use pass by > reference on any variable or atom or any fixed > length structure. The only thing you can't pass by > reference is a sequence because it is dynamic and > there is no way to control the errors that would > be caused by a user. The way you pass by reference > is to use allocates, peeks and pokes. er...no, that's pass-by-value. If I call foo(integer x) as follows: x = 3 foo(x) ? x => 3 No matter what happens inside the mysterious foo, x is still what it was before calling the function. Even if foo sets x to 99, it's only 99 while inside the foo routine. So foo is working with a copy of x, not the real x. Pass-by_reference passes the actual variable, not a copy, so that foo(var integer x) x = 99 end x = 3 foo(x) ? x => 99 The variable IS changed within the routine, and remains changed afterward. Regards, Irv
3. Re: pass by reference
- Posted by Kat <gertie at PELL.NET> Feb 12, 2002
- 598 views
On 12 Feb 2002, at 13:26, Irv Mullins wrote: > > On Tuesday 12 February 2002 12:07 pm, Bernie Ryan wrote: > > > > > > I keep reading that you can't use pass by reference > > in Euphoria. That is not true. You can use pass by > > reference on any variable or atom or any fixed > > length structure. The only thing you can't pass by > > reference is a sequence because it is dynamic and > > there is no way to control the errors that would > > be caused by a user. The way you pass by reference > > is to use allocates, peeks and pokes. > > er...no, that's pass-by-value. > If I call foo(integer x) as follows: > > x = 3 > foo(x) > ? x => 3 > > No matter what happens inside the mysterious foo, x is still what it was > before calling the function. > Even if foo sets x to 99, it's only 99 while inside the foo routine. > So foo is working with a copy of x, not the real x. > > Pass-by_reference passes the actual variable, not a copy, so that > foo(var integer x) > x = 99 > end > > x = 3 > foo(x) > ? x => 99 > > The variable IS changed within the routine, and remains changed afterward. This has been useful in the past, mostly to jump thru hoops in strong typing and other such diversions. I don't know how useful it would be for me in Eu now, but i am not against it, it could attract users as much as the goto could. Likewise the users of ref-passing could write interesting "features" into their programs. However, if the suggestion below is introduced, another whole world could open to Ai and gamers and maybe thread interaction options............ I still have a suggestion (you just *knew* i would, now didn't you?), if we get into passing pointers to the actual var (whether global or local to the calling function), make the pointers a user-accessable table (pronounce "sequence") containing all the variables in use at the time. The table should contain the name of the var, and the pointers one would pass for each var. If this doesn't exist now, it would prolly slow Eu a bit, so being able to switch on/off the updating of the table would be a plus. I could then see someone using this info in a really really really useful IDE, where one could modify the vars while stepping thru the program, set flags/breaks on when the vars change, trace who changed them in the IDE, etc. etc... in addition to the program being able to know what it knows vs what it doesn't know, which is a problem in Ai. Also, the table would be useful for a function like: function monitor_myvar(object var) if equal(var.name,"albatross") then if (var.val > "landing") then scream("crashlanding!!") end if end if if equal(var.name,"abort") then -- code to try a recovery end if -- a loop follows, naturally: if equal(var.name,breakvar.*.name) then if (var.val > breakvar.*.setpoint) then -- alert the IDE to begin stepping end if end if end function on_varchange(monitor_myvar(^albatross)) Kat
4. Re: pass by reference
- Posted by Irv Mullins <irvm at ellijay.com> Feb 12, 2002
- 612 views
On Tuesday 12 February 2002 01:48 pm, Bernie Ryan wrote: > > atom addr_of_x > addr_of_x = allocate(4) > > > foo(var integer x) > > x = 99 > > end > > procedure foo(atom addr_of_x) > poke4(addr_of_x,99) > end procedure > > > foo(x) > > ? x => 99 > > foo(addr_of_x) > ? peek4u(addr_of_x) => 99 So now we have Euphoria with pointers. The worst of both worlds. I'm beginning to like C more and more. Regards, Irv
5. Re: pass by reference
- Posted by kbochert at ix.netcom.com Feb 12, 2002
- 614 views
-------Phoenix-Boundary-07081998- Hi Irv Mullins, you wrote on 2/12/02 10:26:37 AM: >If I call foo(integer x) as follows: > >x = 3 >foo(x) >? x => 3 > >No matter what happens inside the mysterious foo, x is still what it was >before calling the function. >Even if foo sets x to 99, it's only 99 while inside the foo routine. >So foo is working with a copy of x, not the real x. > >Pass-by_reference passes the actual variable, not a copy, so that >foo(var integer x) > x = 99 >end > >x = 3 >foo(x) >? x => 99 > >The variable IS changed within the routine, and remains changed afterward. > >Regards, >Irv In my implementation, pass-by reference is accomplished by the caller. That is: procedure foo (sequence x) x = x[2..3] end procedure sequence s = "test" foo (s) -- s still equals "test" foo (!!s) -- s now equals "es" Library routines can never do something behind your back. The other not-so-minor detail is that only sequences can be passed by reference. I have never heard of a language doing it this way and intrigued by the possibilities. Karl -------Phoenix-Boundary-07081998---
6. Re: pass by reference
- Posted by Kat <gertie at PELL.NET> Feb 12, 2002
- 603 views
On 12 Feb 2002, at 14:10, Irv Mullins wrote: > > On Tuesday 12 February 2002 01:48 pm, Bernie Ryan wrote: > > > > atom addr_of_x > > addr_of_x = allocate(4) > > > > > foo(var integer x) > > > x = 99 > > > end > > > > procedure foo(atom addr_of_x) > > poke4(addr_of_x,99) > > end procedure > > > > > foo(x) > > > ? x => 99 > > > > foo(addr_of_x) > > ? peek4u(addr_of_x) => 99 > > So now we have Euphoria with pointers. > The worst of both worlds. I see your point, maybe. Ideally, the pointer should be available natively, but the reading/writing of the variable should go thru the existing checking. I wouldn't want to be allowed to crash the puter by assigning a 2gig sequence to an integer. > I'm beginning to like C more and more. ewwwwwwww Kat
7. Re: pass by reference
- Posted by tone.skoda at siol.net Feb 20, 2002
- 594 views
----- Original Message ----- From: <bensler at mail.com> > Why on EARTH do I want to type check my variables only to make my > program crash 'elegantly', albeit better than the current alternative(no > type checks). With type checking your code fails sooner (when it would fail any way only at some other place) and you are closer to the source of your problem. You find out what's wrong in less time. Faster debugging. Same with assert in C.
8. Re: pass by reference
- Posted by petelomax at blueyonder.co.uk Feb 20, 2002
- 576 views
On Wed, 20 Feb 2002 15:41:23 +1100, Derek Parnell <ddparnell at bigpond.com> wrote: >The other thing you might want to add is the ability to detect at run time, >whether or not a >variable has been initialized. OTOH.. Suppose I am building result_set but then something semi-catastrophic happens which invalidates everything about result_set, maybe we should not even have been building result_set, we suddenly realise it is a condition_set or something. Therefore we should uninitialise(result_set) so that if any other part of the program tries to reference it, it should cause a trap (to be fair, the interpereter would have to report different errors to avoid confusion). Just a thought, doubt any milage in it, - might it have useful application in a multi-threaded environment? Pete
9. Re: pass by reference
- Posted by petelomax at blueyonder.co.uk Feb 21, 2002
- 592 views
On Thu, 21 Feb 2002 02:13:34 +0000, bensler at mail.com wrote: > >I think you misunderstood, > > The question was not "Why would I want to use typechecking", but "why >would I want to use typechecking to make my program crash" for testing purposes (only) >Typechecking would make more sense if we could modify the variable in >question. Alot of the times, you would be able to change the variable >being typechecked to a default value. This would save your program from >crashing. Hmmm............. (lots of hmms) > >As a customer who purchases software, I would be appalled to run a >program that I paid money for, to have it crash with some error message >that doesn't help me at all. Reminds me of Microsoft :P Are you happier if a program you purchased crashes and burns, or if it does not perform as advertised/is not fit for task? If I spend say 2 hours typing in stuff & the program crashes and burns, losing all my stuff, then I am NOT HAPPY. If I spend say 2 hours typing in stuff & the program either pops up some drivel warning or simply wipes all the stuff I was doing, then I am not just "NOT HAPPY", I am seething with rage at the useless c*** who coded this c*** and spotted a few error cases and then did f*** all but s*** about it, the lazy ****ing **** **** ******* piece of ****. I''l show the **** what ****ing ***** his mother and father ***** ***** ***** ** *** ***** usless *** of a **** can do. If the type check fails so you save loads & loads of stuff for possible recovery, then good on ya, but if you're gonna write code that says 'This should never be 9. I don't care how, why or at all, so I'll just set it back to a nice safe 0", then **** you. >It makes alot more sense to at least ATTEMPT to rectify the problem >before resorting to the BLACK screen of death. As above, I fail to see how hiding the cause of the problem can possibly help. If you suspect there is going to be a problem modifying variable x then why not make it a private variable in a new include file with all the routines, checks etc to modify it? >Let's face it. EVEN IF you write a program that is 100% error free, it's >>usually the user who is the cause of the error. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!. **** YOU!. If that is not an open admittance, what the hell is? > And if I'm distributing >a program, I want to be sure that I can minimize any program/user >errors. Try testing it then > >There are lots of other uses for typechecks that can mutate it's >variable. > <snip> >There are about 50 or more routines in exotica which take a color >parameter. That's about 50 lines or more of mundane code to type and >make typing mistakes in. > >If I could mutate the variable from a type check, all I would need is >a type defined like this: > >type color(object c) > if sequence(c) then c = make_rgb(c) end if > return 1 >end type That's reasonable, however if you wrap your routines: procedure setColour(object c) xsetColour(mapcolour(c)) end procedure then all is well. >> With type checking your code fails sooner (when it would fail any way >> only >> at some other place) and you are closer to the source >> of your problem. You find out what's wrong in less time. Faster >> debugging. Correct. Pete
10. Re: pass by reference
- Posted by Kat <gertie at PELL.NET> Feb 21, 2002
- 588 views
On 22 Feb 2002, at 0:39, petelomax at blueyonder.co.uk wrote: > If I spend say 2 hours typing in stuff & the program either pops up > some drivel warning or simply wipes all the stuff I was doing, then I > am not just "NOT HAPPY", I am seething with rage at the useless c*** > who coded this c*** and spotted a few error cases and then did f*** > all but s*** about it, the lazy ****ing **** **** ******* piece of > ****. I''l show the **** what ****ing ***** his mother and father > ***** ***** ***** ** *** ***** usless *** of a **** can do. Am i to assume you despise sex and women so much, you are a gay priest, and this rant is to promote celibacy? Kat
11. Re: pass by reference
- Posted by Everett Williams <rett at gvtc.com> Feb 22, 2002
- 579 views
Chris, Only one small point. There is no error recovery in Eu, because there is no trapping. All code in Euphoria is defensive. One must write checking code for every possible error( a thing that one quickly realizes is not possible in static data handling and flat unreasonable when handling dynamic data ). Without some form of error trapping, we are reduced to after-the-fact debugging of each error. If we knew how to or could practically check all errors before they happened, we would probably have a program so large that it would not be practical to run or maybe even program. We would also be prescient, and I can think of lots of better uses for that talent than programming...take me to the race track and let me start buying lotto tickets. A language without some form of error trapping makes even debugging a very difficult task. With error trapping, I can make a test run, logging each error that I find. Then I can examine that log and deal with a whole group of errors at once rather than have to debug and restart after each error. The other problem with such sequential bug chasing is that each fix has the possibility of creating or enhancing or hiding other errors, further complicating the process. Everett L.(Rett) Williams rett at gvtc.com bensler at mail.com wrote: > > <SNIP> > >>for testing purposes (only) >> > > Currently, yes, that's all that typechecks are good for. > > <SNIP> > >>>As a customer who purchases software, I would be appalled to run a >>>program that I paid money for, to have it crash with some error message >>>that doesn't help me at all. Reminds me of Microsoft :P >>> > > This was a fairly inaccurate statement. As is, a program can have > extensive error checking AND recovery if wanted. It's just alot of code. > With typechecks that modify, one could typically reduce the error > checking/recovery code by half if not more. This makes the code more > readable, leading to less errors, leading to faster development time. > And makes reading 6 month old code alot easier. Getting the code written > faster also usually means more time for testing. > Writing error checking routines is also boring. When I'm bored, I'm less > productive. > Error recovery is even more tedious. > > >>Are you happier if a program you purchased crashes and burns, or if it >>does not perform as advertised/is not fit for task? >> >>If I spend say 2 hours typing in stuff & the program crashes and >>burns, losing all my stuff, then I am NOT HAPPY. >> >>If I spend say 2 hours typing in stuff & the program either pops up >>some drivel warning or simply wipes all the stuff I was doing, then >> > I > >>am not just "NOT HAPPY", I am seething with rage at the useless <SNIP> >> > > If someone writes an error recovery routine that doesn't fully recover > from the error, that's the programmers fault, not the language. > > Obviously, someone shouldn't write a recovery routine that resets a > spreadsheet database to DEAFULT. That's just STUPID, and that programmer > should be shot. > > >>If the type check fails so you save loads & loads of stuff for >>possible recovery, then good on ya, but if you're gonna write code >>that says 'This should never be 9. I don't care how, why or at all, so >>I'll just set it back to a nice safe 0", then **** you. >> >> >>>It makes alot more sense to at least ATTEMPT to rectify the problem >>>before resorting to the BLACK screen of death. >>> >>As above, I fail to see how hiding the cause of the problem can >>possibly help. If you suspect there is going to be a problem modifying >>variable x then why not make it a private variable in a new include >>file with all the routines, checks etc to modify it? >> > > YOU just answered your own question. A new include file, ALL the > routines/checks, etc.. > > Not only is it ALOT more code, it's harder to follow AND harder > implement. > > <SNIP> > >>>If I could mutate the variable from a type check, all I would need is >>>a type defined like this: >>> >>>type color(object c) >>> if sequence(c) then c = make_rgb(c) end if >>> return 1 >>>end type >>> >>That's reasonable, however if you wrap your routines: >> >>procedure setColour(object c) >>xsetColour(mapcolour(c)) >>end procedure >> >>then all is well. >> > Wrap what? There is nothing to wrap. > > This is what is currently in exoticaX: > global function clear_surface(object col) > if sequence(col) then col = make_rgb(col) end if > return c_func(CLEAR_SURFACE,{col}) > end function > > This is what you propose?: (slightly easier to read, but also slightly > slower) > global function clear_surface(object col) > col = setColor(col) <snip> > > >
12. Re: pass by reference
- Posted by Everett Williams <rett at gvtc.com> Feb 23, 2002
- 583 views
Sorry folks, that last was aimed only at Chris. I didn't even realize it had posted to the list until Kat told me. I have EU stuff filtered to it's own folder. My apologies again. Everett L.(Rett) Williams rett at gvtc.com
13. Re: pass by reference
- Posted by Derek Parnell <ddparnell at bigpond.com> Feb 23, 2002
- 592 views
----- Original Message ----- From: <bensler at mail.com> To: "EUforum" <EUforum at topica.com> Subject: RE: pass by reference > > No offense to you Everett, but I'm tired of lobbying. > > Euphoria *has the potential to be* the best language I have found. > However, it still feels like basic to me. It's not going anywhere very > fast. Rob hasn't expressed much interest in expanding the language. I > didn't get into programming to discuss compiler language development, > and I didn't pick up euphoria so I could write libraries which most > people consider essential. > > Sure, there is the RDS archives, which is packed full of great stuff, > but I don't have or want to spend the time to explore each lib and > program to see if it has the routines I'm looking for anymore. The least > that RDS could do, if it's not going to add to the language, is > offically support essential and proven libraries. > Which OOP library should I use if I want to use classes? Where's the > string library? Why isn't asm.e shipped with euphoria? Where's > peek/poke2? Where is the standard c_struct library? Why hasn't RDS added > link_dll(), link_func(), and link_proc() to DLL.E? > > I've been using euphoria for about 2 years now, so I know the answer > to most of these questions, but even with what I know, I am constantly > finding useful libraries that I didn't before, and spent days writing > for myself. Not too many people are so dedicated. > > Stamping is one way, but it doesn't seem to be utilized very > effectively. There should be a list of recommended libraries, sorted by > category and demand. > > Also, we should be able to filter the archives by stamped files, and > sort by money donated(popularity). > > > Rob, > I know you are only one person, and it's very difficult, if not near > impossible to foster a project of this magnitude on your own, but that's > why I think you need to reevaluate your vision of euphoria, as well as > consider staffing a development team. > Don't have the money to employ anyone? Consider offering royalties from > future sales. It's a good incentive for calculated development, and will > encourage the developers to try harder to do better as well. > I'm sure there are people on this list who would help for free, if only > to see euphoria succeed and floruish. > I too think that moderation and mediation are essential to develop the > language to it's fullest, but there comes a time when you need to > compromise. Reducing the price of your product should be a huge > indication of your progress. > > I'm not even concerned if ANY of my suggestions make it into the > language or your marketing strategies, but you need to do SOMETHING. In > the very least, you need to outline your plan for euphoria's future, so > people know what to expect and can make suggestions based on what your > stated priorities are. There are a lot of extremely talented people in > this community making excellent suggestions, and they seem to be not > only unnoticed, but ignored. > > I will continue to use Euphoria, and hope for it's success, but at > this rate, like Irv, I will most likely migrate to a more productive > language. The only real reasons I am still here, is because would like > to see euphoria do well, and because I love a challenge. Probably more > the latter, because as selfish as it may sound, I have nothing to gain > by promoting and lobbying for euphoria. I'm sure I will be more than > challenged by C/C++. > > This sounds an awful lot like a rant. To a degree it is. But moreover, > I think I speak for alot of people. People who are on this list, people > who have already left the euphoria community, and people who have yet to > discover euphoria. > Chris, over the last few days now I've been exploring the "new" language called D. If you are interested in C/C++ then it might be worthwhile keeping an eye out for what is happening to D. (www.digitalmars.com). It is trying to be a better C++ by dropping some (only some) of the silly things in C/C++. It is including some of the things we find in Euphoria like dynamic arrays (sequences) and some of the things we'd like to see in Euphoria (associative arrays, true compiler, and many others). However, like Euphoria, it is a one man development "team" so you might end up still knocking your head against a brick wall. I've decided to not get involved in D because it is still to C-centric for my tastes. ------ Derek.
14. Re: pass by reference
- Posted by Kat <gertie at PELL.NET> Feb 23, 2002
- 581 views
On 24 Feb 2002, at 7:45, Derek Parnell wrote: > > > ----- Original Message ----- > From: <bensler at mail.com> > To: "EUforum" <EUforum at topica.com> > Sent: Saturday, February 23, 2002 7:57 PM > Subject: RE: pass by reference > > > > No offense to you Everett, but I'm tired of lobbying. > > > > Euphoria *has the potential to be* the best language I have found. > > However, it still feels like basic to me. It's not going anywhere very > > fast. Rob hasn't expressed much interest in expanding the language. I > > didn't get into programming to discuss compiler language development, > > and I didn't pick up euphoria so I could write libraries which most > > people consider essential. > > > > Sure, there is the RDS archives, which is packed full of great stuff, > > but I don't have or want to spend the time to explore each lib and > > program to see if it has the routines I'm looking for anymore. The least > > that RDS could do, if it's not going to add to the language, is > > offically support essential and proven libraries. > > Which OOP library should I use if I want to use classes? Where's the > > string library? Why isn't asm.e shipped with euphoria? Where's > > peek/poke2? Where is the standard c_struct library? Why hasn't RDS added > > link_dll(), link_func(), and link_proc() to DLL.E? > > > > I've been using euphoria for about 2 years now, so I know the answer > > to most of these questions, but even with what I know, I am constantly > > finding useful libraries that I didn't before, and spent days writing > > for myself. Not too many people are so dedicated. > > > > Stamping is one way, but it doesn't seem to be utilized very > > effectively. There should be a list of recommended libraries, sorted by > > category and demand. > > > > Also, we should be able to filter the archives by stamped files, and > > sort by money donated(popularity). > > > > > > Rob, > > I know you are only one person, and it's very difficult, if not near > > impossible to foster a project of this magnitude on your own, but that's > > why I think you need to reevaluate your vision of euphoria, as well as > > consider staffing a development team. > > Don't have the money to employ anyone? Consider offering royalties from > > future sales. It's a good incentive for calculated development, and will > > encourage the developers to try harder to do better as well. > > I'm sure there are people on this list who would help for free, if only > > to see euphoria succeed and floruish. > > I too think that moderation and mediation are essential to develop the > > language to it's fullest, but there comes a time when you need to > > compromise. Reducing the price of your product should be a huge > > indication of your progress. > > > > I'm not even concerned if ANY of my suggestions make it into the > > language or your marketing strategies, but you need to do SOMETHING. In > > the very least, you need to outline your plan for euphoria's future, so > > people know what to expect and can make suggestions based on what your > > stated priorities are. There are a lot of extremely talented people in > > this community making excellent suggestions, and they seem to be not > > only unnoticed, but ignored. > > > > I will continue to use Euphoria, and hope for it's success, but at > > this rate, like Irv, I will most likely migrate to a more productive > > language. The only real reasons I am still here, is because would like > > to see euphoria do well, and because I love a challenge. Probably more > > the latter, because as selfish as it may sound, I have nothing to gain > > by promoting and lobbying for euphoria. I'm sure I will be more than > > challenged by C/C++. > > > > This sounds an awful lot like a rant. To a degree it is. But moreover, > > I think I speak for alot of people. People who are on this list, people > > who have already left the euphoria community, and people who have yet to > > discover euphoria. > > > > Chris, > over the last few days now I've been exploring the "new" language called D. If > you are interested in C/C++ then it might be worthwhile keeping an eye out for > what is happening to D. (www.digitalmars.com). It is trying to be a better C++ > by dropping some (only some) of the silly things in C/C++. It is including > some > of the things we find in Euphoria like dynamic arrays (sequences) and some of > the things we'd like to see in Euphoria (associative arrays, true compiler, > and > many others). However, like Euphoria, it is a one man development "team" so > you > might end up still knocking your head against a brick wall. I'd really hate to see all the people here who i look up to wander off to other languages. I think there is difference in viewpoint tween Rob and the programmers. Rob wants to keep his long term vision of Eu intact, and the programmers who are here want to use it to solve programming problems. The more problems Eu can solve for them, the more they will use it. But Eu may not stay the same as Rob intended 10 yrs ago. Re the string lib question, i am still adding to strtok.e, even tho most of the original code written by Gabriel Boehme will stay in there some way, in some form. As i see a need i have for it to perform, i add it. I also have one strtok2.e that will break all existing code, but it's smarter, you pass it {whatever,somemore,anotherthing,etc} and it figures out what to do with it. The advantage is you can call whatevertok() with a preparsed strings, they have a short memory, parms can be optional, etc. Anyhow, i am still in the Eu camp. The program that was eating memory is at 18hrs running, and seems stable at 199megs and using all otherwise idle cpu cycles. It still bugs me that it's using so much memory..... [00:26] <kat> i can see where loading all the files into memory for Tiggr might take a gig of ram someday [00:26] <[Tiggr]> sorry kat, I don't know. [00:27] <kat> i don't know now either, Tiggr [00:27] * Moonschild looks at tiggr [00:27] * [Tiggr] hides shyly ) Kat
15. pass by reference
- Posted by Tyrone Faulkner <tyrone at idx.com.au> Mar 10, 2003
- 602 views
Is it possible to pass by reference when calling a procedure or do I have to declare the appropriate variables (objects) as global? Tyrone
16. Re: pass by reference
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 10, 2003
- 614 views
----- Original Message ----- From: "Tyrone Faulkner" <tyrone at idx.com.au> To: "EUforum" <EUforum at topica.com> Subject: pass by reference > > Is it possible to pass by reference when calling a procedure or do I > have to declare the appropriate variables (objects) as global? > Yes and No. You can't do it by using the variable's name. You can do by passing a index to the variable. In general, the only way that two or more routines can reference the same variable name, is if they share the same scope. Here one way that it can be done. It's not pretty and you have to wonder if its worth the effort. sequence PBR PBR = {} constant kTax = 1, kComment = 2, kState = 3, kAmount = 4 sequence vWHTRate vWHTRate = {0.15, 0.125, 0.0125, 0.175, 0.30, 0.56, 0.10} procedure WithholdingTax(integer pCustomer) integer lRateIdx lRateIdx = find(PBR[pCustomer][kState], {"vic","qld","nsw","wa","sa,"tas","nt"}) if RateIdx != 0 then PBR[pCustomer][kTax] = PBR[pCustomer][kAmount] * vWHTRate[lRateIdx+1] PBR[pCustomer][kComment] = sprintf("WHT %2.1f%%", vWHTRate * 100) end if end procedure procedure AddCust() sequence lNewCust lNewCust = repeat(0,4) lNewCust[kTax] = 0.0 lNewCust[kComment] = "" lNewCust[kState] = "vic" lNewCust[kAmount] = 17.43 PBR = append(PBR,lNewCust) -- Pass the customer by reference (sort of) WithHoldingTax( length(PBR) ) end procedure ---------------- cheers, Derek Parnell
17. Re: pass by reference
- Posted by Tyrone Faulkner <tyrone at idx.com.au> Mar 11, 2003
- 593 views
Hi Derek, I declared all the common variables at the top of the file and it works like a dream. Actually this was the best solution as it would have been too much fiddling around to send them as parameters because of the quantity. Also each procedure uses most of the variables anyway. It is very quick. The program reads a 7mb comma delimited ascii file, summarizes and writes out to another file (about 3.5mb). All I can say is - a great piece of software. Although I think I will install one of the other editors to speed up productivity. Regards, Tyrone. ----- Original Message ----- From: "Derek Parnell" <ddparnell at bigpond.com> To: "EUforum" <EUforum at topica.com> Sent: Tuesday, March 11, 2003 8:19 AM Subject: Re: pass by reference > > ----- Original Message ----- > From: "Tyrone Faulkner" <tyrone at idx.com.au> > To: "EUforum" <EUforum at topica.com> > Sent: Tuesday, March 11, 2003 12:40 AM > Subject: pass by reference > > > > Is it possible to pass by reference when calling a procedure or do I > > have to declare the appropriate variables (objects) as global? > > > > Yes and No. You can't do it by using the variable's name. You can do by > passing a index to the variable. > > In general, the only way that two or more routines can reference the same > variable name, is if they share the same scope. > > Here one way that it can be done. It's not pretty and you have to wonder if > its worth the effort. > > sequence PBR PBR = {} > constant kTax = 1, kComment = 2, kState = 3, kAmount = 4 > sequence vWHTRate > vWHTRate = {0.15, 0.125, 0.0125, 0.175, 0.30, 0.56, 0.10} > procedure WithholdingTax(integer pCustomer) > integer lRateIdx > > lRateIdx = find(PBR[pCustomer][kState], > {"vic","qld","nsw","wa","sa,"tas","nt"}) > > if RateIdx != 0 then > PBR[pCustomer][kTax] = PBR[pCustomer][kAmount] * > vWHTRate[lRateIdx+1] > PBR[pCustomer][kComment] = sprintf("WHT %2.1f%%", > vWHTRate * 100) > end if > end procedure > > procedure AddCust() > sequence lNewCust > > lNewCust = repeat(0,4) > lNewCust[kTax] = 0.0 > lNewCust[kComment] = "" > lNewCust[kState] = "vic" > lNewCust[kAmount] = 17.43 > > PBR = append(PBR,lNewCust) > > -- Pass the customer by reference (sort of) > WithHoldingTax( length(PBR) ) > end procedure > > > ---------------- > cheers, > Derek Parnell > > > > TOPICA - Start your own email discussion group. FREE! > >