lua-users home
lua-l archive

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


First-time poster. :)

Thanks to Robert Raschke for pointing me to this list.

I would love to hear from anyone on the topics in the post he forwarded here on my behalf.

A bit about me: In the '80s I implemented VIZ::APL for Z80 CP/M machines, and then I-APL which was VM-based and ported to many platforms (PC, Apple ][, Apple Mac, BBC Micro, ARM, etc).

APL was my language of choice for recreational programming in the 80s, replaced (overnight) by Smalltalk in 1992.  I've designed and implemented various languages over the years both for fun and profit.  Like the original designers of Lua, I always try to find a way even when working commercially to design a language which fits the problem domain and the user base. :)

Here is more background on my new-found interest in Lua.

A few years ago, working under commercial contract, I designed and implemented an embedded language ("Taxcel" - don't ask :) which contained as fundamental datatypes: "lists" (one-dimensional indexed arrays); "dictionaries"; and "functions".  The relevant syntax was:

    a := [4,7,2]   an indexed list of three items
    a := (4,7,2)   another way of writing a
    a(1)           4
    a[3,2,1]       [2,7,4]
    a[1]           [2]
    b := (3)       the same as b := 3
    c := [3]       a one-item list containing 3
    a(b)           2
    a[b]           [2]
    a(c)           [2]
    a[c]           [[2]]

    d := {[x:3,y:5]}   a dictionary with two key-value pairs
    d.x                3
    d("x")             3
    d["x"]             [3]
    d.[x,y]            [3,5]
    d["x","y"]         [3,5]

    f := {(a,b),a+b}   a function
    f := {(args),args(1)+args(2)}   another way of writing f
    {(a,b),a+b}[3,4]   7
    f[3,4]             7
    f(3,4)             7
    f[a,b]             [7,10,5]

    min := {(x,y),x<y:x;y}
    max := {(x,y),x>y:x;y}
    limit := {(x,[lo,hi]),min(max(x,lo),hi)}
    limit(10,[4,9])    9
    limits := a[3,1]   [2,4]
    limit(10,limits)   4
    limit([1,3,5,7],limits)    [2,3,4,4]

    (x,y) := (1,3)     multiple assignment
    (x,y) := (y,x)     swap
    (d.(p,(q,r)),a(2)) := [[1,[2,3]],4]  indexed/structured assignment

Notes:
- "atomic" types are number, string, function
- "collection" types are list, dictionary
- collections can contain items of any type
- (x,...) = [x,...] always - a waste of syntax!
- all functions take a *single* argument, which might be a collection
- function parameters are assigned internally as params := <argument>
- functions are first-class (not illustrated)
- operators can be treated as functions (not illustrated)

Similarities to Lua:
- inline construction of lists and dictionaries (Lua tables)
- indexing of lists
- indexing of dictionaries using .key or ["key"]
- multiple assignment
- functions are first-class
- "environments" are dictionaries and therefore first-class (not illustrated)

Arguable advatages over Lua:
- all functions take a single argument (which may be the empty list)
- more powerful indexing and multiple assignment because of wider lvalue syntax
- operators can be treated as functions, and therefore become first-class

Key differences between Taxcel and Lua:
- Taxcel never coerces strings to or from numbers - a matter of personal taste perhaps
- Lua has permissive length rules for multiple assignment and parameter assignment; Taxcel has strict rules
- Lua "adjusts" the number of items when placing lists inside other lists; Taxcel merely nests lists
- Taxcel has *no* keywords - all iteration, etc, is done by higher-order functions and operators
- Taxcel scope rules disallow changing (more) global variables, so "LOCAL" isn't needed

Fundamental disadvantage of Taxcel:
- No metatables/upvalues/hooks because I never thought of them :)

BTW, I can't see from the Lua ref manual whether Lua operators extend over tables, eg whether (2,3,4)+1 is allowed, over even (2,(3,4))+1; In Taxcel, certain operators (eg + and <) extend over list length and pervade list depth.

After finishing the contract, I finally worked out I could have got rid of the ugly {[...]} and freed up [...] for something else: simply allow id *or* integer-constant keys in ()s:

    a := (4,7,2)       an indexed list of three items
    b := (3)           the same as b := 3
    c := (0:3)         a one-item list containing 3
    a(b)               2
    a(0:b)             (0:2)
    a(c)               (0:2)
    a(0:c)             (0:(0:2))

    d := (x:3,y:5)     a dictionary with two key-value pairs
    d.x                3
    d("x")             3
    d(0:"x")           (0:3)
    d.(x,y)            (3,5)
    d("x","y")         (3,5)

I think this is neater than Lua, :) since ()s are used for list and dictionary definition *and* indexing (*and*, as it happens, for function calls).  This keeps {}s free for inline function definition (I hate keywords :), and []s free for anything else I might want to add.

Anyway, once I'd made this leap in syntax, I then thought that it would be neat to make lists and dictionaries the same "type" (the "keys" of a list are just numbers).  Hence my pleasure in discovering Lua. :)

This is how I want finally to extend and implement my ideas:
- first-class functions and operators
- built-in higher-order operators
- user-defined operators (with names like <<< or +*, or even redefining + locally)
- OO extensions similar to Lua's (similar mechanism?)
- eventually, a pure OO underlying paradigm with added FP syntax and semantics and a "classic" - ie C-like - look.

Ambitious!

Cheers, Paul