sparist / Om

The Om programming language.
http://om-language.org
Other
169 stars 8 forks source link

Add more complete examples #13

Closed kud1ing closed 11 years ago

kud1ing commented 11 years ago

I like the reference documentation (e.g. Operations, Programs) but have a hard time to imagine how a more complete Om script would look and feel.

I am thinking of simple stuff like HelloWorld or Fibonacci et al.

sparist commented 11 years ago

There are a few examples ( http://sparist.github.com/Om/#examples ), but these should certainly be expanded.

This will depend on more features being added to the language, as it doesn't do much yet. In the short term, features should be prioritized by how well they support better examples.

kud1ing commented 11 years ago

I've seen them thanks. Some simple programs having some more evaluation steps would be nice.

I am not sure whether one would end up with a lot of nested operands like {foo {bar {baz {x y z}} in trivial applications already or not.

FireyFly commented 11 years ago

Here's an attempt at implementing foldl in Om, which I guess works as a slightly more complex program. Feel free to add it to the examples page if you wish, and improve it as my implementation is probably a bit awkward since I just started toying around with the language. Note the operand order--function is expected to be the last parameter (because I'm lazy and it was easier that way implementation-wise).

define
{ foldl
  { dequote
    choose{
      rearrange{B}{_ B _}
    }{
      foldl
      dequote
      rearrange{D C A B D}{A B C D}
      <-terms
    }
    copy
    swap
  }
}
{ foldl{1}{2 3 4}{drop} }
sparist commented 11 years ago

Thanks. A function like foldl is a great example. I'll see if your definition can be refactored and definitely add the result to the example page.

Until more high-level operations get added to Om, things will unfortunately be complex to define. However, my belief is that once the language matures, definitions will be at least as simple as in any other concatenative language (such as Factor), and potentially simpler, since (a) prefix notation is more powerful than postfix, and (b) data types need not be considered in the same way.

sparist commented 11 years ago

Leaving this ticket closed for now; adding examples will be an ongoing process, as well as improving on existing ones (my foldl code is verbose as well at the moment, but will be refactored further -- clear idioms haven't developed yet, and the operation library is still pretty sparse).