Re: Rob: Q: Constant Scope

new topic     » goto parent     » topic index » view thread      » older message » newer message

Robert Craig wrote:
> 
> Vincent wrote:
> > The ref manual says:
> > "Constants may not be declared inside a subroutine." 
> > "Constant declarations must be outside of any subroutine. Constants can
> > be global or local, but not private."
> > 
> > Can you tell me why you made the language support only constant declera-
> > tions at top-level, and not support it at routine level (private scope)?
> > I'm just curious on why made it this way. What are the disadvantages?
> > 
> > I'm trying to figure out whether or not I want to add this functionability
> > into my
> > custom interpreter, and I wanted to know what you thought about
> > it.
> 
> Here's something I wrote a few years ago, that discusses this issue
> and a few other contentious issues:
> 
> <a
> href="http://www.listfilter.com/cgi-bin/esearch.exu?fromMonth=2&fromYear=7&toMonth=2&toYear=7&postedBy=rds&keywords=constant+scope+routine">http://www.listfilter.com/cgi-bin/esearch.exu?fromMonth=2&fromYear=7&toMonth=2&toYear=7&postedBy=rds&keywords=constant+scope+routine</a>
> 
> In language design there is rarely a "right answer".
> Things are very subjective.
> 

I see your point on how this can cause some confusion...

Your example: (slightly modified)
function aaa(integer z)
object d, e, f
constant a = 99 * foo()
integer b = 99 + bar() * 7, h, i, g = 777
atom c
g += 1
h = g
z = h
return z + b / a
end function


In your example, "integer b & g" uses assignment at declare and right
above it is "constant a", which must use that method--plus the mixed
types have the constant in the same group of code without seperation;
that could cause confusion to the untrained eye.

I was thinking about assignment at declare too as a syntax improvement,
but now I think if I were to add support for private constants within routines,
it would be better to leave it out, while still forcing it
upon constants. That alone greatly helps to destinguish constants from
variables.

New example:
function aaa(integer z)
    constant a = 99 * foo()

    object d, e, f
    integer b, h, i, g
    atom c

    b = 99 + bar() * 7
    g = 777
    g += 1
    h = g
    z = h

    return (z + (b / a))
end function


All the code in the example above has organized grouping: seperating
constant from types, assigment from decleration, and "return" from
the rest; along with the standard four space block indentation. That
organizes the code and eliminates any confusion.

> > Another question... Is there anyway I can use global variables in
> > Eu2C translated/compiled DLLs, being able to use define_c_var()?
> > If not, could you consider, adding support for it in the next
> > release? I tried making an example but it didnt work, maybe I did
> > somthing wrong?
> 
> I have an example of define_c_var() in a Linux demo.
> It lets the Euphoria program access a C variable in a shared library.
> I don't know how well that works in the Windows world.
> I think in Windows, it might only be routines that can be 
> exported from a .dll, not variables. Maybe someone else here has tried it.
> 

I was talking more about global variables being exported to translated +
compiled DLLs via Euphoria to C translator. I made a extremely simple
example, which didnt seem to work using define_c_var() with the DLL and variable
name (string). I think it would be worthwhile to add support
for this, even if it would'nt be a common use. Or is there something I'm
not understanding about all this?


Thanks,
Vincent


Without walls and fences, there is no need for Windows and Gates.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu