[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Digest, Vol 78, Issue 2
- From: KHMan <keinhong@...>
- Date: Wed, 28 Nov 2007 10:39:06 +0800
Hi,
BTW, for an active list participant like you, it will be easier if
you don't receive postings in digest form, otherwise, it's normal
to paste the correct subject in the place of the "Lua Digest"
thingy. Just go and change your list settings. Also, text postings
work best. For an apostrophe, use "'", not a backtick "`". HTH.
XenoLiz wrote:
> |> [snip]
> |> XenoLiz wrote:
> |> > Lua :
> |> > local local_f = function(x,y) return
> |> local_f(x)+local_f(y) end ---
> |> > not work
> |> > local local_g
> |> > local_g = function(x,y) return local_g(x)+local_g(y)
> |> end -- it`s
> |> > half decision
Okay, I don't claim to be an expert or anything, and I've never
formally studied lambda calculus. So, anyway...
>From the little I know or understand of lambda calculus, it's
about anonymous functions. Now, in the above, you seem to be using
local_f in a recursive fashion, but I don't understand why you
define a function with two arguments and then call it with one
argument. For non-math people, Lua syntax support recursive
functions just fine. But, really, I'm not exactly sure what you
are trying to code in the above example. Perhaps a real, practical
example will be better.
> |> > Lua_New:
> |> > local local_f = function(x,y) return *lambda*(self,
> |> > x)+*lambda*(self, y) end
> |> > a={ __main=function(x) return *lambda*(self.super,
> |> x.value) end,
> |> > __run=function(x,y) if x>1 then return function(a,b) return
> |> > *lambda:1:*(self, x-1, a) | *lambda:1:*(self, y-1, b) end
> |> return 1/y
> |> > end }
> |> >
> |> > or something of this kind
> |> [my comments snipped]
As a practical engineer, I sure wouldn't want to maintain code
like the above when I can write it in a more simple way. It may be
elegant or even beautiful in the eyes of a math person, but well,
the average developer will shy away from these things. Given a
choice between a programming language that is procedural and one
that looks like math, I think the market will choose the former.
> About questions you can see into Lua 5.1 Reference Manual $ (2.5.9 -
> Function Definitions)
> [snip]
> (This only makes a difference when the body of the function contains
> references to f.)
Yeah, I guess with a syntax for lambda functions, there is no need
to explicitly name the function in the body. That's one advantage.
> [self(...)] may be use to normal call in current Lua, [function(...)] in
> this context use as function declaration, others?
At first glance, this seems do-able. This works fine in Lua:
local function f(x)
if x == 0 then return 0 end
return f(x-1)+x
end
print(f(10))
Then perhaps this is less daunting for non-math people:
local f = function(x)
if x == 0 then return 0 end
return self(x-1)+x
end
print(f(10))
> PS: '*'lambda'*' its bold text only from html, and may be you suggestion
> better way?
Old timers prefer straight text, on some other lists (e.g. mingw
:-)), people might flame you for using HTML.
--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia