[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Concatenative Programming was( help with naming convention)
- From: David Hollander <dhllndr@...>
- Date: Sun, 23 Oct 2011 08:18:29 -0500
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, ...
end
function reverse(x, ...)
return (x):reverse(), ...
end
function normalize(x, ...)
return x:gsub('[^%w]',''):lower(), ...
end
function is_eq(x, y, ...)
return x==y, ...
end
function is_polynomial(x, ...)
return is_eq(reverse(dup(normalize(x, ...))))
end
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 <lua@rubrica.at> 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
>
>