lua-users home
lua-l archive

Re: Some crazy proposals :-)

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


On 09/07/15 02:13 PM, Andrew Starks wrote:
On Thursday, July 9, 2015, Rena <hyperhacker@gmail.com <mailto:hyperhacker@gmail.com>> wrote:
 On Jul 9, 2015 11:04 AM, "Egor Skriptunoff"
 <egor.skriptunoff@gmail.com
 <javascript:_e(%7B%7D,'cvml','egor.skriptunoff@gmail.com');>> wrote:
 >
 > Hi!
 >
 > The following "proposals" are just for fun.
 >
 > -----------------------------
 > 1) A must-have "dont" statement :-)
 >
 > dont
 > -- code inside dont..end block will be skipped
 > -- useful for easy commenting do..end block
 > end
 >
 > "dont" is also applicable to any block: if, while, for,
 multiline assignment, function definition, etc.
 >
 > dont if ... then -- this condition will not be evaluated
 > -- this code will be skipped
 > else
 > -- this code will be skipped too
 > end
 >
 > "dont" statement acts as --[[...]] comment, but only for a
 single statement inside
 > When using "dont" we do not need to search for a place where
 very long statement ends, so using "dont" is more easy than --[[...]]
 > The "dont...end" is a syntactic sugar for "dont do...end"
 >
 > -----------------------------
 > 2) Famous "comefrom" operator as the opposite to "goto"
 >
 > ...
 > ::label1::
 > ...
 > comefrom label1, label2, label3
 > ...
 > ::label2::
 > ...
 > ::label3::
 > ...
 >
 > is equivalent to
 >
 > ...
 > goto label0
 > ...
 > ::label0::
 > ...
 > goto label0
 > ...
 > goto label0
 > ...
 >
 > -----------------------------
 > 3) Labels are considered to be first-class citizens
 >
 > ::Label1::
 > ...
 > local my_label = Label1 -- assigning a value of type "label" to
 a variable
 > ...
 > -- Now "goto" operator gets its real power!
 > goto my_array_of_labels[where_do_you_want_to_go_today]
 > ...
 > -- And of course the same is true for "comefrom" :-)
 > comefrom get_some_labels()
 > -- it is equivalent to "comefrom label1, label2,..."
 > -- where label1, label2,.. are values returned by LAST
 invocation of get_some_labels()
 > -- "comefrom" without labels is valid (it just does nothing useful)
 > ...
 >
 > -----------------------------
 > 4) Program can modify its own body using methods of labels
 > A label is a "bookmark" between statements in a program (or
 before first statement or after last statement)
 > A label may be named (defined at compile time) or unnamed
 (created at runtime)
 >
 > ...
 > some_func(some_params)
 > ...
 > -- standard library function to create unnamed label just before
 current statement
 > local here = labels.this_label()
 > -- create label just before some_func invocation
 > local previous_some_func_invocation =
 here:search_nearest("backward", "call", "some_func")
 > -- replace "some_func()" with "another_func()" in the program body
 > previous_some_func_invocation:replace_statement("another_func()")
 > ...
 > -- go to unnamed label
 > goto previous_some_func_invocation
 > ...
 >
 > -----------------------------
 > The source of craziness:
 > www.modell.com/Magery/SPharmful.html
 <http://www.modell.com/Magery/SPharmful.html>
 >
 > -- Egor
 >
 Computed goto isn't *that* crazy. It's how things like jump tables
 and switch statements are implemented. Lua doesn't really *need*
 them though since it has first class functions.
I will not rest until we can use Lua patterns for variable names:
.*_foo = nil
Ruby probably already has this feature.
Reminds me of Perl. How do you parse `t.*x`?
--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.

AltStyle によって変換されたページ (->オリジナル) /