Documentation problem

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

Documentation problem

Philippe Lhoste-2
I believe there are two little problems with the HTML version of the Lua 4.0 
documentation. I was quite confused by these, until I had the idea of 
cross-checking with the PDF doc.:

4.1 - Lexical Conventions
Missing the '%' character to the list of other tokens.

I am not sure for the absence of `^' (both in HTML and PDF), as it seems to 
belong to the math. lib., but is listed in the binop below.
Same for `:', which is used in the notation t:f(x). Should it be in the list 
above, or is it a special notation, not a token (whatever a token really 
is...)? Since you list this notation as "syntaxic sugar", perhaps it is not a 
real token (ie. doesn't generate a specific bytecode, or something like that).

The Complete Syntax of Lua
binop ::= [snip] | `<B>\^{ </B>' | [snip] | `<B>\&nbsp;{ </B>'=} <BR> [snip]

In the PDF file, we have `^' for the first item (displayed as `\^{ ') and `~=' 
for the second one (displayed as `\ { '=}).
I suppose it is a little bug in a HTML generation program.

On a lighter side, I have found this amusing site:
http://www.ionet.net/~timtroyr/funhouse/beer.html
It is akin to the Hello world site, ie. it is meant to show the implementation 
of a simple task in the maximum number of languages. It is a bit more 
sophisticated than the Hello world, though, because it features loop and 
string formatting.

Of course, I checked to see if Lua was showcased. Not! So I choose to make my 
first Lua program with this exercice. Here is my work:

function PrintBottleNumber(n)
	local bs
	if n == 0 then
		bs = "No more bottles"
	elseif n == 1 then
		bs = "One bottle"
	else
		bs = n .. " bottles"
	end
	return bs .. " of beer"
end

for bn = 99, 1, -1 do
	write(PrintBottleNumber(bn), " on the wall, \n")
	write(PrintBottleNumber(bn), "\n")
	write("Take one down and pass it around,\n")
	write(PrintBottleNumber(bn-1), " on the wall, \n\n")
end
write("No more bottles of beer on the wall,\nNo more bottles of beer\n")
write("Go to the store, buy some more!\n")

It is probably not very Lua-like, ie. I made it more in the spirit of VBScript 
than using advanced Lua features (beside the Lua 4.0 `for'). If you have some 
ideas to improve it...
Otherwise, I will try and send this submission.

Regards.

¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/
http://philho.multimania.com/
_.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._


Reply | Threaded
Open this post in threaded view
|

Re: Documentation problem

Luiz Henrique de Figueiredo
>I believe there are two little problems with the HTML version of the Lua 4.0 
>documentation.

Yes, it is a bug in the conversion to HTML. Sorry about that.
The PS and PDF versions should be taken as "the" correct versions (but probably
have bugs too...)

Thanks for spotting those bugs.
We plan to update the online versions of the manual independently of the code.
We did not do this before releasing 4.0 final to avoid any further delays.

>I am not sure for the absence of `^' (both in HTML and PDF), as it seems to 
>belong to the math. lib., but is listed in the binop below.
>Same for `:', which is used in the notation t:f(x). Should it be in the list 
>above, or is it a special notation, not a token (whatever a token really 
>is...)? Since you list this notation as "syntaxic sugar", perhaps it is not a 
>real token (ie. doesn't generate a specific bytecode, or something like that).

`^' does generate a specific bytecode.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Documentation problem

Roberto Ierusalimschy
In reply to this post by Philippe Lhoste-2
> On a lighter side, I have found this amusing site:
> http://www.ionet.net/~timtroyr/funhouse/beer.html
> ...
> Here is my work:
> ...
> It is probably not very Lua-like,

It is quite Lua-like. (My only small remark would be to change the name of 
the function `PrintBottleNumber', as it does not actually print anything ;-) 

> Otherwise, I will try and send this submission.

Go ahead!

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Documentation problem

Eric Tetz-2
In reply to this post by Philippe Lhoste-2
--- Philippe Lhoste <[hidden email]> wrote:
> Of course, I checked to see if Lua was showcased. Not! So I choose to make my 
> first Lua program with this exercice. Here is my work:
> 
> function PrintBottleNumber(n)
>  local bs
>  if n == 0 then
>     bs = "No more bottles"
>  elseif n == 1 then
>     bs = "One bottle"
>  else
>     bs = n .. " bottles"
>  end
>  return bs .. " of beer"
> end
> 
> for bn = 99, 1, -1 do
>  write(PrintBottleNumber(bn), " on the wall, \n")
>  write(PrintBottleNumber(bn), "\n")
>  write("Take one down and pass it around,\n")
>  write(PrintBottleNumber(bn-1), " on the wall, \n\n")
> end
> write("No more bottles of beer on the wall,\nNo more bottles of beer\n")
> write("Go to the store, buy some more!\n")

Bizarre... I just posted a Lua entry to that site a few weeks ago:

   function bottle(n)
      if     n==0 then return 'no more bottles'
      elseif n==1 then return '1 bottle'
      else             return n..' bottles'
      end
   end

   n=99
   while (n > 0)
      print (bottle(n)..' of beer on the wall,')
      print (bottle(n)..' of beer.\nTake one down,\npass it around,')
      n = n - 1
      print (bottle(n)..' of beer on the wall.\n')
   end

Pretty dang close (though yours is a bit better).

Cheers,
Eric


__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/