Gammapedia is archived. No new edits are allowed and no new accounts can be registered.

Ikepedia is the officially decreed successor to Gammapedia concerning Gammasphere canon.

Infinitypedia is another successor.

User:Abwayax/Smeth language sketch

From Gammapedia
Revision as of 06:58, 21 February 2007 by 24.243.12.186 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The goal of the Smeth project is to create a programming language that resembles the English language as much as possible.

Basic syntax rules

Smeth syntax closely follows English grammar.

  • Statements begin with a capital letter and end with a period.
  • Multiple statements are chained together by commas, with the final statement ending in a period.
  • Variables are case-sensitive.
  • Parentheses act as comment delimiters outside of statements. Inside of statements they group expressions.

Hello world program

Print "Hello world!".

Setting variables

Set x to 3 * x + 1.

If statement example

If x equals 3 * x + 1, then print "Awesome", else, print "No way!".

Multiple lines

If answer equals 42 and answer equals 6 * 9:
	Print "That's it. That's all there is.",
	Set marvin to "Paranoid Android",
	Print marvin,
	Print answer.

For loop example

Loop i from 1 to 10, increasing i by 1: Print i.

While loop example

While i is less than 10, increase i by 1. (You could also write "Set i equal to i + 1.")

Function declaration

Declare function foo with parameters bar, baz, qux:
	Return bar + baz + qux.
Print foo 2, 3, 4.

Array creation, access, and modification

Set odds to 1, 3, 5, 7, 9, 10.
Remove element 6 from odds. (odds now has 1, 3, 5, 7, 9)
Add 11 to odds. (odds has 1, 3, 5, 7, 9, 11)
Set element 6 in odds to 13. (odds = 1, 3, 5, 7, 9, 13)
Add 11 to odds at position 6. (odds = 1, 3, 5, 7, 9, 11, 13)
Print element 0 in odds. (prints 1)
Print odds. (prints 1, 3, 5, 7, 9, 11, 13)

Foreach loop

For each element e in odds, print e.

Multiline version

For each element e in odds:
	Print e,
	Print e + 1,
	Print foo e, e+2, e+4.