Re: object(x) rethink

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

jacques deschĂȘnes wrote:
> 
> 
> Jason wrote:
> 
> >I dunno. I can see it both ways. But changing the behavior would make it
> >inconsistent
> >with integer(x) and sequence(x) unless those, too, returned false for
> >uninitialized
> >variables.
> 
> right
> 
> >And since procedures are different from variables in Euphoria, I don't know
> >if "object(func_name)" makes much sense, especially since you can use or wrap
> >routine_id().
> 
> right again
> 

On those points, I also agree.

> Derek wrote:
> 
> >The assigned() function would return 1 if the symbol has a value, and 0 if it
> >doesn't. This information is useful so we can tell if we need to initialize
> >the symbol or not.
> 
> You already know if you have an uninitialized variable as it generate a
> runtime
> error when you try to use it.
> I'm not convince of the usefullness of assigned().
> 

This is exactly why something like assigned() would be useful.

When several tasks might enter a race condition, you need this sort of mechanism
so as o avoid the race. Crashing without recovery is probably the simplest, but
it is a very annoying feature of Eu I have complained about, namely lack of
ability to detect an error, correct it and resume execution in a supposedly
stabilised state. I say "supposedly" because Eu doesn't have Design by Contract
builtins. The latter would have my yes vote.

In the meantime, it seems to me just as useful to be able to check whether a var
has a value or whether a sequence index is out of bounds. You can check the
latter without crashing, and hus avoid a crash, but not the former. This is
illogical.

> >...With the possible exception being that a function that
> >took a routine_id could be able to tell you things about the routine, such is
> >it a function or procedure, what is name and namespace is, what is parameter
> >signature is, etc ...
> 
> to be pedandic ;) in c# and other languages it's called "reflection".
> 

My idea of the whole thing is to have a meta(identifier,meta_type) function,
which takes a name and a meta property id (I don't care using "TYPE", META_TYPE
or any other flavor). The return value would be a sequence, empty if property not
available or symbol doesn't exist, and {value} otherwise. I don't mind a
{status,value} pair instead. Examples of meta property ids might include:
TYPE - which type was this identifier declared with;
ARGS - list of argument types for a routine. Simple vars return {};
DEFINED - does this identifier exist;
ASSIGNED - was the symbol ever given a value? For routines, the meaning might
be: was the routine ever called?
READONLY - is this a variable that can be assigned?
SCOPE - is identifier private, local or global, or a keyword, ...?

I cannot see how that info could be gathered using an include file - unless it
is another copy of the parser and maintains duplicate info. This would be the
only way to do it currently, and wouldn't be terribly efficient, and wouldn't
work for all the examples above - specifically the ASSIGNED part.

For some of the above, a set_meta(identifier,property_id,new_value) routine
would make sense and make some areas of coding safer.

> 
> Jacques

CChris

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

Search



Quick Links

User menu

Not signed in.

Misc Menu