lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


BTW, the reason I used Set{} as the name for "make me some keys" was
it was in PiL: http://www.lua.org/pil/11.5.html

invert makes sense if it's explained that way. After the first call
(shaking out {a=1, b=1}) it should be inverses forever unless I'm
missing some fiendish IEEE NaN trap.

Casual module loading scares me.

On Sun, Feb 19, 2012 at 6:30 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> Op 18 februari 2012 19:54 schreef steve donovan <steve.j.donovan@gmail.com>
> het volgende:

>> Since people have said such nice things to me I've made a new version,
>> at a more convenient home:
>>
>> https://github.com/stevedonovan/Microlight

>> It's the start of a community process to find the Top Thirty useful
>> functions.
>
> 1. Every user of Microlight will say every time
>
>         tostring = tstring

They're probably going to regret that eventually. Perhaps I'm making
necessity into virtue, but I find it a useful stumbling block to have
not-so-useful results pop out of tostring() for objects without value
semantics. Python separates str and repr[1] for decent reasons. Scheme
distinguishes these uses at IO time with display vs write.

My idea of the charter of tostring() is that it returns something in
O(1) time. The time we really need tables dumped out is in interaction
and tracing. (Plus persist, but that's different, so now already we
have two candidates for the "real" composite tostring on tables.) I
would have less hesitation in replacing print with a version calling
tstring() on its arguments. As the Lua manuals say, "print is not
intended for formatted output, but only as a quick way to show a
value, for instance for debugging."
http://www.lua.org/manual/5.2/manual.html#pdf-print

So yeah, so that's orig_print(unpack(imap(tstring, {...}))) in
functional syntax. Writing "{...}" is distasteful as there's no need
to construct a list when you just need iteration. But how big is the
list and how often do you call print? How much does a list cost in GC
if if never leaves the nursery? And if print() really did
fflush(stdout) after every call that would dominate runtime in
situations when stdout was buffered.

I've seen a couple non-lua.c environments define d(...) or D(...) as a
debug-print function, but that's going a bit far for me. I suppose you
could local d=dprint. lua.c does call _G.print, so changing the
behavior of that global will change how =foo works.

I'll idly note that "return f(unpack(imap(g, {...})))" seems to pop up
now and then and has an efficient C implementation not available in
Lua--you mutate the stack in-place, since you know you're going to
tail-call f and nobody can notice. If allowable to mutate "..." it's
trivial of course.

Or, since there's more than one reasonable thing for tostring to
return, the cautious approach would be to error out on non-tables and
not even let somebody drop it into _G.tostring with all the mess that
would cause for other libraries etc.

As probably the sole public distributor of code incorporating ml I
ought to upgrade too--although ironically when run on itself it's the
one kind of program specifically not affected! Anyway the name
"nighlight" doesn't seem to be taken either. (I guess nightlights are
for when there isn't enough moonlight to see by.)

Jay

[1]: http://docs.python.org/library/functions.html#repr
http://docs.python.org/library/functions.html#str