really simple list/newline oriented language

First, thanks all to those responded to my post awhile ago. I picked a few brains and got some help, sorry if I didn't get a chance to write back to you.

So I am trying to make a very simple list oriented language (well more like preprocessor ala m4), I think there is a very "natural" solution (something that basically writes itself) to what I am looking for, but I was wondering if I could get some (more) help fleshing out the idea. Basically, I would just want to define list assignment, functions and function application over lists that is very \n delimiter oriented, with the default interpolation behaviour to take cross-products. This would be pseudo example, the idea being that the syntax would be very lightweight over a normal text file...

denotes output



As->{
1
2
3
4
5
}

Bs->{
6
7
8
9
}

AsBs

>16
27
38
49
5

x-> is some number

6x

>6 is some number

6{1,2,3,4}

>61
62
63
64

level1a->{
A
AA
}

level1b->{
B
BB
}

level2->{
level1a level1a
level1a level1b
}

level2

>A A
A AA
AA A
AA AA
A B
A BB
AA B
AA BB




I am not sure exactly how well I've thought this out, but it gives you an idea...it's basically just subsitition with and emphasis on cross products that sacrifices some flexibility for simplicity by imposing things like new line delimiters. I would just need to be able to define lists function and apply them appropriately.

I can kinda see that by imposing newlines, I could swallow things one line at a time, but I keep thinking in terms of encoding an FSM with a bunch of "if" statements...

Should this be a peice of cake using something like recdescent? I would be cool if this was just basically something like a syntax modified perl, so that I could define functions with all the normal goodies.

Many thanks for any advice.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Looks like the list monad

This looks somewhat like a really stripped down version of the list monad. It seems you can't do much other than taking Cartesian products of lists (though in your first example, there was a zip-like operation going on, but no extra syntax to account for it, so I'm not sure what you meant there).

As it happens, taking Cartesian products is what the list monad is all about. We could write your juxtaposition operation in Haskell like

juxta xs ys = do
   x <- xs
   y <- ys
   return (x++y)

or, perhaps more simply:

juxta xs ys = map concat (sequence [xs,ys])

of course, this means that if we want to work with whole lists of juxtaposed lists, we can define:

juxtapose xss = map concat (sequence xss)

So what your language is doing is very close to the list monad's existing behaviour. It's still not entirely clear how you want things to work with nested lists (or if they're an option at all), but if there are no other computations to be done, that justaposition operation is most of an evaluator for your language.

oops

just realized I used juxtaposition for zipping and cross product. I guess I would need to pick one and come up with a symbol for the other.