ClojureScript/Lua

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ClojureScript/Lua

Henk Boom-2
I found this via r/Lua. ClojureScript/Lua is a version of the
ClojureScript compiler that targets Lua.

http://raphamiard.posterous.com/clojurescriptlua-lives

I used Clojure for a little while a few years ago, it's a very
interesting Lisp/Scheme-like language.

Someone posted about it here when the project started a few months
ago, but it looks like there's been a release. Unfortunately the
compiler is still JVM-hosted, though, and the performance is described
in that post as "Not very good". Still, I can't wait to see where this
goes!

    henk

Reply | Threaded
Open this post in threaded view
|

Re: ClojureScript/Lua

Eike Decker
Quoting from the site
"The first thing i had to overcome in porting the Javascript backend
to Lua, is that in Lua, not everything is an object. "

I have to object. Maybe I should do a blog post on how functions CAN
have attributes IF you are crazy enough to want it. I don't think it
should be done though.

---
-- setting the metatable of one function affects all functions...
debug.setmetatable(function()end,{__index = function (f,k) return "foo" end})

print(print.bar) -- prints "foo"
---

With some more fantasy and time, one can do just anything with
function as it is in JavaScript. It's simply not obvious.

Cheers,
Eike


2012/8/8 Henk Boom <[hidden email]>:

> I found this via r/Lua. ClojureScript/Lua is a version of the
> ClojureScript compiler that targets Lua.
>
> http://raphamiard.posterous.com/clojurescriptlua-lives
>
> I used Clojure for a little while a few years ago, it's a very
> interesting Lisp/Scheme-like language.
>
> Someone posted about it here when the project started a few months
> ago, but it looks like there's been a release. Unfortunately the
> compiler is still JVM-hosted, though, and the performance is described
> in that post as "Not very good". Still, I can't wait to see where this
> goes!
>
>     henk
>

Reply | Threaded
Open this post in threaded view
|

Re: ClojureScript/Lua

David Manura
On Thu, Aug 9, 2012 at 4:26 AM, Eike Decker <[hidden email]> wrote:
> Quoting from the site
>> "The first thing i had to overcome in porting the Javascript backend
>> to Lua, is that in Lua, not everything is an object. "
>[...]
> -- setting the metatable of one function affects all functions...
> debug.setmetatable(function()end,{__index = function (f,k) return "foo" end})

Achieving the desired "store all kinds of information on the function
itself, which you can use later. The clojurescript compiler uses that
extensively, most notably for variable arity function dispatch, and
for functions with rest arguments" might also be done with some global
weak tables keyed by a function object:

  local cljs__lang__arity__1 = setmetatable({}, {__mode='k'})
  ...
  cljs__lang__arity__1[a] = function (b) return b end

I don't know if they considered that, but it avoids both the
functables and debug.setmetatable.