1. RE: namespace coflicts: local vs private symbols

Hello Matt,

If you check out your code carefully, i dont think you will
find this to be a namespace error?
You havent applied a value to x in the PRIVATE procedure,
so the P() function fails, not the last "?x".

I thought something was strange here because im pretty sure
i used that idea several times in programs.

I'll check it again after setting x equal to some value first
in the procedure.

Take care,
Al

new topic     » topic index » view message » categorize

2. RE: namespace coflicts: local vs private symbols

Al Getz wrote:
> Hello Matt,
> 
> If you check out your code carefully, i dont think you will
> find this to be a namespace error?
> You havent applied a value to x in the PRIVATE procedure,
> so the P() function fails, not the last "?x".
> 
> I thought something was strange here because im pretty sure
> i used that idea several times in programs.
> 
> I'll check it again after setting x equal to some value first
> in the procedure.
> 
> Take care,
> Al
> 
> 
Sorry, this last post was in reply to "Lewis Townsends' " post,
not one of Matt's.

BTW, the following two lines of code never works in Euphoria:

sequence x
x=x+1

but only because x wasnt assigned a value yet.

Take care,
Al

new topic     » goto parent     » topic index » view message » categorize

3. RE: namespace coflicts: local vs private symbols

Hello Al,

> If you check out your code carefully, i dont think you will
> find this to be a namespace error?

I know its not a namespace error. Eu only looks for variables until it 
finds one. Then if that variable dont have a value then it returns an 
error rather than continuing to look for another variable of the same 
name (but of different scope). The issue is NOT that the given code 
SHOULD work, it is that there is no way to access the local variable 
within the scope of the private variable... not even as the first 
assignment of the private one. The private variable completely blocks 
the local variable. I just think that there should be SOME way to access 
that local var. Not that the code I gave should pass without error. 
Perhaps the following example would be a suitable alternative:

sequence x
x = {0,0,0,0}
procedure p ()
	sequence x
	x = local:x + 1
	? x
end procedure
? x
p ()
? x

later
Lewis Townsend

new topic     » goto parent     » topic index » view message » categorize

4. RE: namespace coflicts: local vs private symbols

Hi again Lewis,


Lewis Townsend wrote:
> Hello Al,
> 
> sequence x
> x = {0,0,0,0}
> procedure p ()
> 	sequence x
> 	x = local:x + 1
> 	? x
> end procedure
> ? x
> p ()
> ? x
> 
> later
> Lewis Townsend
> 
> 

Ahhh! That clarifies the question a bit smile

But, as long as you dont mind renaming the local "x" to
"Local:x" (which doesnt seem like a bad idea really)
then you also wont mind the following solution:


sequence x
x = {0,0,0,0}

function Get_x()
  return x
end function

procedure p ()
sequence x
x = Get_x() + 1
? x
end procedure
? x
p ()
? x


Good luck with it,
Al

new topic     » goto parent     » topic index » view message » categorize

5. RE: namespace coflicts: local vs private symbols

Derek Parnell wrote:

> 
> I kinda do this renaming as a naming convention of mine.
> ... Variables scoped to a routine begin with 'l'  (local)
> ... Variables scoped to the file begin with 'v'   (variable)
> ... Varaibles scoped to global begin with 'g' (global)
> 
> I've been using this convention for about 15 years with some success.
> Thus I'd code...
> 
>   sequence vx
>   vx = {0,0,0,0}
>   
>   function Get_x()
>     return vx
>   end function
>   
>   procedure p ()
>   sequence lx
>   lx = Get_x() + 1
>   ? lx
>   end procedure
>   ? vx
>   p ()
>   ? vx
>   
> 

That's a pretty good idea.

I started doing some of the global vars Global_VarName
myself, and although it takes a bit longer to type
"Global" with the "_" too it sure does clarify a program
when you go to read it over again a year or two later smile
so i know what you are talking about there.

My biggest problems with variable naming conventions comes in
with some seemingly simple tasks:
sequence 
  FileName or Filename, or even filename ?

I always want to type Filename, when FileName is probably most
appropriate.

I tryed once to reserve the first letter as upper case 
to indicate a sequence (and lower case to indicate an atom
or integer) but it's just too hard to do that when other
naming priorities come up.

I usually reserve the underscore "_" for more important things
especially things like buttons, windows, edit controls, etc. :
atom
Button_LoadFile, 
Window_MainWin,
Edit_Amount, Edit_Balance,
etc.

Although it does take longer to type the full name
like "Button_" it always tells me immediately what
kind of thing im accessing.
I've stuck with this even when im in a hurry because it's just
too handy when you go to read the code over several years later.

I do like the (rather) new naming convention for include files,
such as 
include myclass.ew as ClassOne

This is going to be MOST beneficial to most of the programming i 
do in the future with Euphoria, especially with 'plug in' type
files.
The only thing i have to get used to is that the 'as' name isnt 
visible to any other file, it's only visible to the file
it's declared in.  I guess this is a good thing though, because
it allows one to restrict the visibility much better, rather then 
be stuck with having the names automatically visible throughout the
whole program.  It's only a little inconvenience to have to include
them in all the other files in case you do want to use them there 
also.
Would be interesting to have a 'global include x as y' i guess.
When you want to give a second party access to your 'class'
this would make it much easier for them.

Take care,
Al

new topic     » goto parent     » topic index » view message » categorize

6. RE: namespace coflicts: local vs private symbols

I don't think this proposal is wise enough. First, I know of no other
language supporting
it (maybe some of you do). Second, I think a routine should not be dependent
on things external to
it. Third, it seems difficult to implement, because after sequence x is
declared, to know if x has a previous value will entail going backwards in
the symbol chain, also with negative effects in performance. Fourth, if you
add an option to specify "local" or "external" variables, then the routine
will depend on the environment in which it is executed, and consequently
will be difficult to transport to other programs.
Regards.
----- Original Message -----
From: Lewis Townsend <Keroltarr at hotmail.com>
Subject: namespace conflicts: local vs private symbols


>
> Hello Robert, all,
>
> I may be addressing an old issue here but just a thought for future
releases
> of Eu:  With the (relatively) new namespacing abilities of Euphoria you
can
> differentiate (sp?) between conflicting global identifiers by using
> prefixes. I wish there were a similar way to identify local symbols in
> routine that has a private symbol of the same name. Here is an example
> program that doesn't work without renaming something.
>
> sequence x
> x = {0,0,0,0}
> procedure p ()
> sequence x
> x = x + 1
> ? x
> end procedure
> ? x
> p ()
> ? x
>
> I would like to see:
> {0,0,0,0}
> {1,1,1,1}
> {0,0,0,0}
>
> I get this error:
> variable x has not been assigned a value
>
> I would prefer it check the local symbol for a value before returning an
> error. An alternate handling of this situation could require a prefix such
> as "local:" or something like that.
>
> Just some thoughts here folks, any comments?
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>

new topic     » goto parent     » topic index » view message » categorize

7. RE: namespace coflicts: local vs private symbols

Nice solution, Al!
----- Original Message ----- 
From: Al Getz <Xaxo at aol.com>
Subject: RE: namespace coflicts: local vs private symbols


> 
> Hi again Lewis,
> 
> 
> Lewis Townsend wrote:
> > Hello Al,
> > 
> > sequence x
> > x = {0,0,0,0}
> > procedure p ()
> > sequence x
> > x = local:x + 1
> > ? x
> > end procedure
> > ? x
> > p ()
> > ? x
> > 
> > later
> > Lewis Townsend
> > 
> > 
> Ahhh! That clarifies the question a bit smile
> 
> But, as long as you dont mind renaming the local "x" to
> "Local:x" (which doesnt seem like a bad idea really)
> then you also wont mind the following solution:
> 
> 
> sequence x
> x = {0,0,0,0}
> 
> function Get_x()
>   return x
> end function
> 
> procedure p ()
> sequence x
> x = Get_x() + 1
> ? x
> end procedure
> ? x
> p ()
> ? x
> 
> 
> Good luck with it,
> Al
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu