Getting Started

From Swym Wiki
Jump to: navigation, search

Swym is a new programming language, probably best categorized as a functional language. It's statically typed, with type inference and generics, and is implemented in Javascript - which means it can run right here in this wiki page.

'name' = input("What is your name?")

println("Hello, $name!")

Swym's design goal is to be the most readable language ever made. (Obviously, that's very subjective, so don't be surprised if you disagree - especially at first sight. FAQ: No, that's not the same as trying to look "clean" or "pretty". Swym has quite a lot of punctuation to help ensure that the program's structure is clear even when users extend it. FAQ: No, of course not all Swym code will be maximally readable. The language can only provide tools to allow readable code to be written; it cannot enforce it.)

Swym's strategy is to maximize readability by letting users express their program's logic using familiar, intuitive high level concepts - such as "each", "all", "none", "etc", "where" - and define their own, with a minimum of fuss. In a sense, Swym has been designed backwards: the desired programs were written out, and then the language was reverse-engineered around them. For example, this program was written long before it was clear how it worked:

1/2 + 2/4 + 3/8 + etc

The result is a language designed around its syntax, with some very unconventional design choices, and blending a bunch of new ideas with others carefully chosen from Javascript, Python, Haskell, APL, Lisp, and no doubt others.

["Hello", "Guten Tag", "Hola", "Bonjour"].sortBy{.length}

To write your own programs, you can try the interpreter at The language is currently in an early, immature but fairly usable state; a lot of it is subject to change. This wiki is intended to be a language reference and centre for discussion.

forEach[1..100] 'n'->
  // this will be the array ["Fizz"], ["Buzz"], ["Fizz", "Buzz"], or [].
  'output' =
    if( n.divisibleBy(3) ){ "Fizz"}
    if( n.divisibleBy(5) ){ "Buzz" }

  // println prints the array contents without annotation.
  // (trace(output) would add commas and brackets.)

  if( output!=[] )
  { println(output) }
  { println(n) }
Personal tools