1. Namespaces

----- Original Message -----
From: Irv Mullins <irv at ELLIJAY.COM>
Sent: Monday, September 27, 1999 3:55 AM
Subject: Re: little question once again


> Rob has promised that the namespace problem will next on his list of
> things to do. I have no idea how he will accomplish this, but I personally
> prefer the method you suggest - using the include file name as the prefix,
eg:
> foo.position(3.5)  bar.position(5,5)  which leads to more of an object
oriented
> approach to building programs. Not a bad thing IMHO.

Hello all,

I am sitting here reading my daily digest of all the best info on Euphoria
and very much enjoying the little discussion on the subject of "Re: little
question once again".  When Irv brings this very intriguing concept to the
surface anout include files not getting along with each other.  There is
something that we all can do to help, instead of relying on 'Rob' to solve
all the little problems.  Of course this "fix" would be the responsibility
of every one of us that cares.

You said that it would be nice if, in order to access a routine from an
include file that you had to use that files name as a prefix to the routine.
I think this sounds like a great idea although possibly cumbersome if
someone wanted to name their include file something like
'thisismyincludefileforfubar.e'.  However in the spirit of best wishes.  You
could take on the responsibility of applying the prefix process and just
name you routines in the include file with a specific prefix.

-- this is foo.e
-- the routines in this file do next to nothing
-- use them at your own risk

global constant
    foo_Nil = nil,
    foo_Max=+inf

global procedure foo_up(object anyjunk)
    anyjunk = foo_Nil        -- throw it away
end procedure

global function foo_down(object morejunk)
    morejunk = foo_Max
    return(morjunk)
end function

-- this has been an example of worthless programming
-- I claim no responsibilities whatsoever for the content or how you use it
-- thank you for your attention

Now, in order to use any of the stuff in 'foo.e' you would be forced to add
the foo_whatever prefix because that is now a part of the variable name.
Also if you do this.  Rob is not forced to make changes if he doesn't want
too.  Of course.  If that is something that he planed to do anyway..........

L8R

new topic     » topic index » view message » categorize

2. Re: Namespaces

The namespace disscusion has been a issue on the list for 2 years and

if you search the archive for old messages you will find that someone

on the list in the past has already suggested your idea. After a long

debate Rob determined that he would try to add namespaces to Euphoria.

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

3. Re: Namespaces

On Mon, 27 Sep 1999 15:28:28 +0300, Glen T. Brown
<gbrown at SAUDIONLINE.COM.SA> wrote:

>When Irv brings this very intriguing concept to the
>surface anout include files not getting along with each other.  There is
>something that we all can do to help, instead of relying on 'Rob' to solve
>all the little problems.  Of course this "fix" would be the responsibility
>of every one of us that cares.
>

First, this isn't a little problem. It is central to the future of the
language.

>You said that it would be nice if, in order to access a routine from an
>include file that you had to use that files name as a prefix to the
routine.

My preference is to allow "named" includes to keep the prefixes short. These
might be something of the order of

include foo=foo_this_name_is_to_long_to_easily_use.e

very much like a globally declared constant, which in reality, it is. Now
everything gets prefixed with foo. To prevent the build up of includes
recursively calling includes, the interpreter can strip off the prefix and
compare file names to prevent multiple copies of an include being loaded.
This would require aliasing when the same variables and routines were called
with different prefixes, but scoping will take care of most of the real
problems in this area. Some of Ralf's ideas on scoping of variables in
includes could also be used here. I'm running out of gas on this one :) but
leaving it entirely to the programmers to stay out each others' way is
likely to cause a great deal of trouble in the future.

Everett L.(Rett) Williams
rett at gvtc.com

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

4. Namespaces

<html><div style='background-color:'><DIV>
<P>In the first place I would like to thank Don Phillips for being so helpful
and participative&nbsp;in this list. His windows scroll routine was just what I
needed.&nbsp;&nbsp;Congratulations!<BR></P>
<P>Regarding the namespace problem I have always the following one:</P>
<P>DLL.E has NULL defined as global.</P>
<P>WIN32LIB&nbsp;&nbsp;has it defined too.</P>
<P>How can I avoid receiving an error message without editing any of the files?
How could the local definition helpme avoid this problem? I think this problem
has happend to many of the list members. How do you solve it? All my directories
are filled with edited local copies of win32lib in every version released.</P>
<P>Thanks. </P>
<P>Feliz Navidad y próspero año nuevo! (Merry Christmas and happy -prosperous-
new year!)</P>
<P>Carlos Valdés</P>
<P><BR>&nbsp;</P></DIV>
<DIV></DIV>
<DIV></DIV><FONT face=arial,helvetica>

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

5. Namespaces

-------Phoenix-Boundary-07081998-

My vote goes for the simple "include file as F" syntax which is simple to 
use and backward -compatible. However there are 2 fine points which don't 
seem to have been mentioned yet.

1) Namespaces should not be referenced with the dot operator! The dot 
operator is more or less standardized across languages to reference members 
of objects, structures and sometimes arrays. It is not necessary or 
desirable for Euphoria to buck this trend. In a similar way, the colon 
operator generally refers to namespaces (as in C++ or XML).
EX ------------
  include file.e as F
  ...
  F:x =3D 1	-- set the x defined in file.e to 1
---------------
 Euphoria may wish, someday, to use '.' for objects!  

2) Even when a file has been included 'as X', it should still be possible 
to reference its globals without decoration, as long as the reference does 
not conflict with another global.
EX 1------------
  include stack.e as ST
  ..
  a =3D ST:pop ()	-- call the pop function in stack.e
  b =3D pop ()		-- the only 'pop' is in stack.e, so it is called

EX 2--------
  include stack.e as ST
  function pop () --		local function

  b =3D pop()		-- local
  a =3D ST:pop()	-- must use 'ST:' to get to stack's version
------------
  The basic rule is that ':' is a scope resolution operator. Its use is 
only necessary where scope must be resolved. When it is not used, normal 
scope resolution takes place, (local, file, then global) and normal error 
messages are generated.

Karl Bochert

-------Phoenix-Boundary-07081998---

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

6. Namespaces

I have been watching the discussion on namespaces, and thinking about the
problems involved, from the standpoint of a user (as opposed to the
standpoint of an implementor).  I find that I am in agreement with those
whose namespacing proposals leave defining the identity of the namespace in
the control of the _user_ of a module, rather than in the _creator_ of the
module, or the file-system (i.e., taking the namespace identity from the
file name).  This is because...

1. ...if control is left to the creator of the module, all we have done is
moved back one level with respect to the problem that namespace creation is
intended to solve - that of collision of names.  By placing control of the
namespace identity in the hands of the user of the module, collision is
avoided (unless multiple modules may be imported into the same namespace).
Granted, collision is less likely, as only namespace collision stands as an
issue, rather than specific identifier collision - but a complete solution
that avoids even this level of collision is preferred over a partial
solution.

2. ...if control lies with the file system, we have the issue of needing to
make broad changes to working programs if file names change.  Such a change
may be due to a move to a different Euphoria-available environment (e.g.,
moving from Windows to DOS), or a rethinking of the proper name of a module
(as in the event of enhancement, without removing extant functionality).
The broader a change that needs to be made, the more opportunity there is
for introducing error, even with modern automated tools.  If the user
defines the namespace identity, a single change, of the name of the file
imported, is all that need be made.  For cross-environment portability, the
need for broad change can be avoided by restricting module names to eight
characters (which is the limit in DOS, the most restrictive of environments
for which Euphoria is currently available) - but this itself leads to a
need for potentially unclear or arbitrary names. Furthermore, as programs
or modules are exchanged in source form with others, it becomes
increasingly difficult to come up with useful names that avoid collision
with others - unless some other solution, such as a centralized registry,
is found.  Given past industry experience, it is unlikely that such a
centralized registry could be made to work as intended.

It is to be noted that I do not propose a specific syntax for defining a
namespace; while I have my preferences, none of the proposals heretofore
seen for user control of namespace identity are unacceptable to me.
However, I perceive direct user control over the namespace identity to be
an essential component of any proposal to implement namespaces in Euphoria.
--
Jeff Zeitlin
jzeitlin at cyburban.com
(ILink: news without the abuse. Ask via email.)

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

7. Re: Namespaces

Hello Rob,

Here is one idea that I don't think has been mentioned recently. It might 
have been in one of the garbled digests which I deleted. Here it si:

Add another namespace qualifyer: "public" or something else, the name isn't 
important to me, just the functionality. Symbols declared with this 
qualifier are only shared with files that directly include the 
file/namespace in which it is declared. Basically like global only not 
available throughout the whole program.

just my 2 cents. I like many of the other suggestions but feel this is 
neccesary.

thanks in advance,
Lewis Townsend

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

8. Namespaces

How do people prefer namespaces to behave? For example, imagine that you had
a namespace option in Euphoria like this:

   import <file> into <namespace>

that behaved like include does, but the imported code would have to be
accessed through the namespace prefix. So if you had a file like this:

   -- test.e
   global integer number

and you wrote:

   import test.e into foo
   import test.e into bar

Would you expect 'foo.number' and 'bar.number' to reference the *same*
variable, or different variables? My thinking is that it would be more along
the lines of how Euphoria currently behaves to have them refer to the same
variable. On the other hand, it's awfully convenient for each namespace to
have it's own local data, like classes.

Thanks!

-- David Cuny

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

9. Re: Namespaces

--
  David:
     I had a look at py and was very impressed with your concepts.
     I would recomend that you use the : ( colon ) for
     namespaces and reserve the . ( dot ) for future use in
     structure access notation.
  Thanks
  Bernie

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

10. Re: Namespaces

On Mon, 23 Oct 2000, David Cuny wrote:
> How do people prefer namespaces to behave? ...

>    import test.e into foo
>    import test.e into bar

Further experimentation shows that this is a much more involved question
than I at first thought. It'll take several posts to explore the possibilities,
but let's start by evaluating the simplest alternative:

As I see it, there could be a couple of reasons a programmer might
do multiple imports if references to foo and bar will point to the SAME variable
space:

1. A mistake.(forgot it was already included)

2. Obfuscation of code.
       foo.name = "Fooman"
       bar.name  = "Barman"
     ? foo.name => "Barman"

   Not something I normally do (intentionally). Besides, there's always shroud.

I see no upside to this, therefore if multiple includes are going to point to
the SAME space,  they should be prohibited.

In exploring what happens if multiple includes point to DIFFERENT instances of
the included variables, we need to examine three different areas:
stand-alone variables
sequences
routines

I have some experiments in each of these areas which I'll post individually.

Regards,
Irv

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

11. Re: Namespaces

On 23 Oct 2000, at 3:25, David Cuny wrote:

> How do people prefer namespaces to behave? For example, imagine that you had
> a namespace option in Euphoria like this:
>
>    import <file> into <namespace>
>
> that behaved like include does, but the imported code would have to be
> accessed through the namespace prefix. So if you had a file like this:
>
>    -- test.e
>    global integer number
>
> and you wrote:
>
>    import test.e into foo
>    import test.e into bar
>
> Would you expect 'foo.number' and 'bar.number' to reference the *same*
> variable, or different variables? My thinking is that it would be more along
> the lines of how Euphoria currently behaves to have them refer to the same
> variable. On the other hand, it's awfully convenient for each namespace to
> have it's own local data, like classes.

Unequivocally *different* !!! After all, if i wanted the same data, i'd not use
different
names to get to it. And if Py or Eu has a method to multitask that we haven't
discovered yet (see my previous post on multitasking,, did anyone try that for
me, or
explain why it would not work?), i would not want namespace conflicts to kill
that off.

Now, as an offshoot of this in variable naming, i have tried to write code that
would get
me the same var *in some circumstances* no matter how i asked for it:

%table.top.color
%table.color.top
%color.table.top

could all be the same, but not this:

%top.table.color
or
%color.top.table

Which got into a complicated syntax parsing for the var names, which wasn't my
point
at the time. But my point here is this, if the programmer knows what she is
writing,
and she writes foo.number() in the code, she should not get bar.number(),
especially if
we get threads, and something execs bar(), doing something totally unrelated to
foo(),
changing a local var there that foo.number's processing is/was based on. You
could
get some nasty hard.to.track bugs that way too.

Kat

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

12. Re: Namespaces

The reason I was asking about namespaces is because I think a lot of people
are looking to namespaces as a way to implement OOP in Py. I don't think
that it's that good of a fit, either in Py, or in Euphoria.

Although namespaces *could* be implemented in an OOP sort of way, that would
be inconsistant with the rest of Euphoria. My guess (and that's all it is,
an uninformed guess) is that Robert's implementation of namespace will
simply be a way to make local (non-global) objects in a file visible. At
least, this approach seems sensible to me. For example:

   -- foo.e
   integer i

   -- bar.ex
   import foo.e as stuff -- 'i' is visible as 'stuff.i'

All the namespace prefix does is make local objects visible to the importer.
Because globals have the 'side effect' of being visible to anyone after they
are declared, I don't even think they properly belong in the namespace:

   -- foo.e
   global integer.i

   -- bar.ex
   import foo.e as stuff -- 'i' is global, NOT 'stuff.i'

Finally, I suspect that the 'modules are loaded once' rule is going to
continue:

   -- foo.e
   integer i

   -- bar.ex
   import foo.e as stuff -- 'i' is visible as 'stuff.i'
   import foo.e as nonsense -- 'i' is visible as 'nonsense.i'

the file 'foo.e' file will be loaded a single time, and made visible through
the 'stuff' and 'nonsense' namespaces under 'bar.ex'. But 'stuff.i' and
'nonsense.i' both refer to the same variable.

This is all speculation, but I think that trying to turn namespaces into
objects goes against the Euphoria way of doing things.

The problem with trying to turn namespaces into OO is that they are
statically bound. Now, I *know* that there are tons of languages out there
that implement namespaces dynamically (such as Python). But I don't think
that Robert is likely to take that direction, and I'm not sure that's the
right approach for Py, either.

What I *do* think would work well would be the addition of associative
arrays. Here's three examples from JavaScript, which basically do the same
thing:

   myCar.make = "Ford"
   myCar.model = "Mustang"
   myCar.year = 1969

   myCar["make"] = "Ford"
   myCar["model"] = "Mustang"
   myCar["year"] = 1969

   myCar = {make:"Ford", model:"Mustang", year:1969}

Anyway, that's my two bits...

Thanks!

-- David Cuny

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

13. Re: Namespaces

David, I too am a little impressed, or at least awake again.
The py code could be a great testing phase for new features of Euphoria.

My questions, answers and ideas .....

 - I like the associated list, but why aren't you using it for the namespace
? It would be much more consistent, and easy.
        foo.e["i"]
 - I don't the namespace solution (hack ?!) of using the filename. Instead,
do something like this, to avoid the whole global/local/naming issue:

       include foo.pi
         bar as foo_bar
         i as foo_i
      end include

 - I don't like the auto creation of variables, why not distinguish:
          integer x = 5    -- declare & initialize
          x = 5  -- only assign a value

 - I like for-in-do .. everybody does. (except Robert obviously tongue)
 - Where is the { left, middle, right }  = my_func () notation ?
 - And how to procedures work now ?

Good luck and succes ..

Cheers,

Ralf N.
nieuwen at xs4all.nl

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

14. Re: Namespaces

Ralf wrote:

> David, I too am a little impressed, or at
> least awake again. The py code could be a
> great testing phase for new features of Euphoria.

Yeah, that's one of the reasons I'm promoting it. It's primarily an
incarnation of my wish list for additions to Euphoria - most of the features
could be added right in. I won't guarantee that they are 100% compatible
with existing code, though.

> I like the associated list, but why aren't you
> using it for the namespace

Because I got blindsided with dealing with reloading modules, and was
convinced that a truly stupid hack was the only way to do it. I'm recoding
namespaces using a-lists now. They are broken in the latest release.

> I don't the namespace solution (hack ?!) of using
> the filename. Instead, do something like this, to
> avoid the whole global/local/naming issue:

Wait for the next release. If it's still broken, complain again. smile


> I don't like the auto creation of variables ...

I'll probably be adding a 'option explicit' for people who don't like auto
creation. For the moment, objects will remain 'typeless', though. The
declaration will probably look like:

   declare x = 10, y, z = 10


> I like for-in-do .. everybody does.

It's just a convenience notation, but it works well with sequences. I'm
thinking that the shorthand:

   for i in 10

is probably too much of a hack, though.


> - Where is the { left, middle, right }  = my_func () notation ?

An example, please?


> And how to procedures work now?

The same as functions, but you ignore the result. For example:

   x = sin(1) -- it's a function!
   sin(1) -- it's a procedure!

This would be another neat thing in Euphoria, so you could avoid:

   ignore = foo()

> Good luck and success ..

Thanks!

-- David Cuny

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

15. Re: Namespaces

On 24 Oct 2000, at 8:46, Cuny, David@DSS wrote:

> Ralf wrote:

> > I don't like the auto creation of variables ...
>
> I'll probably be adding a 'option explicit' for people who don't like auto
> creation. For the moment, objects will remain 'typeless', though. The
> declaration will probably look like:
>
>    declare x = 10, y, z = 10

If you add the declare, you can't do the dynamic name generation, cause the
programmer would haveto know all the names of all the vars as she is writing the
code.

Kat

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

16. Re: Namespaces

David wrote:
> > I don't the namespace solution (hack ?!) of using
> > the filename. Instead, do something like this, to
> > avoid the whole global/local/naming issue:
>
> Wait for the next release. If it's still broken, complain again. smile

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)

Why ? Because of these advantages:
  - shorter variable names
  - no collision with variables that are not used.
  - you see precizely what variables are "imported"

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.

>    for i in 10
>
> is probably too much of a hack, though.

Well indeed, its not that nessecary. But I don't consider for-each to be
more than just an easy to use notation. Example:

for each item in call_func () do

end for

PS. How do like:

find each ' ' in "Hello World, how many spaces ?" as pos do
 printf (1, "Found a space at %d \n", {pos})
end find

> > - Where is the { left, middle, right }  = my_func () notation ?
>
> An example, please?

{ eof_status, value } = get (0)

> > And how to procedures work now?
>
> The same as functions, but you ignore the result. For example:

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.

Cheers,

Ralf N.
nieuwen at xs4all.nl
UIN: 9389920

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

17. Re: Namespaces

> If you add the declare, you can't do the dynamic name generation, cause
the
> programmer would haveto know all the names of all the vars as she is
writing the code.


You will need to know all the names of all the vars anyway, otherwise you
can't look them up. And if you to look them up dynamically as well, then
there is already the a-list.

BTW. I would say that enforcing an declare statement or allow auto creation
of variables is pretty much the same in the aspect of allowing dynamical
variables. Why would that automatically be illegal ?

Or am I just missing the point ?

Ralf N.
nieuwen at xs4all.nl

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

18. Re: Namespaces

Kat wrote:

>> declare x = 10, y, z = 10
>
> If you add the declare, you can't do the dynamic
> name generation, cause the programmer would have to
> know all the names of all the vars as she is writing
> the code.

Yes, they are mutually exclusive.

I rather like the dynamic assignment, and if Robert added something like:

   without declarations

it could be added to Euphoria without (I think) breaking any code. Euphoria
could still allow declarations (for speed and type checking), and allow
'lazy' programmers to mix in on-the-fly variables.

-- David Cuny

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

19. Re: Namespaces

Ralf wrote:

>> Wait for the next release. If it's still
>> broken, complain again. smile
>
> 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.

If you want, you can import the module into the current namespace with:

   import "foo.py"

I'll also probably add the Python-styled import:

   from "foo.py" import x, y, z

that should take care of the issue.

I have no idea how Robert might want to approach this in Euphoria.


> 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.

That's true, you can't lock an include. I'm taking the Python route here,
where enforcement is more a matter of policy.

Put it this way: when was the last time you got a compiler error warning you
were changing the value of a constant?


> find each ' ' in "Hello World, how many spaces ?" as pos do
>    printf (1, "Found a space at %d \n", {pos})
> end find

There's a chance that a LISP-style map/apply sort of routine will be added
at some point. I've always wanted one of those for Euphoria, although I
suppose you can emulate them with routine_id. It would be a lot easier if
routine_id were scoped differently; then you could write something like:

   function apply( sequence s, sequence routine )
      integer id
      id = routine_id(routine)
      if id = -1 then
         printf( 1, "can't apply routine, %s not defined", {routine} )
         abort 0
      else
         for i = 1 to length(s) do
            s[i] = call_func( id, {s[i]} )
         end for
      end if
      return s
   end function

Here's an entirely worthless example:

   -- convert red to green
   function red_to_green( integer i )
      if i = red then
         return green
      else
         return i
      end if
   end function

   s = apply( s, "red_to_green" )


> { eof_status, value } = get (0)

Just write:

   eof_status, value = get(0)

After looking at Python, it became obvious that there was no reason to use
braces in the syntax. It'll be nice if Robert decides to add this to
Euphoria; I really like this notation.


> Yes, but what if there is NO result?

You don't like to read the documentation, do you? blink

Actually, there was a longer discussion about this in the original
documentation, but didn't make it to the current docs.

You don't need to return a result; Py will automatically return a zero value
for you. If I had access to the Euphoria innards, I'd have it return a
'Null' or something.

The catch is that you *always* have to use a return value with the 'return'
statement. If you don't intend to use it, just write:

   return 0

The reason for *having* to return a result have to do with the parser not
having more than 1 token look ahead. Jiri suggested using (), like so:

   return ( expr ) -- return expr
   return -- no explicit return value

but that would require, on average, more work for the coder, and more
chances for typos. So for now, I'm opting for a required value.

-- David Cuny

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

20. Re: Namespaces

On 24 Oct 2000, at 19:34, Fam. Nieuwenhuijsen wrote:

> > If you add the declare, you can't do the dynamic name generation, cause
> the
> > programmer would haveto know all the names of all the vars as she is
> writing the code.
>
>
> You will need to know all the names of all the vars anyway, otherwise you
> can't look them up. And if you to look them up dynamically as well, then
> there is already the a-list.

<chatty.mode=on>

I missed the definition of "alist" somehow. But i do a lot of this dynamic name
generation, and call them again dynamically. It beats a loop to search a
database,
especially when you want to delete vars based on a wildcard match. For example:

if ( %traceroute.done. [ $+ [ $gettok(%traceroutekick. [ $+ [
 %traceroute.kickindex ] ]
,2,32) ] $+ . $+ [ $gettok(%sockname,2-,$asc(.)) ] ] == $null ) {
.dde TiggrBot1 command  ""  /ddekickban $gettok(%traceroutekick. [
            $+ [
%traceroute.kickindex ] ] ,2,32) $gettok(%sockname,2-,$asc(.))
$gettok(%traceroutekick. [ $+ [ %traceroute.kickindex ] ] ,3-,32)
            set -u10 %traceroute.done. [ $+ [ $gettok(%traceroutekick. [ $+ [
%traceroute.kickindex ] ] ,2,32) ] $+ . $+ [ $gettok(%sockname,2-,$asc(.)) ] ]
did
          }

That generates and uses vars by names i cannot possibly foresee, and seems to do
it
without any loss of speed (other than the calls to $gettok()) over using plain
generic
variable nomenclature such as "x".

When starting up, i can simply do this:

unset %traceroute.done.*

and "forget" all the %traceroute.dones before from memory, no need to go find
all of
them by hand (altho in the above code, if the program is not interrupted, the
vars auto-
clear in 10 seconds anyhow). But %traceroute.available* isn't lost, nor is
%traceroute.ok, nor etc. While in memory, i can find them by many various
wildmatches, or by exact match, or a timewasting brute force SaveVarsToFile -
SearchTheFile loop. The program can know what it knows, and know what it doesn't
know quite easily.

And yeas,, that code executes hundreds of times a day, without errors. smile

Kat

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

21. Re: Namespaces

On 24 Oct 2000, at 10:26, Cuny, David@DSS wrote:

> Kat wrote:
>
> >> declare x = 10, y, z = 10
> >
> > If you add the declare, you can't do the dynamic
> > name generation, cause the programmer would have to
> > know all the names of all the vars as she is writing
> > the code.
>
> Yes, they are mutually exclusive.

<chatty.mode= still on>

You could do a pre-processor if you are prone to typoing your var names. Or, the
language could be told to notify the programmer in debug mode when vars are made
or
assigned, like this:

I typed:
//set -s %var hello

and this appeared:
*** Set %var to hello

Yeas, it really did appear, how handy is that?

> I rather like the dynamic assignment, and if Robert added something like:
>
>    without declarations
>
> it could be added to Euphoria without (I think) breaking any code. Euphoria
> could still allow declarations (for speed and type checking), and allow
> 'lazy' programmers to mix in on-the-fly variables.

I didn't consider it being lazy as much as it's using the native compiled
language to do
something faster than the interpreted code. If i used a loop to search a random
length
array used to hold the vars, i'd expect it to run 10x or more slower. Tests last
yr
generally bear this out, i switched to the "lazy" way pronto. Storing the
parameters of
the variable in the name also makes lookup in native code possible and quite a
bit
faster than nested search loops in interpreted code, especially when you don't
know
how many parms there are going to be, so you don't know just how deep to write
the
nested searches,, or even *what* you are searching for.. the *what* would make
recursive search routines difficult, imho.


I did make one mistake in an earlier email, i think... i'll clarify.. i can use
indexed vars
with wildmatches in them against a known var name, but doing a wildmatch on a
"family" of vars won't return all of them without a loop.

Kat

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

22. Re: Namespaces

Kat wrote:

> I missed the definition of "a-list" somehow.

It's my shorthand for associated list. I think they originated from LISP.
Jiri has posted an implementation to the Euphoria page. The list takes for
internal form:

   { key list, value list }

and Jiri's code offers the choice between using 'find' for small lists, and
binary searches for large lists. Languages that allow it natively typically
use a notation like this for creation:

   Kat = { job:"programmer", language:"euphoria", specialty:"bots" }

and this for accessing:

   ? Kat["job"] -- returns "programmer"

Languages like Python and JavaScript allow further syntactic sugar:

   ? Kat.job -- same as Kat["job"]

They offer a lot of OOP-sort of functionality. If you want to play with
them, take a look at Py. I think they'd make an interesting addition to
Euphoria.

-- David Cuny

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

23. Re: Namespaces

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

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

24. Re: Namespaces

> The reason for *having* to return a result have to do with the parser not
> having more than 1 token look ahead. Jiri suggested using (), like so:
>
>    return ( expr ) -- return expr
>    return -- no explicit return value
>
> but that would require, on average, more work for the coder, and more
> chances for typos. So for now, I'm opting for a required value.

David, why not go for the ICON style returning of values:

def match (x, s)
    for index = 1 to length(x) - length(x) do
        if equal (x, s[index..index+length(x)]) then
            return index
        end if
    end for
end def

A normal call would just return the first matching value, however, imagine
what the 'each' keyword does:

printf(1, "Found match as %d", {each match(x,s)})

More readable, look at this approach:

for each match (x, s) as pos do
    s[pos] = '!'
end for

What do you all think about this feature ?

Ralf N.
nieuwen at xs4all.nl

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

25. Re: Namespaces

Irv wrote:

> hr, min, sec  = date()[4..6]

The only reason that this isn't part of the Py grammar is because it's not
part of Euphoria. It's been discussed here before, and I don't recall it
getting an overwhelming reception.

My best complaint is that it looks odd, but that's no reason at all. It's
certainly consistant with it's use elsewhere. You should be able to write:

   {"foo", "bar", "grill"}[x]

which also looks a bit odd. But I've seen both used in Python, exactly in
this manner.

Maybe Robert could shed so light on this?

-- David Cuny

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

26. Re: Namespaces

On Tue, 24 Oct 2000, David.Cuny at DSS.CA.GOV wrote:
> Irv wrote:
>
> > hr, min, sec  = date()[4..6]
>
> The only reason that this isn't part of the Py grammar is because it's not
> part of Euphoria. It's been discussed here before, and I don't recall it
> getting an overwhelming reception.

I recall it being discussed a number of times,
specifically because of the awkward requirement for a "go-between"
variable when using parts of returns.

Rob has said that it would generally be wasteful to discard portions of returned
values,  and better to just write a function to return what you are actually
going to use. This makes sense, until you actually try to put it into practice.

I can't re-write the date() function to return only the portion I intend to use.
I can, of course, write my customer lookup functions to return only
a slice, but the syntax winds up somewhat less readable than the "sliced" return
would be.

Regards,
Irv

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

27. Re: Namespaces

David Cuny writes:
>   {"foo", "bar", "grill"}[x]
>
> which also looks a bit odd. But I've seen both used in Python,
> exactly in this manner.
>
> Maybe Robert could shed so light on this?

Subscripting/slicing of general expressions,
rather than just variables, is on my list,
but it's pretty far down the list. It would take
some effort to retrofit it, and I suspect I've made numerous
subtle assumptions.

Since you are inventing a new language, you have the
luxury of starting with a clean sheet of paper, with no
installed base of user-written code to support, no users
to support, little existing code of your own to maintain etc...
Someone once said that God created the world in
just seven days, because he started from scratch,
with no installed base to support.  smile

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

back to the Translator...

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

28. Re: Namespaces

On Tue, 24 Oct 2000, Robert Craig wrote:

> Since you are inventing a new language, you have the
> luxury of starting with a clean sheet of paper, with no
> installed base of user-written code to support, no users
> to support, little existing code of your own to maintain etc...
> Someone once said that God created the world in
> just seven days, because he started from scratch,
> with no installed base to support.  smile

A literal reading of Genesis would lead us to believe He dropped support for
version 1.0, and destroyed all existing copies,  after discovering numerous
bugs.

Irv

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

29. Re: Namespaces

Robert Craig wrote:

> Subscripting/slicing of general expressions,
> rather than just variables, is on my list,
> but it's pretty far down the list. It would take
> some effort to retrofit it, and I suspect I've
> made numerous subtle assumptions.

Thanks, I just wondered if there were any compelling conceptual reasons
against it.


> with no installed base of user-written code
> to support, no users to support, little existing
> code of your own to maintain etc...

I better revel in it while I can. blink


> back to the Translator...

I remember saying I couldn't think of any compelling reason why I'd want the
translator. Now I've written Py, and need all the speed I can get my hands
on. I suspect I'll figure out how to link it to C libraries at some point,
and *really* be hooked.

I really like how ec hides all the compiler, linker, and makefile details.
The djgpp version even automatically compresses the executable. Very nice,
especially for idiots like me.

-- David Cuny

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

30. Re: Namespaces

Irv,

Irv wrote:
>>>
A literal reading of Genesis would lead us to believe He dropped support for
version 1.0, and destroyed all existing copies,  after discovering numerous
bugs.
Irv
<<<

Are we still talking about God, or Microsoft?  blink

--Al

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

31. Re: Namespaces

Those weren't bugs, Irv, those were "artificial intelligence" programs gone
awry! blink

> > Someone once said that God created the world in
> > just seven days, because he started from scratch,
> > with no installed base to support.  smile
>
> A literal reading of Genesis would lead us to believe He dropped
> support for
> version 1.0, and destroyed all existing copies,  after
> discovering numerous
> bugs.
>
> Irv


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

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

32. Re: Namespaces

On Tue, 24 Oct 2000, Al Getz wrote:
> Irv,
>
> Irv wrote:
> >>>
> A literal reading of Genesis would lead us to believe He dropped support for
> version 1.0, and destroyed all existing copies,  after discovering numerous
> bugs.
> Irv
> <<<
>
> Are we still talking about God, or Microsoft?  blink
>

"Thank you for calling the Heaven Hotline. All lines are busy right now, please
hold, and you will be connected  with the first available representative."
[harp music]

"Thank you for holding. We appreciate your business. A representative will be
with you shortly"
[more harp music]

<Click>"Heaven Hotline - Gabe speaking"
#!$$

"Oh, hello Mr. Lot. How are things in Sodom?"
$@$@#o!o!

"More input/output problems? Didn't you read the warning in the maual
about the indiscriminate use of peek and poke?"
!##?

"The manual? It's that big, rolled up sheepskin thingy"
@#$#@ !

"Well, I suppose it is a bit of a difficult read. We're working on a "For
Dummies" version. In fact, Moses and the Boss are down at Sinai hammering
out a rough draft right now...."
%%))!!!##

"I see you have our premium service plan, Mr. Lot, so I'll send a couple of
Field  Service Reps around to try and fix your problem."
~!!
:)?

"Are they cute? erm... I guess so, but what..."
!o@^^!0!!

"Oh, I see. Thanks, I'll warn them about that. I'm afraid, Mr. Lot, that
in order to fix your problem, they'll have to bring down the whole system.
That may result in the loss of some data. By the way, how's the wife?"


Irv

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

33. Re: Namespaces

Irv (the 13th Apostle) wrote:

>>>
An extensive rewrite of the entire King James Version
of the Holy Scriptures in modern English.
<<<

hee hee smile

--Al
  "If your car wont start, close all the windows, then try again."
  --Bill Gates

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

34. Re: Namespaces

Robert Craig wrote:

> Subscripting/slicing of general expressions,
> rather than just variables, is on my list,
> but it's pretty far down the list.

Can we see that list?

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

35. Re: Namespaces

Skoda writes:
>Robert Craig wrote:
>> Subscripting/slicing of general expressions,
>> rather than just variables, is on my list,
>> but it's pretty far down the list.

> Can we see that list?

No.
It's a large set of files, with cryptic notes written to myself.
A lot of it refers to internal stuff that wouldn't mean
anything to anyone else.

If I'm uncertain of what to work on next,
I'll present some alternatives to this list.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

36. Namespaces

Al Getz presnts a useful idea for namespacing and his points about changing
filenames is well-taken.  If this were adopted, I would simplify the syntax
to:

prefix ClassA

an require the statement at the top of the include file or at least before
the first executable statement.

My own preference would be to extend include:

include filex.e as FileX

But either idea could work. If it were desired, they could even be combined:
if include as was used it would override prefix.

-- Mike Nelson

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

37. Namespaces

After due consideration, I believe  that iclude as the way Derek defined it
would be the most workable solution and I must withdraw my previos support
of Al's idea--not beacase it's a bad one, but that it presents some problems
that include as doesn't.

-- Mike Nelson

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

38. Namespaces

I have a global function foo() declared in two includes:

include inc1.e
include inc2.e as two

? foo()

I get an error:

test.exu:4
A namespace qualifier is needed to resolve foo.
foo is defined as a global symbol in:
    inc1.e
    inc2.e

Why is this? Logically, there should now be two functions visible to 
my main program (test.exu), one named two:foo()
and another function named just foo().

Obviously, I know how to "fix" it - just add a namespace to inc1.e also, 
and then go thru my code and add that namespace to all references to foo().

But why is that necessary?

Irv

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

39. Re: Namespaces

Hi there,

I brought that up something like a year ago, but dont remember
what the outcome was.  My suggestion was to simply add a
default namespace to everything that doesnt have a namespace
explicitly declared.    Dont know if Rob wants to do this
or not, but im pretty sure it wont hurt any existing code.

Take care,
Al

Good luck with your programming!

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

40. Re: Namespaces

On Sun, 06 Jun 2004 07:54:44 -0700, irv mullins
<guest at RapidEuphoria.com> wrote:

>Why is this? Logically, there should now be two functions visible to 
>my main program (test.exu), one named two:foo()
>and another function named just foo().

I'm sure this isn't the shortest answer you'll get, but:

You have two functions named foo(), one of which can be qualified
using the namespace "two". There is nothing actually named
"two:foo()", eg if you include misc.e as something, you can still call
reverse(), you don't have to call "something:reverse()" [unless of
course reverse() is defined somewhere else]. Clearly that can save
alot of editing when there is only one conflict over a single name,
not everything in the included file(s).

Suppose you have a source, say customers.e, which contains add(),
delete(), and update() routines, and you write some code which calls
them and test it.

You also create a file orders.e which contains the same named
routines, but obviously they affect a different file or something, and
again you write some code which calls them and test it.

(It might make a bit more sense to think of third party routines or an
application written by more than one programmer).

Now you add them both to your main application, and of course you get
a 'namespace qualifier required' on the first add() call (say). So you
fix it, probably sensibly performing a global search for add(), and
run the program again. If it worked the way you suggest, the program
will compile cleanly, but, whichever way you went, half of the
delete() and update() calls would be to the wrong one, and there would
be no further error or warning messages to help you.

If the interpreter assumed no namespace means the first include (ie
the one with no "as" clause), then after one warning, you would have
to perform a global search on every global in the source you added a
namespace qualifier to, plus any further code you add will not give an
error if you forget to specify the namespace when you should have.

Does that make sense?

Regards,
Pete

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

41. Re: Namespaces

irv mullins wrote:
> 
> 
> I have a global function foo() declared in two includes:
> 
> include inc1.e
> include inc2.e as two
> 
> ? foo()
> 
> I get an error:
> 
> test.exu:4
> A namespace qualifier is needed to resolve foo.
> foo is defined as a global symbol in:
>     inc1.e
>     inc2.e
> 
> Why is this? 

Because in the statement '? foo()', the interpreter does not know 
which of the two foo() functions you wish to invoke. Because it can see
two functions both named the same, and you haven't explictly identified
which of them to run, it sees this as ambiguous.


>Logically, there should now be two functions visible to 
> my main program (test.exu), one named two:foo()
> and another function named just foo().

The first part is right, there are two foo() functions visible. But they
are both *called* 'foo'. The namespace qualifier is NOT a part of the
function's name. It is only used by the interpreter to disambiguate 
an identifier at the point of reference.
 
> Obviously, I know how to "fix" it - just add a namespace to inc1.e also, 
> and then go thru my code and add that namespace to all references to foo().
> 
> But why is that necessary?

Because! Just kidding ... 

Yes it would be nice if an unqualified reference to a global variable 
meant that the interpreter would just look in the 'unnamed' global 
namespace. But I'm sure that would just cause other headaches too.

-- 
Derek Parnell
Melbourne, Australia

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

42. Re: Namespaces

Hi pete,

Yes, it makes a lot of sense, but you have to realize that
that is not the only way of looking at the problem.  You're
sort of saying that there's only one way it can be.

Let's start over for a second here...

I'll use NSQ as a shortie for "Name Space Qualifier"...

Start of story...

Apparently, we want to be able to refer to a function without
an NSQ and mean to call the only said named function
that never got an NSQ, even though there are other functions
with the same name that had been declared with other NSQ's.

...End of story.

Now the question is not whether it can be done or not,
but how hard it would be to do.  I guess you could weigh
the difficulty of coding it in somewhere, but that's 
still secondary.

I'm 'sort of' satisfied with the way it is now, but it would be
better if libraries that depend highly on NSQ's could co-exist
nicely with libraries that dont use them at all, without any
modifications to either library.

Since we are on the subject smile i might as well bring up the
'second instance' problem too.  You can't include a second
instance of an include file, and that's a shame too.  If you 
could, you could declare whole files of objects to be used
again with the same properties as the original (and hard work'ed)
file.  Currently, you have to rename the file first (!?!)....
<Sound(Qubert Drop)>

Im sure i've just touched the surface on these issues.

Take care,
Al

Pete Lomax wrote:
> 
> On Sun, 06 Jun 2004 07:54:44 -0700, irv mullins
> <guest at RapidEuphoria.com> wrote:
> 
> >Why is this? Logically, there should now be two functions visible to 
> >my main program (test.exu), one named two:foo()
> >and another function named just foo().
> 
> I'm sure this isn't the shortest answer you'll get, but:
> 
> You have two functions named foo(), one of which can be qualified
> using the namespace "two". There is nothing actually named
> "two:foo()", eg if you include misc.e as something, you can still call
> reverse(), you don't have to call "something:reverse()" [unless of
> course reverse() is defined somewhere else]. Clearly that can save
> alot of editing when there is only one conflict over a single name,
> not everything in the included file(s).
> 
> Suppose you have a source, say customers.e, which contains add(),
> delete(), and update() routines, and you write some code which calls
> them and test it.
> 
> You also create a file orders.e which contains the same named
> routines, but obviously they affect a different file or something, and
> again you write some code which calls them and test it.
> 
> (It might make a bit more sense to think of third party routines or an
> application written by more than one programmer).
> 
> Now you add them both to your main application, and of course you get
> a 'namespace qualifier required' on the first add() call (say). So you
> fix it, probably sensibly performing a global search for add(), and
> run the program again. If it worked the way you suggest, the program
> will compile cleanly, but, whichever way you went, half of the
> delete() and update() calls would be to the wrong one, and there would
> be no further error or warning messages to help you.
> 
> If the interpreter assumed no namespace means the first include (ie
> the one with no "as" clause), then after one warning, you would have
> to perform a global search on every global in the source you added a
> namespace qualifier to, plus any further code you add will not give an
> error if you forget to specify the namespace when you should have.
> 
> Does that make sense?
> 
> Regards,
> Pete
> 
> 


Good luck with your programming!

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

43. Re: Namespaces

On Mon, 07 Jun 2004 11:16:20 -0700, Al Getz <guest at RapidEuphoria.com>
wrote:

>Yes, it makes a lot of sense, but you have to realize that
>that is not the only way of looking at the problem.  You're
>sort of saying that there's only one way it can be.
I was trying to explain how it is, and justify it, even though I
neither designed nor wrote it blink

<snip>
>Now the question is not whether it can be done or not,
>but how hard it would be to do.
Technically, I suspect it would be rather trivial, but has not been
done for fear of the problems it might cause.

I would certainly have no concern over permitting eg:

include file.e as ""

to indicate that is the one you should use automatically when no
namespace is specified (though it would still have to complain if the
global was included more than once as "", or if it was included
somewhere with no 'as' clause).

Regards,
Pete

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

44. Re: Namespaces

Hi pete,

Ok thanks.  I guess right now there are only two people asking about
this.

Good luck with your programming!

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

45. Re: Namespaces

From: "Al Getz"
Sent: Tuesday, June 08, 2004 6:09 AM


[...]
 

include mylib.e
include yourlib.e as your

your:routine() -- call your routine()
routine() -- call my routine()



> Hi pete,
> 
> Ok thanks.  I guess right now there are only two people asking about
> this.


I support the request for NSQ's to be made better as suggested in a 
previous post.

[...]

    unkmar  - Lucius L. Hilley III

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

46. Re: Namespaces

unknown wrote:
>
> I support the request for NSQ's to be made better as suggested in a 
> previous post.
> 

The real problem I have with namespacing is this:
My EuGTK library, for example, has 150+ files, more or less one per 
GTK object. 

If I write a program that uses, for example, a window, a button and a 
text entry, then I would have to write:
include window.e as window
include button.e as button
include entry.e as entry


So far, so good, my code might look like:
mywin = window:new("Title")
btn[1] = button:new("OK")


However, any *actual* program which is going to be useful is going 
to require between 50 and 150 of those GTK objects. So the first 50 to 
150 lines of each and every program would be includes. That's just 
not acceptable, many whole programs are less than 100 lines. 

I would like to put all those "include...." lines in a separate "wrapper" 
file, which could be included via one line at the top of each program. 
But that's not possible, because namespaces aren't passed on. 

IOW, to the wrapper, window:new() is a separate function from button:new(),
but to any program which includes the wrapper, the qualifiers are lost, and
everything is again just "new()".

Here are a couple of possibilities:
1. Fix the namespacing so it can be inherited.
or
2. Add a new command which simply copies a file into the source at the 
place the command is found: IOW, an automatic source code "merge".

call it "merge otherfile.e",
or "import otherfile.e", or whatever you like. It should be simple to 
implement.

If "otherfile.e" is a long list of "include x as y", then the result would
be the same as copying and pasting that file using a text editor, 
except that Euphoria would do it automatically. 

I can think of other uses for something like this, such as copying long 
boilerplate text into a program. The boilerplate could then reside in a 
separate file which could be edited without having to mess with the source 
code. 

Irv

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

47. Re: Namespaces

irv mullins wrote:
> 
> 
> unknown wrote:
> >
> > I support the request for NSQ's to be made better as suggested in a 
> > previous post.
> > 

<some snippage occurred>

> I would like to put all those "include...." lines in a separate "wrapper" 
> file, which could be included via one line at the top of each program. 
> But that's not possible, because namespaces aren't passed on. 

<more snippage occurred>

> Here are a couple of possibilities:
> 1. Fix the namespacing so it can be inherited.
> or
> 2. Add a new command which simply copies a file into the source at the 
> place the command is found: IOW, an automatic source code "merge".
> 
> call it "merge otherfile.e",
> or "import otherfile.e", or whatever you like. It should be simple to 
> implement.

Yes, please. Please, yes. Yes, yes, yes. Please, please, please.

> I can think of other uses for something like this, such as copying long 
> boilerplate text into a program. The boilerplate could then reside in a 
> separate file which could be edited without having to mess with the source 
> code. 

Please, please, please. Yes, yes, yes. Please, yes. Yes, please.

Thank you.

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

48. Re: Namespaces

cklester wrote:
> 
> 
> irv mullins wrote:
> > 

> > call it "merge otherfile.e",
> > or "import otherfile.e", or whatever you like. It should be simple to 
> > implement.
> 
> Yes, please. Please, yes. Yes, yes, yes. Please, please, please.
> 
> > I can think of other uses for something like this, such as copying long 
> > boilerplate text into a program. The boilerplate could then reside in a 
> > separate file which could be edited without having to mess with the source 
> > code. 
> 
> Please, please, please. Yes, yes, yes. Please, yes. Yes, please.
> 

Hmm. Come to think of it, we could have "merge otherfile.e", which 
would simply insert whatever was in otherfile.e into the code, as well 
as something like "merge otherfile.e as myvar", which would read it 
into an already declared constant or variable.

Irv

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

49. Re: Namespaces

irv mullins wrote:
> 
> 
> Hmm. Come to think of it, we could have "merge otherfile.e", which 
> would simply insert whatever was in otherfile.e into the code, as well 
> as something like "merge otherfile.e as myvar", which would read it 
> into an already declared constant or variable.

uh... say what?

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

50. Re: Namespaces

irv mullins wrote:
> 
> Here are a couple of possibilities:
> 1. Fix the namespacing so it can be inherited.
> or
> 2. Add a new command which simply copies a file into the source at the 
> place the command is found: IOW, an automatic source code "merge".
> 
> Irv
> 

Very good idea Irv.  I second this.  I have same problem with
my library too.

Here's a summary of the namespace issues that should be addressed:

1.  global namespace fix (Me and others)
2.  inheritance or dynamic merge (Irv & Me)
3.  multiple include instances (Me)

Take care,
Al

Good luck with your programming!

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

51. Re: Namespaces

Al Getz wrote:

> Here's a summary of the namespace issues that should be addressed:
> 
> 1.  global namespace fix (Me and others)
> 2.  inheritance or dynamic merge (Irv & Me)
> 3.  multiple include instances (Me)

Oh, yeah - I forgot about the multiple-include idea. 
You may remember Dave Cuny's "Py" language, which for a time 
allowed code such as:
include mailinglist.e as customer
include mailinglist.e as supplier


resulting in two instances of mailinglist, each with their own 
independent set of variables and functions. Very handy. You could write:
customer:file = "customer.edb"
supplier:file = "supplier.edb"
customer:add("Coyote, W")
supplier:add("Acme Anvils, Inc.")


and use the exact same code to manage both instances.
 
Irv

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

52. Re: Namespaces

cklester wrote:
> 
> > irv mullins wrote:
> > 
> > 
> > Hmm. Come to think of it, we could have "merge otherfile.e", which 
> > would simply insert whatever was in otherfile.e into the code, as well 
> > as something like "merge otherfile.e as myvar", which would read it 
> > into an already declared constant or variable.
> 
> uh... say what?

sequence license
merge GPL_license.txt as license
-- or perhaps better would be:
import GPL_license.txt into license

puts(1,license)


Irv

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

53. Re: Namespaces

irv mullins wrote:
> 
> cklester wrote:
> > 
> > > irv mullins wrote:
> > > 
> > > 
> > > Hmm. Come to think of it, we could have "merge otherfile.e", which 
> > > would simply insert whatever was in otherfile.e into the code, as well 
> > > as something like "merge otherfile.e as myvar", which would read it 
> > > into an already declared constant or variable.
> > 
> > uh... say what?
> 
> <font color="#330033"></font>
> <font color="#FF00FF">sequence </font><font color="#330033">license</font>
> <font color="#330033">merge GPL_license.txt as license</font>
> <font color="#FF0055">-- or perhaps better would be:</font>
> <font color="#330033">import GPL_license.txt into license</font>
> <font color="#330033"></font>
> <font color="#FF00FF">puts</font><font color="#330033">(1,license)</font>
> <font color="#330033"></font>

Oh! Basically reading in a textfile, right? I thought you meant something
like:

sequence myInclude
merge some_include_file.ew as myInclude

junk = myInclude:some_function()

I don't think merging a text file into a variable is really necessary
at that level. Why not just

sequence myText
myText = GetAFile( "GPL License.txt" )

?

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

54. Re: Namespaces

On 8 Jun 2004, at 13:06, cklester wrote:

> 
> 
> posted by: cklester <cklester at yahoo.com>
> 
> irv mullins wrote:
> > 
> > cklester wrote:
> > > 
> > > > irv mullins wrote:
> > > > 
> > > > 
> > > > Hmm. Come to think of it, we could have "merge otherfile.e", which 
> > > > would simply insert whatever was in otherfile.e into the code, as well
> > > > as
> > > > something like "merge otherfile.e as myvar", which would read it into an
> > > > already declared constant or variable.
> > > 
> > > uh... say what?
> > 
> > <font color="#330033"></font>
> > <font color="#FF00FF">sequence </font><font color="#330033">license</font>
> > <font color="#330033">merge GPL_license.txt as license</font> <font
> > color="#FF0055">-- or perhaps better would be:</font> <font
> > color="#330033">import GPL_license.txt into license</font> <font
> > color="#330033"></font> <font color="#FF00FF">puts</font><font
> > color="#330033">(1,license)</font> <font color="#330033"></font>
> 
> Oh! Basically reading in a textfile, right? I thought you meant something
> like:
> 
> sequence myInclude
> merge some_include_file.ew as myInclude
> 
> junk = myInclude:some_function()
> 
> I don't think merging a text file into a variable is really necessary
> at that level. Why not just
> 
> sequence myText
> myText = GetAFile( "GPL License.txt" )

Is GetAFile() different from the getf() in file.e ?

Kat

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

55. Re: Namespaces

cklester wrote:

> I don't think merging a text file into a variable is really necessary
> at that level. Why not just
> 
> sequence myText
> myText = GetAFile( "GPL License.txt" )
> 

Of course you're correct. That function would be easy enough to write. 
But in reality, all this discussion is just something to fill idle moments; 
I don't expect to see any improvement in the way namespacing works.

Irv

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

56. Re: Namespaces

irv mullins wrote:
> 
> Of course you're correct. That function would be easy enough to write. 
> But in reality, all this discussion is just something to fill idle moments; 
> I don't expect to see any improvement in the way namespacing works.

Oh, ye of little faith.

:P

"Pester the gods." - Anonymous

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

57. Re: Namespaces

Kat wrote:
> 
> On 8 Jun 2004, at 13:06, cklester wrote:
> > 
> > posted by: cklester <cklester at yahoo.com>
> > 
> > sequence myText
> > myText = GetAFile( "GPL License.txt" )
> 
> Is GetAFile() different from the getf() in file.e ?

Kat, I couldn't find a "getf()" in file.e. Am I missing something?

Yes, GetAFile() was just pseudo-code.

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

58. Re: Namespaces

Man that would be one cool item (the multiple inheritance).
I personally have wanted this to redo a portion of my API code base
(structures).  It would improve the readability of my code alot.

I was going to use it something like the dot operator in C/C++...

Rect = new(RECT)
Rect:left = 10
Rect:bottom = 20 -- etc etc

As you pointed out, it will not currently work from including them
all in one include file and including that.  I am not going to try
and include some thousand structs manually at the top of my files :P


Don Phillips
     National Insturments
     mailto: eunexus at yahoo.com

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

59. Re: Namespaces

On 8 Jun 2004, at 14:10, cklester wrote:

> 
> 
> posted by: cklester <cklester at yahoo.com>
> 
> Kat wrote:
> > 
> > On 8 Jun 2004, at 13:06, cklester wrote:
> > > 
> > > posted by: cklester <cklester at yahoo.com>
> > > 
> > > sequence myText
> > > myText = GetAFile( "GPL License.txt" )
> > 
> > Is GetAFile() different from the getf() in file.e ?
> 
> Kat, I couldn't find a "getf()" in file.e. Am I missing something?

global function getf(sequence filename)
object junk, file, filecontents
 file = open(filename,"r")
 if not equal(file,-1) then
   filecontents = ""
   junk = gets(file)
   while not equal(junk,-1) do
     filecontents &= junk
     junk = gets(file)
   end while
   close(file)
   return filecontents
 end if
 return -1
end function


I use it often, it's for win/dos text files, i don't know who wrote it. I spose
it
would work for *nix too. That function is in all my file.e going back to 1999.

Kat

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

60. Re: Namespaces

On 8 Jun 2004, at 14:46, Don wrote:

> 
> 
> posted by: Don <eunexus at yahoo.com>
> 
> Man that would be one cool item (the multiple inheritance).
> I personally have wanted this to redo a portion of my API code base
> (structures).  It would improve the readability of my code alot.
> 
> I was going to use it something like the dot operator in C/C++...
> 
> Rect = new(RECT)
> Rect:left = 10
> Rect:bottom = 20 -- etc etc
> 
> As you pointed out, it will not currently work from including them
> all in one include file and including that.  I am not going to try
> and include some thousand structs manually at the top of my files :P

Download Karl's take on what Eu could be, Bach.

Kat

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

61. Re: Namespaces

> Download Karl's take on what Eu could be, Bach.
> 
> Kat

I thought about that once.  Actually downloaded it also.
Then I read the user agreement thing and it mentioned something
about nag screen and /or pop up or something and trashed it...

If its not in there anymore, I will consider it again...


Don Phillips
     National Insturments
     mailto: eunexus at yahoo.com

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

62. Re: Namespaces

irv mullins wrote:
> But in reality, all this discussion is just something to fill idle moments; 
> I don't expect to see any improvement in the way namespacing works.

There will be some improvement in the way namespacing works 
in 2.5. Remember the small change that Matt Lewis suggested 
way back when? I haven't forgotten about it. 

The massive rewrite from C into Euphoria created a lot of "dust" 
that still has to settle before I can release anything.
Not too many bugs, just things like build procedures
testing, documentation, performance tuning etc.
A lot of components to build/test on a lot of platforms.
I'm really not looking for any more major changes at this 
stage. Once the Euphoria in Euphoria interpreter is out,
anyone will be able to add or change anything, or at least
you'll be able to call my bluff when I say something 
is too hard. smile

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

63. Re: Namespaces

Hi Don,

That's exactly the way the WinClass library works.
I've been copy'ing and paste'ing includes to make up
for the lack of 'merge' (or whatever).

Take care,
Al

Don wrote:
> 
> 
> Man that would be one cool item (the multiple inheritance).
> I personally have wanted this to redo a portion of my API code base
> (structures).  It would improve the readability of my code alot.
> 
> I was going to use it something like the dot operator in C/C++...
> 
> Rect = new(RECT)
> Rect:left = 10
> Rect:bottom = 20 -- etc etc
> 
> As you pointed out, it will not currently work from including them
> all in one include file and including that.  I am not going to try
> and include some thousand structs manually at the top of my files :P
> 
> 
> Don Phillips
>      National Insturments
>      mailto: eunexus at yahoo.com
> 


Good luck with your programming!

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

64. Re: Namespaces

Hi irv,

I never got around to trying Py, but it sounds similar.
I've had the need to include several instances of the same
file many times already.  I suggested this way back when,
but at the time hardly anyone was using the namespace feature.
It sounds like more people are finally using it now so issues
like this will keep comming up.  The results will be an improved
Euphoria, sooner or later.

Take care,
Al


irv mullins wrote:
> 
> 
> Al Getz wrote:
> 
> > Here's a summary of the namespace issues that should be addressed:
> > 
> > 1.  global namespace fix (Me and others)
> > 2.  inheritance or dynamic merge (Irv & Me)
> > 3.  multiple include instances (Me)
> 
> Oh, yeah - I forgot about the multiple-include idea. 
> You may remember Dave Cuny's "Py" language, which for a time 
> allowed code such as:
> <font color="#330033"></font>
> <font color="#0000FF">include </font><font color="#330033">mailinglist.e as
> customer</font>
> <font color="#0000FF">include </font><font color="#330033">mailinglist.e as
> supplier</font>
> <font color="#330033"></font>
> 
> resulting in two instances of mailinglist, each with their own 
> independent set of variables and functions. Very handy. You could write:
> <font color="#330033"></font>
> <font color="#330033">customer:file = </font><font
> color="#00A033">"customer.edb"</font>
> <font color="#330033">supplier:file = </font><font
> color="#00A033">"supplier.edb"</font>
> <font color="#330033">customer:add(</font><font color="#00A033">"Coyote,
> W"</font><font color="#330033">)</font>
> <font color="#330033">supplier:add(</font><font color="#00A033">"Acme Anvils,
> Inc."</font><font color="#330033">)</font>
> <font color="#330033"></font>
> 
> and use the exact same code to manage both instances.
>  
> Irv
> 


Good luck with your programming!

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

65. Re: Namespaces

Hi irv,

using my macro utility, you could do it thus ...
 
  @insert mailinglist.e <ns=customer
  @insert mailinglist.e <ns=supplier

  customer_file = "customer.edb"
  supplier_file = "supplier.edb"
  customer_add("Coyote, W")
  supplier_add("Acme Anvils, Inc.")


where the 'mailinglist.e' file would look something like ...


  sequence [[ns]]_file
  function valid_[[ns]](object pKey)
    integer lStatus 
    lStatus = 0
  @if [[ns]] eq customer
   . . . code to validate the customer data
  @endif
  @if [[ns]] eq supplier
   . . . code to validate the supplier data
  @endif
     return lStatus
  end function
  procedure [[ns]]_add(object pKey)
       if valid_[[ns]](pData) then
         open_db([[ns]]_file)     
         rec_add(pKey)
       end if
  end procedure

You could even have insert files ...
   @ newfld.i
   @inc global [[[[ns]]_fldno]]
   constant [[ns]]_[[fld]] = [[[[ns]]_fldno]]

and
   @  recdef.i
   constant [[ns]]_Empty_Record = repeat(0,[[[[ns]]_fldno]]])

and used like this ...

  @insert newfld.i <ns=customer,fld=Name
  @insert newfld.i <ns=customer,fld=Address
  @insert newfld.i <ns=customer,fld=Phone
  @insert newfld.i <ns=customer,fld=Email
  @insert newfld.i <ns=supplier,fld=ID
  @insert newfld.i <ns=supplier,fld=Email
  @insert newfld.i <ns=supplier,fld=Address
  @insert recdef.i <ns=customer
  @insert recdef.i <ns=supplier

to generate ...

  constant customer_Name = 1
  constant customer_Address = 2
  constant customer_Phone = 3
  constant customer_Email = 4
  constant supplier_ID = 1
  constant supplier_Email = 2
  constant supplier_Address = 3
  constant customer_Empty_Record = repeat(0, 4)
  constant supplier_Empty_Record = repeat(0, 3)

-- 
Derek Parnell
Melbourne, Australia

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

66. Re: Namespaces

Robert Craig wrote:
> 
> 
> irv mullins wrote:
> > But in reality, all this discussion is just something to fill idle moments; 
> > I don't expect to see any improvement in the way namespacing works.
> 
> There will be some improvement in the way namespacing works 
> in 2.5. Remember the small change that Matt Lewis suggested 
> way back when? I haven't forgotten about it. 

To be fair, I didn't suggest it, but I implemented it using the Euphoria
source code.  I'm not sure who first suggested it (Pete maybe?).

Matt Lewis

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

67. Re: Namespaces

On 9 Jun 2004, at 4:04, Matt Lewis wrote:

> 
> 
> posted by: Matt Lewis <matthewwalkerlewis at yahoo.com>
> 
> Robert Craig wrote:
> > 
> > 
> > irv mullins wrote:
> > > But in reality, all this discussion is just something to fill idle
> > > moments;
> > > I don't expect to see any improvement in the way namespacing works.
> > 
> > There will be some improvement in the way namespacing works 
> > in 2.5. Remember the small change that Matt Lewis suggested 
> > way back when? I haven't forgotten about it. 
> 
> To be fair, I didn't suggest it, but I implemented it using the Euphoria
> source code.  I'm not sure who first suggested it (Pete maybe?).

I don't remember who asked for namespaced functions, but i was prolly the 
first to ask for namespaced vars, for access to the name list of vars, for 
ability to build var-names in the program dynamically, and for a trap to know 
when a var was changed and to execute code at that time. For now, anyone 
wanting to do these things needs to use associated lists.

Kat

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

68. Re: Namespaces

Kat wrote:

> I don't remember who asked for namespaced functions, but i was prolly the 
> first to ask for namespaced vars, for access to the name list of vars, for 
> ability to build var-names in the program dynamically, and for a trap to know 
> when a var was changed and to execute code at that time. For now, anyone 
> wanting to do these things needs to use associated lists.

Speaking of variables, namespacing (as implemented) does absolutely nothing 
to help the following type of situation:
-- Customer file:
global object rec
global constant NAME = 1, ADDR = 2, CITY = 3, STATE = 4

rec = {"Coyote, W.","55 Fifth St.","Tucson","AZ"}

-- Supplier file:
global sequence rec

global constant NAME  = 1, STATE = 2

rec = {"Acme Anvils, Inc.","PA"}

-- Main program:
include customer.e as customer
include supplier.e as supplier

printf(1,"Name:%s, State:%s\n",
       {customer:rec[customer:NAME],
        customer:rec[customer:STATE]})


Anyone else note a great duplication of effort here?
How do you get the same result without qualifying every 
instance of NAME and STATE?

Anyone remember how easily that was done with ancient Pascal?

Irv

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

69. Namespaces

--7JfCtLOvnd9MIVvH

Why doesn't euphoria support inline namespaces? it would make combining
include file much easier! instead, if you want namespaces, you either have
to write a program that pulls them out into seperate files, or you
have to write a program that renames the variables & routines in
a program, like I did. Anyone know why?

TIA,
jbrown

P.S. I inclose a namespace program in this email,
and it renames the data, not make a hundred diffrent include files.

-- 
Linux User:190064
Linux Machine:84163
http://jbrown105.1avenue.com


--7JfCtLOvnd9MIVvH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="namespace.ex"

--namespace.ex
--based on my combine.ex
--based on David Cuny's concat.ex
--Altered to adjust name according to namespace
--Supports routine_id-ing routines in namespace
--Doesn't support multiple namespaces (one inside the other) yet.

--JBrown
--combine.ex
--global scopes aren't redefined
    --this MIGHT cause an error, however, euphoria should normally have an
    --error in that case too.
--procedure-scope vars aren't saved, this makes code more readable
    --N/A if shroud is on
--you can either choose not to combine files in a list, or
    --you can ignore include files on 1 dir (default: eu's include dir)
--shrouding symbols is optional.
--bug fixed: local symbols were being treated as global.
--bug fixed: strings with \x were changed to \x\x.
--bug fixed: file c:\myfile.e and myfile.e were the diffrent files.
--added platform to sequence builtin
--bug: using routine_id("abort_") gives error
    --"Unable to resolve routine id for abort"
    --to fix made routine_id-ing of builtin routines legal.

with trace

-- concat.ex
-- version 1.0
--
-- replacement for Euphoria's bind routine

include get.e
include file.e
include wildcard.e
include misc.e

integer slash, IGNORE
if platform() = 3 then
    slash = '/'
else
    slash = '\\'
end if
IGNORE = 0
sequence ignore_table, ignore_dir
ignore_dir = getenv("EUDIR")&slash&"include"
if ignore_dir[1] = -1 then
    ignore_dir = "include"
end if
ignore_table={ --the default euphoric files
"dll.e",
"file.e",
"get.e",
"graphics.e",
"image.e",
"machine.e",
"misc.e",
"mouse.e",
"msgbox.e",
"safe.e",
"sort.e",
"wildcard.e",
""}


sequence charClass

-- character classes
constant    
    DIGIT       = 1,
    OTHER       = 2,
    LETTER      = 3,
    BRACKET     = 4,
    QUOTE       = 5,
    DASH        = 6,
    WHITE_SPACE = 7,
    NEW_LINE    = 8

    charClass = repeat( OTHER, 255 )

    
    charClass['a'..'z'] = LETTER
    charClass['A'..'Z'] = LETTER
    charClass['_']      = LETTER
    charClass['0'..'9'] = DIGIT
    charClass['[']      = BRACKET
    charClass[']']      = BRACKET
    charClass['(']      = BRACKET
    charClass[')']      = BRACKET
    charClass['{']      = BRACKET
    charClass['}']      = BRACKET
    charClass['\'']     = QUOTE
    charClass['"']      = QUOTE
    charClass[' ']      = WHITE_SPACE
    charClass['\t']     = WHITE_SPACE
    charClass['\n']     = NEW_LINE
    charClass['-']      = DASH

    "constant",
    "do",
    "else",
    "elsif",
    "end",
    "exit",
    "for",
    "function",
    "global",
    "if",
    "include",
    "not",
    "or",
    "procedure",
    "profile",
    "profile_time",
    "return",
    "to",
    "type",   
    "type_check",
    "then",       
    "warning",
    "while",
    "with",
    "without",
    "xor",
    "namespace"} --not really builtin, but treated so


    "and_bits",
    "append",
    "arctan",
    "atom",
    "call",
    "c_func",   
    "c_proc",
    "call_func",
    "call_proc",
    "clear_screen",
    "close",
    "command_line",
    "compare",
    "cos",
    "date",
    "equal",
    "find",
    "floor",
    "get_key",
    "get_pixel",
    "getc",
    "getenv",
    "gets",
    "integer",
    "length",
    "log",
    "machine_func",
    "machine_proc",
    "match",
    "mem_copy",
    "mem_set",
    "not_bits",
    "object",
    "open",
    "or_bits",
    "peek",
    "peek4s",
    "peek4u",
    "pixel",
    "poke",
    "poke4",
    "position",
    "power",
    "prepend",
    "print",
    "printf",
    "profile",
    "puts",
    "rand",
    "remainder",
    "repeat",
    "routine_id",
    "sequence",
    "sin",
    "sprintf",
    "sqrt",         -- missing
    "system",
    "system_exec",
    "tan",
    "time",
    "trace",
    "platform",
    "xor_bits" }


    ids,                    -- count of ids issued
    outFile,                 -- file to write to
    addtype,
    nextGoff,
    inname
    
    globalState = 0         
    routineFlag = 0
    procState = 0
    ids = 0
    addtype = 0
    nextGoff = 0
    inname = 0
    
sequence
    oldProc, newProc,
    oldLocal, newLocal,
    oldGlobal, newGlobal,
    included, types, all_ids, name, names

    oldProc = {}
    newProc = {}
    oldLocal = {}
    newLocal = {}
    oldGlobal = {}
    newGlobal = {}
    included = {}
    types = {"atom", "integer", "object", "sequence"}
    all_ids = {}
    name = {}
    names = {}


constant
    EuPlace = getenv( "EUDIR" ),
    --Place = { "", EuPlace & "\\", EuPlace & "\\INCLUDE\\" }
Place = { current_dir()&slash, EuPlace & slash, EuPlace & slash&"include"&slash,
"" }

    -- returns where a file is
    -- looks in the usual places
    
    -- look in the usual places
    --trace(1)
    if find(fName[length(fName)], {10, 13}) then
	fName = fName[1..length(fName)-1]
    end if
    for i = 1 to length( Place ) do
	if sequence( dir( Place[i] & fName ) ) then
	    if platform() = 3 then
		return Place[i] & fName
	    else
		return upper( Place[i] & fName )
	    end if
	end if
    end for
    
    printf( 1, "Unable to locate file %s.\n", {fName} )
    abort(0)
    
end function

function curnames()
    sequence s
    s = ""
    for i = 1 to length(name) do
	s &= name[i] &"_"
    end for
    return s
end function


    integer at
    sequence new

    --if equal(word, "char") then
	--trace(1)
    --end if
    -- negates global?
    if globalState = 2
    and find( word, { "constant", "for","function","procedure","type" } ) 
    then
	-- clear global flag
	globalState = 0
    elsif nextGoff then
	globalState = 0
	nextGoff = 0
    end if
    
    if addtype then
	types &= {word}
	addtype = 0
    end if
    
    if globalState = 2 and find(word, types) then
	globalState = 0
    end if

    -- ignore if builtin
    if find( word, builtin ) then
	if equal(word, "type") then
	    addtype = 1
	end if
	return word --commented out so local types can be redefined
    end if
    
    -- ignore if identifier
    if find( word, identifier ) then
	return word
    end if
    
    -- scoped to current procedure?
    -- scopes reversed so last redefinition will be used
    if procState = 2 then
	--at = find( word, reverse(oldProc) )
	at = find( word, oldProc )
	if at then     
	    return newProc[at]
	end if
    end if

    -- scoped to current module?
    -- scopes reversed so last redefinition will be used
    --at = find( word, reverse(oldLocal) )
    at = find( word, oldLocal )
    if at then
	return newLocal[at]
    end if

    -- scoped to globals?
    -- scopes reversed so last redefinition will be used
    --at = find( word, reverse(oldGlobal) )
    at = find( word, oldGlobal )
    if at then
	return newGlobal[at]
    end if

    -- not found; add to appropriate list    
    --if SHROUD_ON then
	--new = sprintf( "id_%d", {ids} )
    --else
	new = word
	if globalState = 0 then --never change a global name
	    --if find(new, all_ids) then
		new = sprintf( "%s%s", {curnames(), word} )
		names &= {word}
		word = new
	    --end if
	end if
    --end if
    if procState != 2 then --only add globals and locals, procs don't go in
	all_ids &= {new} --but proc names do.
	ids += 1
    end if

    if procState = 2 then
	-- defined in a proc
	oldProc = append( oldProc, word )
	newProc = append( newProc, new )
	
    elsif globalState then
	-- global declaration
	oldGlobal = append( oldGlobal, word )
	newGlobal = append( newGlobal, new )
	
    else
	-- local
	oldLocal = append( oldLocal, word )
	newLocal = append( newLocal, new )
	
    end if

    return new
    
end function

function checkn(sequence word)
    if find(word, names) then
	return 1
    end if
    return 0
end function

    
    integer at, char, i
    sequence out, word
    integer namewaiting, needtoreplace
    namewaiting = 0
    needtoreplace = 0
    
    out = {}
    at = 1

    while at <= length( s ) do        
    
	-- get a character
	char = s[at]      

	-- identifier
	if charClass[char] = LETTER then     
	
	    word = {}
	
	    -- read until end
	    while charClass[char] = LETTER
	    or    charClass[char] = DIGIT do
	
		-- add to word
		word = append( word, char )
		-- next letter
		at += 1       
		char = s[at]
	
	    end while       

	    -- routine flag
	    routineFlag = equal( word, "routine_id" )
	    needtoreplace = checkn(word)

	    if equal(word, "namespace") then
		if inname = 0 then --need to change to support multiple names
		    name = append(name, "")
		    namewaiting = 1
		    inname = 1
		else
		    inname = 0
		    names = ""
		    name = name[1..length(name)-1]
		end if
		out = "--" & out --comment out
	    elsif namewaiting then
		namewaiting = 0
		name[length(name)] = word
	    else
	    -- substitute?            
	    word = replaceWord( word )
	    end if

	    -- global flag
	    if equal( word, "global" ) then
		-- new occurance
		globalState = 1
		
	    elsif globalState = 1 then
		-- mark as used
		globalState = 2
	    end if

	    
	    -- manage proc state
	    if equal( word, "function" )
	    or equal( word, "procedure" )
	    or equal( word, "type" ) then
		if procState = 0 then
		    -- beginning of definition
		    procState = 1

		elsif procState = 2 then
		    -- end function/procedure
		    procState = 0
		    oldProc = {}
		    newProc = {}

		end if          
	    elsif procState = 1 then
		-- move state ahead
		procState = 2    
		globalState = 0
	    end if

	    -- substitute, if needed            
	    out = out & word

	-- number: handles hex as well
	elsif charClass[char] = DIGIT
	or    char = '#' then

	    word = {}
	    
	    -- read until end
	    while charClass[char] = DIGIT
	    or    charClass[char] = LETTER
	    or    char = '#' do
	    
		-- add to word
		word = append( word, char )
		-- next letter
		at += 1       
		char = s[at]
	
	    end while       

	    -- accumulated number            
	    out = out & word

	
	-- comment
	elsif char = '-'
	and   s[at+1] = '-' then
	    -- comment
	    out = out & s[at..length(s)]
	    -- move past end
	    at = length(s)+1
	
	-- character literal        
	elsif char = '\'' then
	    at += 1
	    if s[at] = '\\' then
		-- special
		at += 1
		word = "'\\" & s[at] & "'"
	    else          
		-- normal
		word = "'" & s[at] & "'"
	    end if       

	    -- move past quote            
	    at += 2

	    -- accumulate            
	    out = out & word

	-- quote                 
	elsif char = '"' then

	    word = {'"'}
	    while 1 do 
		-- move ahead
		at += 1
		-- special?
		if s[at] = '\\' then           
		    at += 1
		    --word = word & s[at-1] & s[at]
		    word = word & '\\' & s[at]
		    -- prevent reading as quote
		    s[at] = ' '
		else
		    word = word & s[at]
		end if

		-- end of quote?                
		if s[at] = '"' then
		    -- move ahead and exit
		    at += 1
		    exit
		end if
		
	    end while

	    -- handle routine_id
	    if routineFlag then
		needtoreplace = 1
	    end if
	    if needtoreplace then
		if routineFlag then
		    -- remove quotes
		    word = word[2..length(word)-1]
		end if
		if find(word, names) then
		    word = curnames() & names[find(word, names)]
		end if
		
		-- scoped to current procedure?
		i = 0
		if procState = 2 then
		    i = find( word, oldProc )
		    if i then
			word = newProc[i]
		    end if
		end if

		-- not found in procedure?
		if i = 0 then
		    -- scoped to current module?
		    i = find( word, oldLocal )
		    if i then
			word = newLocal[i]
		    end if
		end if

		-- not found procedure or module?
		if i = 0 then
		    -- scoped to current module?
		    i = find( word, oldGlobal )
		    if i then
			word = newGlobal[i]
		    end if
		end if
		
		if find(word, builtin) or find(word, identifier) then
		    i = 1
		    word = word --so routine_id("abort_") will work
		end if
		
		if i = 0 then
		    printf( 1, "Unable to resolve routine id for %s\n", {word} )
		    abort(0)
		end if
		
		-- re-apply quotes
		word = '"' & word & '"'
		
	    end if

	    -- accumulated
	    out = out & word
	    
	-- delimiter
	else        
	    out = out & char
	    at += 1
					  
	end if
	
    end while
    
    return out
    
end function



    -- if the statement is an include statement, return the file name
    integer at
    
    -- include statement missing?
    if not match( "include ", data ) then
	return ""
    end if

    -- trim white space
    while charClass[ data[1] ] = WHITE_SPACE do
	data = data[2..length( data ) ]
    end while      
    
    -- line feed?
    if find( '\n', data ) then
	data = data[1..length(data)-1]
    end if

    -- not first statement?
    if not equal( data[1..8], "include " ) then
	-- not an include statement
	return ""  
    else
	-- remove statement
	data = data[9..length(data)]
    end if

    -- remove data after space
    at = find( ' ', data )
    if at then
	data = data[1..at-1]
    end if

    return data

end function



    -- if statement is a with/without instruction, comment it out
    
    -- include statement missing?
    if match( "with ", data )
    or match( "without ", data ) then

	-- trim white space
	while charClass[ data[1] ] = WHITE_SPACE do
	    data = data[2..length( data ) ]
	end while      

	-- first statement?
	if length( data ) > 8 then      
	    if equal( data[1..5], "with " )
	    or equal( data[1..8], "without " ) then
	    
		-- comment out
		data =  "-- " & data
		
	    end if
	end if

    end if
	
    return data

end function

function trimer(sequence s)
    sequence t
    integer u
    if s[length(s)] = '\n' then
	s = s[1..length(s)-1]
    end if
    if s[length(s)] = '\r' then
	s = s[1..length(s)-1]
    end if
    t = reverse(s)
    u = find(slash, t)
    if not u then
	return s
    end if
    t = t[1..u-1]
    s = reverse(t)
    return s
end function

function includable(sequence name)
    --IGNORE=1 is table, IGNORE=2 is dir
    sequence s
    if IGNORE = 0 then
	return 1
    elsif IGNORE = 1 then
	if not find(name, ignore_table) then
	    return 1
	else
	    return 0
	end if
    elsif IGNORE = 2 then
	s = dir(ignore_dir)
	if atom(s) then
	    return 1
	end if
	s = s[3..length(s)] --skip '.' and '..'
	for i = 1 to length(s) do
	    s[i] = s[i][D_NAME]
	end for
	if not find(name, s) then
	    return 1
	else
	    return 0
	end if
    end if
    return 0 --unknown IGNORE option, so always ignore
end function


    integer inFile
    sequence newPrior, oldPrior, includeName
    object data

    -- find the file
    fName = findFile( fName )

    -- already part of the file?
    if find( fName, included ) then
	return
    else
	included = append( included, fName )
    end if  
    
    -- store locals and clear
    oldPrior = oldLocal
    newPrior = newLocal
    oldLocal = {}
    newLocal = {}

    -- write header                              
    --puts( outFile, "\n" )
    --puts( outFile, repeat( '-', 80 ) & "\n" )
    --puts( outFile, repeat( '-', 80 ) & "\n" )
    --printf( outFile, "-- INCLUDE FILE: %s\n", {fName} )
    --printf( outFile, "--file %s\n", {fName} )
    --puts( outFile, repeat( '-', 80 ) & "\n" )
    --puts( outFile, repeat( '-', 80 ) & "\n" )
    --puts( outFile, "\n" )
    
    inFile = open( fName, "r" )
    
    while 1 do        
    
	-- read a line
	data = gets( inFile )
    
	-- end of file?
	if integer( data ) then
	    exit
	end if

	-- include file?
	includeName = getIncludeName( data )
	--if match("file.e", includeName) then trace(1) end if
	--if length( includeName ) and includable(trimer(includeName)) then
	
	    -- include the file
	    --parseFile( includeName )
	    
	if length(includeName) then --no parse
	    puts( outFile, data )        
	
	elsif sequence(data) and length(data) >= 2 and
		equal(data[1..2], "#!") then --remove all #!
	    puts( outFile, "--"&data )        
	
	else
	
	    -- translate
	    data = parseLine( data )

	    -- remove with/without
	    data = removeWith( data )
	    
	    -- output
	    puts( outFile, data )        
	    
	end if
	
    end while
    
    close( inFile )
    --end of file header
    --puts( outFile, "\n" )
    --printf( outFile, "--end of file %s\n", {fName} )
    --puts( outFile, "\n" )

    -- restore locals
    oldLocal = oldPrior
    newLocal = newPrior

    
end procedure

procedure command_length(integer i, sequence s)
    if length(s) > i then
	printf(2, "\nError - too many parameters! - %s \n", {s[i+1]})
	abort(2)
    end if
end procedure

procedure get_options(sequence c)
    if equal(c[1], "--table") then
	command_length(5, command_line())
	IGNORE = 1
    elsif equal(c[1], "--dir") then
	command_length(6, command_line())
	IGNORE = 2
	if length(c) = 2 then
	    ignore_dir = c[2]
	end if
    else --simulate too many parameters
	command_length(4, command_line())
    end if
end procedure

		  
    sequence cmd, inFileName, outFileName

    -- read the command line
    cmd = command_line()

    -- get input file
    if length( cmd ) > 2 then
	inFileName = cmd[3]
    else
	inFileName = prompt_string( "File to concatonate? " )
	if length( inFileName ) = 0 then
	    abort(0)
	end if
    end if
		     
    -- get output file
    if length( cmd ) > 3 then
	outFileName = cmd[4]
    else
	outFileName = prompt_string( "File to create? " )
	if length( outFileName ) = 0 then
	    abort(0)
	end if
    end if

    --trace(1)
    if length(cmd) > 4 then
	get_options(cmd[5..length(cmd)])
    end if

    -- make sure they are different
    if equal( inFileName, outFileName ) then
	puts( 1, "File names must be different!\n" )
	abort(0)
    end if
		       
    -- open the file
    outFile = open( outFileName, "w" )
    puts(outFile, "--This file was created by namespace.ex\n")
    puts(outFile, "--by JBrown at jbrown105 at hotpop.com\n")
    puts(outFile, "--based on concat.ex, by David Cuny\n")

    -- process the input file
    parseFile( inFileName )
    
    -- close the output file
    close( outFile )
		       
end procedure


run()


--7JfCtLOvnd9MIVvH--

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

70. Re: Namespaces

Could you please explain namespaces?   Why are they important/good/possibly 
bad?  Who uses them and why, etc?

Start at ground zero, as the only namespaces I deal with are on Netware 
volumes, and are certainly unrelated to what you're referring to :).

Thanks,
Ted

--On Sunday, April 29, 2001 03:26:39 PM -0500 jbrown105 at HotPOP.com wrote:

>
>
> Why doesn't euphoria support inline namespaces? it would make combining
> include file much easier! instead, if you want namespaces, you either have
> to write a program that pulls them out into seperate files, or you
> have to write a program that renames the variables & routines in
> a program, like I did. Anyone know why?
>
> TIA,
> jbrown
>
> P.S. I inclose a namespace program in this email,
> and it renames the data, not make a hundred diffrent include files.
>
> --
> Linux User:190064
> Linux Machine:84163
> http://jbrown105.1avenue.com
>
>
>
>

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

71. Re: Namespaces

Howdy!

>Could you please explain namespaces?   Why are they important/good/possibly 
>bad?  Who uses them and why, etc?
>
>Start at ground zero, as the only namespaces I deal with are on Netware 
>volumes, and are certainly unrelated to what you're referring to :).
>
>Thanks,
>Ted

Okay.  Here's a situation in which you need namespaces.  Suppose Bob wrote an
include file named
foo.ew, which has a global function named getValue().

Now suppose John wrote an include file named bar.ew, which also has a global
function named
getValue().

And now, suppose Mr. Fines wrote a Euphoria app like this:

include foo.ew
include bar.ew

atom
	theValue

theValue = getValue()

Now then, which getValue() does the interpreter use?  The one in foo.ew, or
bar.ew?  That's an
itchy situation, and is caused by the fact that Euphoria uses one, global
namespace.  As you may
realize, this causes a hairy situation in which the author of an include file
has to hope to hell
they don't use the same name for a routine as the authors of *all the other
include files* that a
developer might wish to include.

The answer to this is to give one or more include files a separate namespace. 
Many languages do
this.  Here's a modified version of the example with a type of namespacing
scheme that has been
suggested here on the list:

include foo.ew
include bar.ew

atom
	theValue

theValue = foo.getValue()

This tells the interpreter to use foo.ew's getValue, and thus clears up the
ambiguity.  In other
words, it tells the interpreter to use the getValue() in the foo namespace.  If
you wanted to
drop the "foo", you could tell the interpreter to assume that you're talking
about the foo
namespace:

using foo.ew
    theValue = foo.getValue()
end using

Hope I didn't confuse you more,

Travis

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

72. Re: Namespaces

On Sun, Apr 29, 2001 at 05:38:13PM -0500, Ted Fines wrote:
> Could you please explain namespaces?   Why are they important/good/possibly 
> bad?  Who uses them and why, etc?
> 
> Start at ground zero, as the only namespaces I deal with are on Netware 
> volumes, and are certainly unrelated to what you're referring to :).

Of course. Short answer: makes programming easier, as you don't
have to worry about name conficts (i.e. two functions with the name "foo").
Now for the long answer:
You see, in the early days of programming, programming languages didn't
even have variables, just memory addresses. As this was very complicated,
variables were quickly used to simply life. However, this introduced a new
problem: two variables with the same name. At first, it was pretty minor,
because people tended to write everything themselves. However, as
code-sharing gained popularity, it became an extreme cause of errors.
So, in euphoria, routines had their own set of variable names, and local files
have their own as well. That's why you have to use "global" to share a routine,
because of namespacing. The problem with euphoria is that it doesn't support
inline namespaces, which allow programs to define multiple scopes in a single
file. Basicly, you can have the infomation hiding of multiple files in a single
file. That's why namespaces are so useful.

> Thanks,
> Ted

You're welcome.
jbrown

-- 
Linux User:190064
Linux Machine:84163
http://jbrown105.1avenue.com

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

73. Re: Namespaces

Ted Fines wrote:

> Could you please explain namespaces?

OK, the summary first:

   - namespaces exist to prevent name collisions

   - they allow you to use multiple libraries more easily

   - the allow developers to break large libraries into
     smaller files without polluting the global namespace


A name collision occurs when you include a file, and it tries to define a
variable or function with a name that's already in use. This is fairly
common, and programmers tend to use the same sort of naming convention. This
means the user of the library has to go into one of the files and change
names, which is a real pain.

For example, let's imagine that wanted to use a cool library of Jiri's, and
one of my own:

   include jiri_lib.e
   include my_lib.e

Both of us decided to include a global routine called 'abs' because Euphoria
hasn't got one. So in order to use both libraries, I'm going to have to
change the name of the routine in one of the two.

If there were namepaces, instead of the routines going into the 'global'
area, I could tell Euphoria to place them in a different space:

   include jiri_lib.e into jiri
   include my_lib.e into my

To refer to the routines in Jiri's library, I can write:

   jiri.abs()

and those in mine:

   my.abs()

That way, these routines can have the same name, yet still co-exist
peacefully together. So, from a user's point of view, namespaces mean you
can use libraries without having to go in and rename a bunch of routines if
there are collisions.

>From a coder's perspective, namespaces allow you to break up large files
into smaller chunks, and not 'pollute' the global namespace. Here's a simple
example of that:

   integer accumulator
   accumulator = 0

   global procedure add( integer i )
      accumulator += i
   end procedure

   global function clear()
      accumulator = 0
   end function

   global function sum()
      return accumulator
   end function

Here's the library in action:

   clear()
   add(12)
   add(334)
   add(-19)
   ? sum()

Pretty exciting, huh? smile

The routines that are declared as global are the interface that the library
creates. All the internal details are hidden from the user. For example, you
can use the library and never be aware that there's a variable called
'accumulator'.

This is fine and good, until libraries become large - for example, like
Win32Lib. Imagine you broke the example library in half. For it to work, you
would have to declare things that rightfully had been local as global:

   global integer accumulator

And we're back to the problem of name collisions again. With namespaces, you
should be able to avoid this problem.

I hope this helps!

-- David Cuny

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

Search



Quick Links

User menu

Not signed in.

Misc Menu