Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #45365
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: local variable |
| Date | 2016-02-08 16:09 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <n9aejb$g3f$1@dont-email.me> (permalink) |
| References | <5504c7af$0$2974$426a74cc@news.free.fr> <meb11d$jve$1@dont-email.me> |
WJ wrote:
> grobibi wrote:
>
> > Hello,
> > There is something I don't understand with local variable with gforth.
> > A variable defined like this :
> >
> > variable x 10
> >
> > will have a general scope. How can I get a
> > local scope for a variable inside a word definition ? Is it possible ?
> >
>
> Oforth:
>
> x is the local variable.
>
> func: pair-with-squares(list)
> {|x| list map( #[ -> x [x, x x *]])}
>
>
> > [2,3,4] pair-with-squares println
> [[2, 4], [3, 9], [4, 16]]
> ok
> > pair-with-squares([5,6,7,8]) println
> [[5, 25], [6, 36], [7, 49], [8, 64]]
> ok
For OFORTH version V0.9.23.1:
: pair-with-squares(list)
|x| list map( #[ -> x [x, x x *]]) ;
> [2,3,4] pair-with-squares .
[[2, 4], [3, 9], [4, 16]] ok
> pair-with-squares([5,6,7,8]) println
[[5, 25], [6, 36], [7, 49], [8, 64]]
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Re: local variable "WJ" <w_a_x_man@yahoo.com> - 2016-02-08 16:09 +0000
csiph-web