Re: math.e and misc.e
- Posted by CChris <christian.cuvier at agriculture.?ouv.?r> Aug 03, 2007
- 425 views
Pete Lomax wrote: > > Juergen Luethje wrote: > > > > Pete Lomax wrote: > > > > > }}} <eucode> > > > -- file getelement.e > > > constant get_element_NIL="NI"&'L' -- avoid constant pooling > > > > > > global function get_element(sequence s, integer idx) > > > if idx<1 or idx>length(s) then > > > return get_element_NIL > > > end if > > > return s[idx] > > > end function > > > > > > global function is_my_NIL(object x) > > > return x===get_element_NIL > > > end function > > > </eucode> {{{ > > Unfortunately, I did not understand how is_my_NIL() can distinguish a "NIL" > > that should signal an error from a string "NIL" that is by chance part of > > the data. > > > In the above I renamed NIL as get_element_NIL to make things clearer. > > Technically the 'distinguish a "NIL" that should signal an error from some > other > "NIL"' is instead 'distinguish get_element_NIL from other "NIL"'. > > I assumed the above would be in its own file, so no other code could ever > reference > the constant, or as above rename it to something that won't be. > The function is_my_NIL(x) determines whether x is a reference pointer to the > local constant and should return False if x points to some other "NIL". > The key point being that the only way to get a reference pointer to that local > constant should be that return statement in get_element(). > > While Eu normally detects sequences as (from execute.h): > > SEQUENCE: 100ppppp pppppppp pppppppp pppppppp (29-bit pointer) > > If you avoid that (eg by using the optimised EQUAL_IFW_I which normally only > gets integer operands) and just compare the pointers, as 32-bit dwords, then > it will not match any other "NIL". A case of obtaining the desired feature by > using less code. > > An alternative to "===" is "identity(a,b)". > > Regards, > Pete NIL wouldn't be unique?????? I hope I misunderstood you. I have an application which uses two libraries. Some function in the main code may takes a an argument something that comes from either library. That something is usually not NIL, but might be if something went wrong. Does your proposal imply that I have to care for two different NILs from the libraries, plus the one in my app, because of the second argument of the function? If so, it looks like a very bad idea to me. The absence is unique, because a difference is a difference between two things and 0 < 2. Hence NIL must be unique across any source file set, as many files as it may have. CChris