Re: math.e and misc.e

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

Juergen Luethje wrote:
> 
> jacques deschênes wrote:
> 
> [quoting order rearranged]
> 
> > Juergen Luethje wrote:
> > 
> > > jacques deschênes wrote:
> > > 
> > > > Not so, many languages have a nil value and doesn't use any special "if"
> > > > for
> > > > it.
> > > > Some simply define in their semantic that a nil should be considered as
> > > > false
> > > > in boolean expression.
> > > > 
> > > > regards,
> > > > Jacques Deschênes
> > > 
> > > Then I'd like to repeat me old suggestion: introduce a NIL value in
> > > Euphoria.
> > > Not necessarily tomorrow or next week, but ... smile
> > > The main advantage in practice IMHO would be to have a special value
> > > available that can be returned by user-defined functions to unambiguously
> > > tell the calling program that there was an error in the function.
> > > 
> > > <snip>
> > > 
> > > Regards,
> > >    Juergen
> > 
> > Hi Juergen,
> > 
> > Language that use nil values usualy don't use for reporting error but to
> > signal
> > that an undefined state.
> > for exemple
> > sequence  s
> > if s = nil then ....
> > here nul is use to check if s have been assigned a value and report true if
> > it's not the case.
> > I don't think nil should be used to report error state, it would be rather
> > confusing
> > to me.
> > 
> > regards,
> > Jacques Deschênes
> 
> E.g. in Lua, nil is used like this:
> | Nil is a type with a single value, nil, whose main property is to be
> | different from any other value. As we have seen, a global variable has
> | a nil value by default, before a first assignment, and you can assign
> | nil to a global variable to delete it. Lua uses nil as a kind of
> | non-value, to represent the absence of a useful value.
> Source: [<a
> href="http://www.lua.org/pil/2.1.html">http://www.lua.org/pil/2.1.html</a>]

this is exactly what I was meaning in my post.

> 
> "to represent the absence of a useful value" is very general. I think it
> includes both the usage that I described, and the usage described by you.
> 
> Just some examles for the useage of nil in Euphoria that come
> spontaneously to my mind:
> }}}
<eucode>
> function calc_something (...)
>    atom a, atom b
> 
>    a = <blah>
>    b = <blah>
>    ...
>    if b = 0 then
>       return nil   -- nil represents the absence of a useful return value
>    else
>       return a/b
>    end if
> end function
> 
> function find_something (sequence list, integer idx)
>    object x
> 
>    if idx < 1 or idx > length(list) then
>       return nil   -- nil represents the absence of a useful return value
>    end if
> 
>    x = list[1]
>    for i = 2 to length(list) do
>       ...
>    end for
>    return <blah>
> end function
> </eucode>
{{{

> Rehards,
>    Juergen

I agree with it,  in your exemples  the 'nil' return value doesn't signal an
error but a case where the function result is not defined.
That OK, and those cases must be mentionned it the doc.

regards,
Jacques Deschênes

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

Search



Quick Links

User menu

Not signed in.

Misc Menu