[OpenBIOS] Fwd: [PATCH] Adds local variable support to OpenBIOS.

Programmingkid programmingkidx at gmail.com
Sun Sep 2 03:32:19 CEST 2012


On Sep 1, 2012, at 7:51 PM, openbios-request at openbios.org wrote:

> Message: 2
> Date: Fri, 31 Aug 2012 13:40:58 -0500
> From: Tarl Neustaedter <tarl-b2 at tarl.net>
> To: The OpenBIOS Mailinglist <openbios at openbios.org>
> Subject: Re: [OpenBIOS] Fwd: [PATCH] Adds local variable support to
> 	OpenBIOS.
> Message-ID: <5041053A.90303 at tarl.net>
> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
> 
> On 2012-Aug-31 09:50 , Programmingkid wrote:
>> 
>> Are you saying my-variable is better than myVariable?
> 
> Yes.

I have changed all my code from camelCase to hyphens. 

> 
>> How do global variables get you in trouble in recursion? Do you have 
>> an example?
> 
> Not off-hand, we learn to avoid doing that. To construct one - let's 
> take a method doing recursion properly, and break it:
> 
> \ Correct way, using stack manipulation
> : fibonacci ( fib -- return ) recursive
>    dup 2 >= if                 ( fib )
>       dup 1- fibonnaci         ( fib fib-1 )
>       swap 2 - fibonnaci       ( fib-1 fib-2 )
>       +                        ( fib )
>    then                        ( fib )
> ;
> 
> \ Incorrect way - using variable "fib", which will get overwritten 
> during recursion
> 0 value fib;
> : fibonnaci ( fib -- return ) recursive
>    to fib \ to avoid stack manipulation
>    fib 2 < if
>       fib exit
>    then
>    fib 1- fibonnaci           ( fib-1)
>    fib 2 - fibonnaci          ( fib-1 fib-2 )
>    +                          ( fib )
> ;

There is nothing to worry about. All the global variables in my code are only used at compile- time - not during runtime. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openbios.org/pipermail/openbios/attachments/20120901/3f2e6203/attachment.html>


More information about the OpenBIOS mailing list