[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Misc Qs: Passing Strings, Table Terminology, Coroutine Limitations
- From: Veli-Pekka Tätilä <vtatila@...>
- Date: Mon, 30 Jun 2008 10:21:57 +0300
Hi,
Sorry to bother you again. This is the third and final post from me for a
little while, haha. These are partly implementation and convention
questions, I guess, and there are a couple:
1. PIL 1st ed says strings are immutable and any changes make a copy of a
string. The ref manual also says only tables are passed by reference. Does
that mean that a string is needlessly copied by value when I pass it to a
function (ala Perl if you copy args to my variables in that language)? one
would think it wouldn't have to be. That is if you only access a string as a
parameter, then surely you don't need a separate copy. And even if you tried
to modify it, that modification would yield a new string, i.e. there's no
fear of clobbering the original.
2. What should I call tables indexed by a continuous range of ints as
opposed to arbitrary strings in documenting functions? In Perl you have the
terms array and hash. In Lua most folks talk about tables but that's sort of
ambiguous. I'd be tempted to call tables indexed by int lists, but Perl uses
the term list specially, and even in Lua it mostly brings to mind list
assignments and vararg lists. Does it make sense to use the terms array,
record, hash and sparce array depending on whether you'll use the table for
storing elems by int indeces, named fields, looking up stuff by arbitrary
data or storing noncontiguous runs of int indexed elements?
3. There's a bit in the ref man about coroutines I'd like clarified:
Quote about yield:
Suspends the execution of the calling coroutine. The coroutine cannot be
running a C function, a metamethod, or an iterator.
End quote.
Umm what's this about? Surely you can do iterators using coroutines or even
yield in the middle of a for in statement, right? Does the C function bit
have any relevance if I'm only using Lua. SUrely if I call a C function I
cannot do anything before it returns anyway. Howabout Lua code that is
called from a C app, If I got it right, that's still eligible for using
coroutines normally.
I think I've fundamentally misunderstood something in the above brief
description, oh well. Lists like these are great for clarifying points such
as this.
--
With kind regards Veli-Pekka Tätilä
Accessibility, Apps and Coding plus Synths and Music:
http://vtatila.kapsi.fi