[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: 99 Bottles of Beer...
- From: Philippe Lhoste <PhiLho@...>
- Date: Thu, 7 Dec 2000 09:35:48 -0500
> > 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 ;-)
>
> -- Roberto
>
I used Print in a generic sense, ie. put a trace on a peripheral. But even in
this sense, the name is wrong, as it just returns a value, and doesn't output
it. Perhaps the previous version did a write...
> > 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
>
OK, since you already submitted an entry, I will not send mine, we will wait
for the update of the site (if it is still updated...).
I agree with you, mine is better ;^)) but your is Lua 3.2 compatible.
> >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
OK, but I meant `:' probably doesn't generate a specific bytecode. Anyway, the
syntax highlighting lexer of SciTE must take this symbol in account, and we
display it as an operator, even if is not the case (but so is t.f()...). We
don't make a real lexer, just something helping displaying code in a readable
fashion.
> I've just downloaded Erik's binaries for win. Initially,
> my intention is to be a naive user. By that I mean to
> use Lua Standalone (luaSA?). I would find a tutorial
> on luaSA very useful. I'm willing to proof-read any
> attempt at such a manual. I'll be able to provide the
> perspective of someone who knows C (intermediate level)
> but who is new to luaSA.
>
> Such a tutorial is vital to increasing the use of lua;
> after all, the intention is that there will be more
> end-users (i.e. those using luaSA) than those embedding and
> extending it. Perhaps the wiki will encourage such a 'project'.
> I'm happy to help in any way possible.
>
I agree with that. That's why I published my binaries, because even if Lua is
primarily an extension scripting language, so mainly aimed at users able to
compile a project (embedding Lua), it can also be used as standalone
interpreter, so it should be accessible to users without a proper compiler.
As somebody which have just finished reading the Lua 4.0 manual, I also think
a tutorial (or more!) would be useful.
Don't take me wrong, the reference manual is very clear, and agreable to read,
with numerous small examples. But it is a reference manual, giving minute
details quite early, sometime making forward reference (eg. using the
libraries without introducing them), etc. Not necessarily a bad thing, but a
bit confusing for the first time user.
I am playing with the idea of writing a Lua tutorial myself, but I fear lack
of time will prevent it.
As a Lua beginner, I may not be the most qualified person to do it, but I use
to think that the beginner state is useful for such things, as we are aware of
the problems, pitfalls, and traps where we can trip. Now, Lua is quite an open
community, so one can write such a tutorial, and submit it to public review,
to improve it and add the view of more seasoned Lua programmers.
What I have in mind is to write a full program, like an HTML pre-processor,
showing the various steps, introducing more and more advanced concepts, etc.
I would introduce the tags quite later, the base libraries progressively from
the beginning, drop alternate syntax (like f"string") or give them later.
One point that's necessary is to introduce some smart uses of Lua constructs,
like:
c = {}
function c:f(o)
etc.
Regards.
¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/
http://philho.multimania.com/
_.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._.·´¯`·._