Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,11 @@
\ declare a variable which is initialized to the number '0'
var x
\ declare a variable which is initialized to a string "cat"
"cat" var, y
\ Get the value in x, add 20 and store it:
x @ 20 n:+ x !
\ Change the cat to a dog:
"dog" y !

View file

@ -0,0 +1,15 @@
// If not initialized at class/member level, it will be set to null
Integer x = 0;
Integer y; // y is null here
Integer p,q,r; // declare multiple variables
Integer i=1,j=2,k=3; // declare and initialize
/*
* Similar to Integer, below variables can be initialized together separated by ','.
*/
String s = 'a string';
Decimal d = 0.0;
Double dbl = 0.0;
Blob blb = Blob.valueOf('Any String');
Boolean b = true;
AClassName cls = new AClassName();

View file

@ -0,0 +1 @@
1→A

View file

@ -0,0 +1 @@
#Realloc(L₂)

View file

@ -0,0 +1 @@
int a;

View file

@ -0,0 +1 @@
int b,c,d;

View file

@ -0,0 +1 @@
0 => int e;

View file

@ -0,0 +1,41 @@
// declare thread variable, default type null
var(x)
$x->type // null
// declare local variable, default type null
local(x)
#x->type // null
// declare thread variable, initialize with a type, in this case integer
var(x = integer)
// declare local variable, initialize with a type, in this case integer
local(x = integer)
// assign a value to the thread var x
$x = 12
// assign a value to the local var x
$x = 177
// a var always has a data type, even if not declared - then it's null
// a var can either be assigned a type using the name of the type, or a value that is by itself the type
local(y = string)
local(y = 'hello')
'\r'
// demonstrating asCopyDeep and relationship between variables:
local(original) = array('radish', 'carrot', 'cucumber', 'olive')
local(originalaswell) = #original
local(copy) = #original->asCopyDeep
iterate(#original) => {
loop_value->uppercase
}
#original // modified
//array(RADISH, CARROT, CUCUMBER, OLIVE)
'\r'
#originalaswell // modified as well as it was not a deep copy
//array(RADISH, CARROT, CUCUMBER, OLIVE)
'\r'
#copy // unmodified as it used ascopydeep
//array(RADISH, CARROT, CUCUMBER, OLIVE)

View file

@ -0,0 +1,3 @@
x = 23
y = "Hello world!"
z = TRUE -- same effect as z = 1

View file

@ -0,0 +1,3 @@
on foo
put x
end

View file

@ -0,0 +1,2 @@
put value("x")
-- <Void> -- means: undefined

View file

@ -0,0 +1,4 @@
on foo
x = VOID
put x
end

View file

@ -0,0 +1,4 @@
global x
on foo
put x
end

View file

@ -0,0 +1,4 @@
on foo
global x
put x
end

View file

@ -0,0 +1 @@
_global.x = 23

View file

@ -0,0 +1 @@
put _global.x

View file

@ -0,0 +1,11 @@
var x: int = 3
var y = 3 # type inferred to int
var z: int # initialized to 0
let a = 13 # immutable variable
var
b, c: int = 10
s = "foobar"

View file

@ -0,0 +1,6 @@
import: date
: testVariable
| a b c |
Date now ->a
a println ;

View file

@ -0,0 +1,2 @@
integer x = 25, y = 25, z
object {a, b, c} = {{}, 5, "string"}

View file

@ -0,0 +1,6 @@
type hour(integer x)
return x >= 0 and x <= 23
end type
hour h1, h2
h1 = 10 -- ok
h2 = 25 -- error! program aborts with a message

View file

@ -0,0 +1,8 @@
var counter: I32 = 10 // mutable variable 'counter' with value 10
let temp: F64 = 36.6 // immutable variable 'temp'
let str: String // immutable variable 'str' with no initial value
str = "i am a string" // variables must be initialized before use
let another_str = "i am another string" // type of variable 'another_str' infered from assigned value
let b = true
let b' = false // variable names can contain ' to make a distinct variable with almost the same name

View file

@ -0,0 +1,6 @@
var x: I32 = 10
var y: I32 = x = 20
try
Fact(x == 20) // x gets the new value of 20
Fact(y == 10) // y gets the old value of x which is 10
end

View file

@ -0,0 +1 @@
<Variable Name> = <Value>

View file

@ -0,0 +1,16 @@
x = "Hello" # x is a string
see x + nl
x = 5 # x is a number (int)
see x + nl
x = 1.2 # x is a number (double)
see x + nl
x = [1,2,3,4] # x is a list
see x # print list items
x = date() # x is a string contains date
see x + nl
x = time() # x is a string contains time
see x + nl
x = true # x is a number (logical value = 1)
see x + nl
x = false # x is a number (logical value = 0)
see x + nl

View file

@ -0,0 +1,6 @@
list = [1,2,3,"four","five"]
list2 = list
list = []
See list # print the first list - no items to print
See "********" + nl
See list2 # print the second list - contains 5 items

View file

@ -0,0 +1,2 @@
<NUMBER> + <STRING> --> <NUMBER>
<STRING> + <NUMBER> --> <STRING>

View file

@ -0,0 +1,5 @@
x = 10 # x is a number
y = "20" # y is a string
sum = x + y # sum is a number (y will be converted to a number)
Msg = "Sum = " + sum # Msg is a string (sum will be converted to a string)
see Msg + nl

View file

@ -0,0 +1,11 @@
set a 0 > Useless intialization - All lowercase variables have an initial value of 0
set b 66 > Simple variable assignment - ''b'' is now the ASCII value of 66, or the character 'B'
[c=0] set c 5 > Conditional variable assignment - If ''c'' is 0, then set ''c'' to 5
set ? 6 > A "goto" command; Setting the ''?'' variable defines the line of code to be executed next
set z 1 > This line of code will never be executed, because the previous skipped it
set c 10 > Line #5 skipped to here
set d A > Assigning a variable to another variable - ''d'' is now ASCII 65, or the character 'A'
set b ! > The ''!'' deals with I/O. Setting a variable to it receives an input character and assigns it to the variable
set ! a > Setting the exclamation point to a variable outputs that variable
set e (d+1) > Combiners are defined inside round brackets - () - and have an addition and a subtraction function
set f (e-1) > Variable ''e'' was assigned to ''d'' + 1 (65 + 1 = 66, character B), and ''f'' was assigned to ''e'' - 1 (66 - 1 = 65, character A)

View file

@ -0,0 +1,71 @@
import Foundation
// All variables declared outside of a struct/class/etc are global
// Swift is a typed language
// Swift can infer the type of variables
var str = "Hello, playground" // String
let letStr:String = "This is a constant"
// However, all variables must be initialized
// Intialize variable of type String to nil
var str1:String! // str1 is nil
// Assign value to str1
str1 = "foo bar" // str1 is foo bar
// Swift also has optional types
// Declare optional with type of String
var optionalString = Optional<String>("foo bar") // (Some "foo bar")
println(optionalString) // Optional("foo bar")
// Optionals can also be declared with the shorthand ?
var optionalString1:String? = "foo bar"
// ! can be used to force unwrap but will throw a runtime error if trying to unwrap a nil value
println(optionalString1!)
optionalString1 = nil // Is now nil
// println(optionalString1!) would now throw a runtime error
// Optional chaining can be used to gracefully fail if there is a nil value
if let value = optionalString1?.lowercaseString {
// Is never executed
} else {
println("optionalString1 is nil")
}
// Swift also has type aliasing
typealias MyNewType = String // MyNewType is an alias of String
var myNewTypeString = MyNewType("foo bar")
// Swift also has special types Any and AnyObject
// Any can hold any type
// AnyObject can hold any object type
let myAnyObjectString:AnyObject = "foo bar"
// Downcast myAnyObjectString to String
if let myString = myAnyObjectString as? String {
println(myString) // foo bar
} else {
println("myString is not a string")
}
// Swift treats functions as first-class
// Declare a variable with a type of a function that takes no args
// and returns Void
var myFunc:(() -> Void)
func showScopes() {
// Variable is scoped to function
let myFunctionVariable = "foo bar function"
// Nested functions inherit variables declared in enclosing scope
func nestFunc() {
println(myFunctionVariable)
}
nestFunc()
}
myFunc = showScopes // myFunc is now showScopes
myFunc() // foo bar function

View file

@ -0,0 +1,43 @@
# variable declaration
#
# declare [type] [name]
# -or-
# decl [type] [name]
decl int test
# initialization / assignment
#
# the set statement can be used to init variables and
# assign values to them
set test 10
# datatypes
#
# ursa currently has 10 built-in types, but
# more may be added in the future.
# boolean
# double
# file
# function
# int
# iodevice
# port
# serverport
# string
# task
#
# also, java classes may be used as data types
# cygnus/x ursa
# scope
#
# there is a global variable space, and functions
# have their own scope. control statements (for,
# if, try, while) don't have their own scope yet,
# but this will be implemented in the near future
# referencing
#
# variables are referenced by their name
decl port p
out p endl console

View file

@ -0,0 +1 @@
jq -n '1 as $x | (2 as $x | $x) | $x'

View file

@ -0,0 +1 @@
EXPRESSION as $NAME

View file

@ -0,0 +1,2 @@
def test: $x;
test

View file

@ -0,0 +1 @@
jq --arg x 123 -n -f test.jq