lua-users home
lua-l archive

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


I think you can get quite close to the syntax, but still will need some extra keystrokes, I'm afraid.

I can conceive using a 'matrix' lib this way:

local m = require 'matrix'

A1 = m'1 2 3' -- m transforms a string into a matrix
A = -A1 -- A is the transpose of A1. minus is the only unary operator in Lua. If you don't like that one, you must use A1.trans or something similar.
B = m'1 1 1; 0 1 1; 0 0 1' -- more parsing
C = B * A -- totally possible in lua via metatables
C['2,3'] = 4   -- Cheat and use strings to index matrices. A bit dirty, yes. But see below.
D = B .. A   -- The concatenation operator (or the power operator: ^) could be used for that one
E = B['1:2,end-1'] -- again, use a string to index the table. This is consistent with the previous usage

I don't have the time or experience to create this myself, but I'm convinced that what I wrote is feasible in vanilla Lua.


On Thu, Nov 1, 2012 at 10:06 PM, forkandwait@gmail.com <forkandwait@gmail.com> wrote:
Rena <hyperhacker <at> gmail.com> writes:


> C[2,3] = 4 would be both clearer and more consistent.

Absolutely.  My question was about C[2,3] instead of C[2][3].  The matlab parens
syntax kind of sucks.