Re: Namespaces
- Posted by Irv <irv at ELLIJAY.COM> Oct 24, 2000
- 694 views
On Tue, 24 Oct 2000, Fam. Nieuwenhuijsen wrote: > Yes, but I just don't want variable names to get any longer than they > already are. I don't want the filename as part of the variable name. Look: > > include foo.py do > def x as x > def y as y > def foo_circle as circle > end include > > foo_circle (3, 6) Hi Ralf: Actually, I think I prefer the way Py handles the imports - it assures that items that were designed as part of a package remain obviously connected to that package. Optionally re-naming only bits and pieces could get really confusing. However, I do agree with your point about writing long variable names: Therefore the suggestion that we be allowed a "block prefix" notation: with foo do x = 3 -- this is foo.x y = 5 -- foo.y circle() -- foo.circle ..... end foo > > Secondly, you should only be able to import global variables. Local > variables are "hands-off". Otherwise there is no way to lock an include, and > the type of errors and issues you have to deal with. No way. As far as I know, there are no "local" variables, except for those inside routines. Anything declared outside a routine is fair game to be imported. I don't see that as being a big problem, but you could be right. Perhaps there should be a "local" block, wherein any variables would be visible only to routines in that one file. > > for i in 10 > > > > is probably too much of a hack, though. And not very clear in its meaning, either. > > > - Where is the { left, middle, right } = my_func () notation ? > > > > An example, please? > > { eof_status, value } = get (0) eof_status, value = get(0) -- no curly brackets required around the left-hand This is one of the best features, as far as I am concerned. It lacks one thing, which I have discussed with Dave: yr, mo, da = date() -- won't currently work, because date() returns 8 items. --m, d, y, hr, min, sec, dow, doy My suggestion was to warn, but not prohibit, partial assignments. A more useful alternative would be slicing function calls: i.e: hr, min, sec = date()[4..6] which I think may be possible. > Yes, but what if there is NO result ? Are you forced to return an result ? I > prefer functions & procedures, without enforcing the end user to use the > return value, but also without enforcing the routine to return a value. If there is no result, you just don't return one. Example: def foo() puts(1,"Hello") end def foo() Hello def foo() return "Hi" end def foo() -- nothing happens msg = foo() ? msg "Hi" Regards, Irv