pil2 errata

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

pil2 errata

Taj Khattra
couldn't find an errata list on the pil2 home page...

on pg 60

    function getnext(list, node)
        return not node and list or node.next
    end

shouldn't that be

    if not node then return list else return node.next end

to handle the corner case list==nil?

thanks
Reply | Threaded
Open this post in threaded view
|

Re: pil2 errata

Michael Broughton
The two statements are equivalent. Re-read section 3.3.

Mike



Taj Khattra wrote:

> couldn't find an errata list on the pil2 home page...
>
> on pg 60
>
>    function getnext(list, node)
>        return not node and list or node.next
>    end
>
> shouldn't that be
>
>    if not node then return list else return node.next end
>
> to handle the corner case list==nil?
>
> thanks
>
Reply | Threaded
Open this post in threaded view
|

Re: pil2 errata

Taj Khattra
> The two statements are equivalent. Re-read section 3.3.

> =(function() if not nil then return nil else return 1729 end end)()
nil
> =(not nil and nil or 1729)
1729
Reply | Threaded
Open this post in threaded view
|

Re: pil2 errata

Michael Broughton
I understand that. Sorry, I think I misread your message. I thought you
where commenting on something else.

Now that I think about it, there is a problem with the example but I
don't think we agree on where the problem is. Let me explain:

I expect the following statements to throw the same error...

for node in traverse(nil) do ... end
for node in traverse(8008135) do ... end
for node in traverse("string") do ... end

That seems natural to me. The error message could be made friendlier,
but I don't see why nil needs to be a special case. The problem, in my
opinion, is the following line...

list = nil

For this example, I think that an empty list is better represented by an
empty table than a nil. Of course, a non-empty list can still be
terminated by a nil or an empty table.


Mike



Taj Khattra wrote:
>> The two statements are equivalent. Re-read section 3.3.
>
>> =(function() if not nil then return nil else return 1729 end end)()
> nil
>> =(not nil and nil or 1729)
> 1729
>
Reply | Threaded
Open this post in threaded view
|

Re: pil2 errata

Roberto Ierusalimschy
In reply to this post by Taj Khattra
> couldn't find an errata list on the pil2 home page...

There isn't one yet.


> on pg 60
>
>    function getnext(list, node)
>        return not node and list or node.next
>    end
>
> shouldn't that be
>
>    if not node then return list else return node.next end
>
> to handle the corner case list==nil?

Sure. I guess it is time to create the errata :)

-- Roberto
Reply | Threaded
Open this post in threaded view
|

Re: pil2 errata

Gavin Wraith
In message <[hidden email]> you wrote:

> > couldn't find an errata list on the pil2 home page...
>
> There isn't one yet.

> Sure. I guess it is time to create the errata :)

A small erratum on page 65, penultimate paragraph,
line -8,
"when the chunk in not in" -> "when the chunk is not in"

I have not noticed any others yet.
--
Gavin Wraith ([hidden email])
Home page: http://www.wra1th.plus.com/
Reply | Threaded
Open this post in threaded view
|

Re: pil2 errata

David Burgess
P254 -
"environment over the register" to
"environment over the registry"