Getting started
.தமிழ் is a small programming language with bilingual keywords. You can write the same program in Tamil script or roman characters, and it runs identically either way.
The playground at /playground runs entirely in your browser. No install. No account. Just open it and start typing.
Files use the .தமிழ் extension. Programs are top-to-bottom scripts. Blocks open with a keyword and close with முடிஞ்சுது (or mudinjathu).
Hello world
The simplest program prints a greeting:
சொல்லு "வணக்கம் உலகமே"Or in roman:
sollu "vanakkam ulagame"சொல்லு (or sollu) prints whatever follows it. Strings go inside double quotes.
Variables
Assign a value with =. Names can be in Tamil or roman. Reassign the same name as many times as you like.
பெயர் = "கீதா"
வயசு = 21
சொல்லு பெயர் + " is " + சொல்லா(வயசு)Built-in conversions: சொல்லா(n) turns a number into a string, எண்ணா(s) turns a string into a number.
Numbers and math
Numbers are 64-bit floats, like in JavaScript. The usual operators all work: + - * / %.
சொல்லு 7 + 3 # 10
சொல்லு 10 / 4 # 2.5
சொல்லு 10 % 3 # 1
சொல்லு (2 + 3) * 4 # 20Comparison operators: == != < > <= >=. Logical operators: && || !.
Strings
Strings are double-quoted. Concatenate with +.
வணக்கம் = "வணக்கம்"
சொல்லு வணக்கம் + ", " + "கீதா"Strings know Tamil. நீளம்("தமிழ்") returns 3, not the codepoint count. Indexing, slicing, and iteration all walk graphemes the way a reader would.
சொல்லு நீளம்("தமிழ்") # 3
சொல்லு பகுதி("வணக்கம்", 0, 3) # "வண"
ஒவ்வொரு "தமிழ்" உள்ள ch
சொல்லு ch
முடிஞ்சுதுBooleans
The two boolean values are சரி (true) and பொய் (false). Their roman aliases are sari and poi.
வேலைசெய்தது = சரி
காலியா = பொய்
சொல்லு வேலைசெய்தது && !காலியா # சரிIf and else
Branch with ஒருவேளை (if), இல்லாட்டி_ஒருவேளை (else if), and இல்லாட்டி (else). Every block ends with முடிஞ்சுது.
வயசு = 20
ஒருவேளை வயசு >= 18
சொல்லு "வாக்களிக்கலாம்"
இல்லாட்டி_ஒருவேளை வயசு >= 16
சொல்லு "almost there"
இல்லாட்டி
சொல்லு "இன்னும் வயது போதாது"
முடிஞ்சுதுWhile loops
வரைக்கும் repeats while a condition is true. Use நிறுத்து to break out, தொடரு to skip to the next iteration.
எண் = 1
வரைக்கும் எண் <= 5
சொல்லு எண்
எண் = எண் + 1
முடிஞ்சுதுFor-each loops
ஒவ்வொரு <iterable> உள்ள <var> walks every item in an array, string, or range. Use வரிசை(n) to generate a sequence of numbers.
ஒவ்வொரு வரிசை(5) உள்ள i
சொல்லு i
முடிஞ்சுது
பழங்கள் = ["மா", "வாழை", "ஆப்பிள்"]
ஒவ்வொரு பழங்கள் உள்ள ப
சொல்லு "எனக்கு " + ப + " பிடிக்கும்"
முடிஞ்சுதுArrays
Arrays are square-bracketed lists. Index with arr[i] starting at 0. Mutate with arr[i] = value.
எண்கள் = [10, 20, 30, 40]
சொல்லு எண்கள்[0] # 10
எண்கள்[1] = 99
சொல்லு எண்கள் # [10, 99, 30, 40]
# Append and remove
கூட்டு(எண்கள், 50) # push
கடைசி = எடு(எண்கள்) # popDictionaries
Dictionaries map string keys to values. Use { key: value } literal syntax, and read or write with d[key].
எண் = { "ஒன்று": 1, "இரண்டு": 2 }
சொல்லு எண்["ஒன்று"] # 1
எண்["மூன்று"] = 3
சொல்லு சாவிகள்(எண்) # ["ஒன்று", "இரண்டு", "மூன்று"]
சொல்லு உண்டா(எண், "நான்கு") # பொய்Functions
Define with வேலை, return with திருப்பி_கொடு. Functions can be recursive and capture outer variables.
வேலை வாழ்த்து(பெயர்)
திருப்பி_கொடு "வணக்கம் " + பெயர் + "!"
முடிஞ்சுது
சொல்லு வாழ்த்து("கீதா")
சொல்லு வாழ்த்து("ராஜா")
# Recursion
வேலை fib(n)
ஒருவேளை n < 2
திருப்பி_கொடு n
முடிஞ்சுது
திருப்பி_கொடு fib(n - 1) + fib(n - 2)
முடிஞ்சுதுTry and catch
Run code that might fail inside முயற்சி. Recover inside பிடி <err>. The error string is bound to the named variable.
raw = கேளு "ஒரு எண் கொடுங்க: "
முயற்சி
n = எண்ணா(raw)
சொல்லு "double = " + சொல்லா(n * 2)
பிடி err
சொல்லு "அது எண் இல்ல. சொன்னது: " + raw
முடிஞ்சுதுTamil errors
Every runtime error is reported with a Tamil-first message and a line number. The shape is வரி <N> ல பிழை: <message>.
சொல்லு 5 / 0
# வரி 1 ல பிழை: 0 வைத்து divide செய்ய முடியாதுErrors that bubble out of முயற்சி are caught by பிடி as plain strings.
Standard library
A small set of built-in functions, available globally. Most have a Tamil canonical name and a roman alias.
Strings
நீளம் neelam / length | Returns the length of a string or array. |
எண்ணா ennaa / to number | Converts a string into a number. |
சொல்லா sollaa / to string | Converts a value into a string. |
பிரி pirivu / split | Split a string into an array using a separator. |
இணை inai / join | Join an array of values into a single string. |
பெரிதாக்கு periya / upper | Convert a string to uppercase. |
சிறிதாக்கு siriya / lower | Convert a string to lowercase. |
மாற்று maatru / replace | Replace every occurrence of one substring with another. |
உள்ளதா ulladha / contains | Check whether a string/array/dict contains a value. |
கண்டுபிடி kandupidi / find | Return the index of a substring/element, or -1. |
பகுதி paguthi / slice | Return a portion of a string or array (start ≤ i < end). |
வரிசைப்படுத்து varisaippadu / sort | Return a new array sorted (numbers ascending, strings lexically). |
மீள் meel / reverse | Return the reversed form of a string or array. |
Arrays
கூட்டு koottu / push | Adds an item to the end of an array. |
எடு edu / pop | Remove and return the last item of an array. |
General
வரிசை varisai / range | Generate a number sequence (range). |
தூய்மை thuymai / trim | Remove leading and trailing whitespace. |
Dictionaries
சாவிகள் savigal / keys | Return the keys of a dictionary as an array. |
மதிப்புகள் madhippugal / values | Return the values of a dictionary as an array. |
உண்டா undaa / has | Check whether a dictionary contains a key. |
File extension
Source files use the Tamil-script extension .தமிழ். The playground enforces this automatically. A typical filename:
hello.தமிழ்
வாக்களிப்பு.தமிழ்
fizzbuzz.தமிழ்On the web playground, you can rename files freely. Saved state stays in your browser, in localStorage.
Keyword reference
Every keyword has a canonical Tamil form and one or more roman aliases.
Input / Output
சொல்லு sollu / print | Print output to the console. |
கேளு kelu / input | Read input from the user. |
Control flow
ஒருவேளை oruvelai / if | Run code only when a condition is true. |
இல்லாட்டி illati / else | Runs when the ஒருவேளை condition is false. |
இல்லாட்டி_ஒருவேளை illati oruvelai / else if | Check another condition when the previous if/else-if was false. |
முயற்சி muyarchi / try | Run code that might fail; recover in the பிடி block. |
பிடி pidi / catch | Catch any error from the preceding முயற்சி block. |
Loops
வரைக்கும் varaikkum / while | Repeat the body while the condition is true. |
ஒவ்வொரு ovvoru / for-each | Iterate over each item in an array or string. |
நிறுத்து niruthu / break | Stop the current loop immediately. |
தொடரு thodaru / continue | Skip to the next loop iteration. |
Structure
உள்ள ulla / in | Used inside ஒவ்வொரு before the loop variable. |
முடிஞ்சுது mudinjathu / end | Marks the end of a block (if / while / for / function / try). |
Functions
வேலை velai / function | Define a reusable function. |
திருப்பி_கொடு thiruppi_kodu / return | Return a value from a function. |
Values
சரி sari / true | The boolean value true. |
பொய் poi / false | The boolean value false. |
Comments
Comments start with
#and continue to the end of the line. They are ignored when the program runs.