lua-users home
lua-l archive

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


2014-04-10 10:01 GMT+02:00 steve donovan <steve.j.donovan@gmail.com>:
> On Thu, Apr 10, 2014 at 9:54 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>>> 3 4⍴⍳12
>> 1  2  3  4
>> 5  6  7  8
>> 9 10 11 12
>>> A←3 4⍴⍳12
>>> 2 3 4⌹A
>> ¯0.35 ¯0.075 0.2 0.475
>
> That gave me a nostalgia rush (not all APL memories are painful).
>
> But surely it is awkward to type without a special keyboard? (we used
> to have special IBM golf ball terminals to speak APL with the
> mainframe)

On any X-Window system, including Linux, it is this easy:

$ xmodmap lua-apl.xmodmap

After which, Alt-Gr selects the APL characters from the keys where
old-timers have always found them. You can print a little card to
remind you (as the old-timers need to before their fingers learnt
the way).

For people from Asia or Eastern Europe, MS Windows probably would
also be this easy. It's only us English speakers that don't bother to learn
how to type letters with diacritics.

> I suppose my concern is that the compact notation favoured by
> mathematicians (so they can cram as many thoughts onto a A4 page as
> possible[1]) is not necessarily something to be admired in production
> code ;)

Like most other things, compact notation has its place and only gets
obfuscated when abused. Disciplined APL programmers define lots
of functions with informative names. Then APL syntax, like Forth syntax,
allows your actual user interface to be just the standard interpreter,
to which you speak a restricted dialect of broken English.

My APL implementation uses an object for APL arrays, a large
Lua library for manipulating those, and a parser cum code
generator in LPeg that turns APL code into Lua code.

> f=apl"2 3 4⌹A"
> lua(f)
return MatDiv(_V.A,{2,3,4})



The biggest problem I have with APL in Lua is that of namespaces.
I've made _ENV to be a fallback for the APL namespace _V, so that
APL expressions have read-only access to global variables unless
shadowed.