lua-users home
lua-l archive

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


It was thus said that the Great Coroutines once stated:
> On Sat, May 3, 2014 at 5:42 AM, Petite Abeille <petite.abeille@gmail.com> wrote:
> 
> > "It would appear that Lua's clean syntax appeals to language improvers like a clean wall to graffiti sprayers."
> > — David Kastrup, Sep 2010
> 
> This proposed sugar is evaluated once at compile-time, where every
> appearance of string.byte() is always called at runtime.

  Ah, compile time vs. run time.  You must really look into Forth sometime.
It makes that distinction and yes, you can define functions (called "words"
in Forth) to be run at compile time.  Lisp can do this too, but there, such
functions are called "macros".

> Currently the best option is assigning the value to a local once, and
> then using that local identifier throughout a loop.  It gets difficult
> to figure out a name for these identifiers, though.  It also uses up 1
> of the 200 afforded locals you have, but that's a lesser concern.

  That's an optimization the compiler can do automatically.

> It would help if we could put a literal integer value of 'a' there,
> which makes a syntax other than '' and "" necessary for doing this
> transform at compile-time.  I feel that it also makes the code more
> readable than remembering what the identifier references.  Also this
> value would then be read-only, as it would become a literal integer.

  This is the realm of "compiler optimizations" and feelings about that
differ.  C has the keyword "register" to inform the C compiler that the
following variable is to be kept in a register (and consequently, taking the
address of such a variable is now impossible), to help the compiler with
optimizations.

  No one uses the keyword "register" anymore.  The compilers have gotten
very good about optimizing that.

  Part of the reason that Lua compiles so fast is that it does not to much
in the way of optimization.  TCC [1] is also fast [2] but does almost no
optimization what-so-ever.  

> I've also pondered a syntax for having functions evaluated only at
> compile-time if their operands are literal/static -- something like
> @string.byte('a')

  So would 

	@string.byte(somevar)

be an error?

> Is this a blind dislike of any additional syntax sugar that this list
> is so well-known for?  Or do you see it colliding with future plans
> for Lua?  I do think `` might be confused with '' if you're skimming
> quickly -- that is a negativity.

  It depends upon the font used I would think.  Some fonts make it easy to
see the difference between 0 and O; others, not so much (same goes for 1 and
l).

  -spc (Compiles fast, runs fast, please pick one)

[1]	The Tiny-C Compiler.  Look it up.  It's a really cool C99 compiler.

[2]	In 2006, a version of TCC could compile the Linux kernel in under
	ten seconds.  It was used in a proof-of-concept system where, at
	boot time, the boot loader would compile Linux directly into memory.