pil2 errata

7 messages
Open this post in threaded view
|

pil2 errata

 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
Open this post in threaded view
|

Re: pil2 errata

 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 >
Open this post in threaded view
|

Re: pil2 errata

 > 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
Open this post in threaded view
|

Re: pil2 errata

 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 >
Open this post in threaded view
|

Re: pil2 errata

 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