From: ······@gmail.com
Subject: Matlab to Lisp converter?
Date: 
Message-ID: <1167520806.324734.297560@k21g2000cwa.googlegroups.com>
I am just wondering if someone has attempted such a crazy thing? I do
not mean converting all of matlab functions, just enough of its
language to keep matlisp kernel busy numbercrunching using existing
matlab codebase while higher level interfaces are written in more lispy
way...

I've looked at f2c code, learned something for myself, but most of it
seems to be there to deal with random fortran weirdness (common blocks,
etc.) -- I have a feeling that starting from scratch might be easier.

Any ideas/suggestion?

Paul B.
From: zergling
Subject: Re: Matlab to Lisp converter?
Date: 
Message-ID: <1167560781.378873.121810@s34g2000cwa.googlegroups.com>
······@gmail.com ¼g¹D¡G

> I am just wondering if someone has attempted such a crazy thing? I do
> not mean converting all of matlab functions, just enough of its
> language to keep matlisp kernel busy numbercrunching using existing
> matlab codebase while higher level interfaces are written in more lispy
> way...

May I suggest an alternative. clisp has an FFI binding to the Matlab C
foreign interface, which I use. Perhaps a cffi version could be made
based on that, for portability (although you are stuck with whatever
is running Matlab anyway...). I have re-wrapped it with a few
convenience functions, and happily use Matlab from
Slime->clisp->Matlab and back. With a simple Emacs keyboard macro and
Lisp reader macro, I can use Matlab commands as is from the REPL (just
missing tab-completion for Matlab).

For more 'sophisticated' stuff, I use small scripts on the Matlab side
to prepare a Lisp readable string, to be read using read-string on the
Lisp side. I say sophisticated, but as it turned out, Matlab has quite
advanced objects, classes, structs, and whatever else (no garbage
collection that I have been able to find, or perhaps it's a manual
stop and copy gc (you "pack" to disk, and read everything back in to
compact some space)). The problem is its sometimes arcane syntax for
nested structures. I wanted Lisp structs or classes, which are more
consistent than Matlab's.

As it turns out, for what I was doing, Lisp alists were so much more
pliable: easily printed, read out, read back in (light weight
serialization, so simple, yet so useful), first class symbols, print
formats (format & pretty printer variable), and to top it off, inspect
in Slime + Emacs occur just felt so productive, and I didn't have to
write any code for this! Unfortunately, it also meant that I was slow
in setting things down in stone(code) when it comes to repetitive
things... you definitely have to be more disciplined in Lisp. It's too
easy to run wild. I sometimes wonder what my colleagues would think
about code that doesn't use 'objects', that uses O(n) linked lists in
random-access fashion (yeah, they're short lists), or that more or
less ties you into Emacs (if you want to be productive)...

Anyhoo, I'm basically using Matlab for its libraries, and Lisp as my
programming language. It just seems too hard to make an all-Lisp
solution. I suppose if you have lots of legacy Matlab code of your
own, you could use the Matlab to C converter, then Lisp FFI, but that
would still require the Matlab engine/runtime (not sure if you can
make standalone programs). Depending on how desperate you are to get
rid of Matlab, you could subsist on older copies/licenses (not sure of
the details) of Matlab.

Happy consing!