Ra Vs Cobra

This page assumes you are familiar with Cobra.

Non-English Programming

Non-English programming

Terminal Commands

Ra file extension: .racode To compile and run a Ra file: ra To keep generated .cobra and .mdb files: -keep-files To run a line of Ra code: raline In Ra, use -target:library instead of -target:lib

Namespaces Automatically Included

use System.Text.RegularExpressions use System.Numerics

Comments in Ra

# Singleline comment ##Multiline comment## **Doc comment**

Not Supported

Cannot use "protected", "private", or "public" in Ra (use leading underscores instead) Cannot use spaces for indentation (must use tabs) Compiler options not supported: -color (Ra always outputs in color) -about -path -version

Strings in Ra

"This is a multiline string" singleline"This is a singleline string" "This is a singleline string" asis"This is a raw string" "{tab}" (use {} for special characters) "{2 tabs}" (same as "{tab}{tab}") "{{" (use {{ for a literal {) "[[" (use [[ for a literal [) "blah""blah" (escape quotation marks by doubling them) "\" (a literal \) "{# This is a string comment (useful for patterns)}" c"{tab}" (a character literal) Special characters (Ra -> Cobra): "{0xblah}" -> "\xblah" "{0oblah}" -> "\blah" "{cC}" -> "\cC" "{ublah}" -> "\ublah" "{bell}" -> "\a" "{backspace}" -> "\b" "{new page}" -> "\f" "{new line}" -> CobraCore.newLine (this one is a string, not a character) "{n}" -> "\n" "{r}" -> "\r" "{tab}" -> "\t" "{vertical tab}" -> "\v" "{?}" -> "\?" "{null}" -> "\0" Ra has no equivalent of the "ns" string. Ra has no equivalent of the "sharp" string.

Ra Patterns (Regexes)

Patterns

Operators (Ra -> Cobra)

:= -> = = -> == /= -> <> ^ -> ** ^^ -> ^ Augmented Assignment: :+ -> +=

Types (Ra -> Cobra)

Object -> Object() type reference Object -> Object Object.sharedMethod -> Object.sharedMethod (same syntax) List? of blah -> List? List of blah? -> List Cow{Animal} -> Animal.Cow (enumerator)

Lambdas (Ra -> Cobra)

do foo -> do = foo do(foo as Bar) foobar -> do(foo as Bar) = foobar

Slicing (Ra -> Cobra)

a[1 to 4 by 2] -> a[a:4:2] a[to 4] -> a[:4] a[1 to] -> a[4:] a[by 2] -> a[::2]

Math (Ra -> Cobra)

Math (Ra -> Cobra): empty -> .count == 0 not empty -> .count <> 0 even -> % 2 == 0 odd -> % 2 <> 0 2pi -> 2*RaMath.pi 2e -> 2*RaMath.e 1i -> Complex(0, 1) [2 - 3i] -> Complex(2, -3) infinity -> Double.positiveInfinity negative infinity -> Double.negativeInfinity to radians -> *Math.pi/180 to degrees -> *180/Math.pi random -> CobraCore.random function(blah) -> RaMath.function(blah) (can use either form for RaMath)

Getting Program Information (Ra -> Cobra)

program arguments -> CobraCore.commandLineArgs[1:] ([] if no args) program arguments string -> CobraCore.commandLineArgs[1:].join(" ") ("" if no args) program name -> CobraCore.commandLineArgs[0] program path -> CobraCore.exePath program directory -> Path.getDirectoryName(CobraCore.exePath) on mac -> CobraCore.isRunningOnMac on windows -> CobraCore.isRunningOnWindows on unix -> CobraCore.isRunningOnUnix

Working with Paths and Directories (Ra -> Cobra)

slash -> Path.directorySeparatorChar current directory -> Environment.currentDirectory

Time Spans and Thread Handling

TimeSpan literals: 4s, 4.5s, 4ms, 4min, 4h, 4days Pausing a thread: wait 4s

Minor

There is no need for "..." (indicates the rest of the statement/expression is on the next line) if the line ends with an operator There is no need for "..." if the line ends with a comma (,) and in a print, assert, or trace statement Ra prints "To do:" and "Fix:" comments. Ra recognizes the following variations: # To do: # To do # Todo: # Todo # To-do: # To-do # Fix: # Fix any version of the above with all lower case or all upper case

Ra -> Cobra

create -> init on start -> def main ... -> _ (continue to next line) @arguments -> @args @nowarning -> # .nowarning. exit program -> CobraCore.exit(0) exit program with error code -> CobraCore.exit(1) exit program with blah -> CobraCore.exit(blah) error code -> 1 print color -> Console.foregroundColor print highlight -> Console.backgroundColor reset print color -> Console.resetColor clear console -> Console.clear without new line -> stop boolean -> bool character -> char constant -> const define -> def anything -> dynamic enumeration -> enum external -> extern integer -> int nothing -> nil parallel -> par property -> pro reference -> ref signature -> sig structure -> struct uinteger -> uint field -> var various -> vari exit loop -> break made -> to (casting) String stream -> String* for 10 -> for raReserved in 10


Ra Standard Library