lua-users home
lua-l archive

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

Lua can be considered a "right to left" concatenative language as-is
by using "..." . Translation of the Factor tutorial:

function dup(x, ...)
  return x, x, ...
function reverse(x, ...)
  return (x):reverse(), ...
function normalize(x, ...)
  return x:gsub('[^%w]',''):lower(), ...
function is_eq(x, y, ...)
  return x==y, ...
function is_polynomial(x, ...)
  return is_eq(reverse(dup(normalize(x, ...))))

assert(is_polynomial 'hello' == false)
assert(is_polynomial 'race car' == true)
assert(is_polynomial 'A man, a plan, a canal: Panama.' == true)

Errr maybe that's "left to right". Depends on one's perspective I suppose.

- David

On Fri, Oct 14, 2011 at 3:56 PM, Peter Sommerfeld <> wrote:
> Patrick Mc(avery wrote:
>> I have fallen in love with the concatenative programming paradigm.I spent
>> a month with the Factor language.
> Indeed an interesting language...
>> So I was thinking, do we have to have another language for this?
> Lua is well suited for domain specific languages or playing
> with different paradigms. Eduardo Ochs has bootstrapped a
> Forth in 40 line of Lua (see "Lua programming gems").
>> factor has about 26K  function(words actually). These tinyfunctioncan be
>> used to build other tiny functions veryquickly but againwithout a naming
>> convention it becomes veryhard to follow along with.
> Factor has introspection facilities. I don't like the idea
> of prefixing everything. Why write math.floor() if floor()
> will do ? One table lookup more. Of course, it depends on...
> Peter