File: prism-concurnas.html

package info (click to toggle)
node-prismjs 1.30.0%2Bdfsg%2B~1.26.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,220 kB
  • sloc: javascript: 27,628; makefile: 9; sh: 7; awk: 4
file content (89 lines) | stat: -rw-r--r-- 2,111 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<h2>Comments</h2>
<pre><code>// This is a comment
/* This is a comment
on multiple lines */</code></pre>

<h2>Numbers</h2>
<pre><code>12
12e5
12.f
12f
12d
12.d
12.0
12.0f
12.0d</code></pre>

<h2>strings and language extensions</h2>
<pre><code>"hi"
'hi'
'c'
'what "yach"'
s'c'
"c"
r"[a-z|A-Z]+"</code></pre>

<h2>Functions</h2>
<pre><code>def add(a int, b int) => a + b</code></pre>

<h2>Language Extensions</h2>
<pre><code>dcalc = mylisp||(+ 1 2 (* 2 3))|| // == 9

myFortran || program hello
          		print *, "Hello World!"
       		 end program hello|| //prints "Hello World!"

lotto = myAPL || x[⍋x←6?40] || //6 unique random numbers from 1 to 40</code></pre>

<h2>Full example</h2>
<pre><code>//an overloaded function
def adder(a int, b int) => a + b
def adder(a int, b float) => adder(a, b as int)
def adder(a int) => adder(a, 10)

//a default value
def powerPlus(a int, raiseTo = 2, c int) => a ** raiseTo + c

//call our function with a default value
res1 = powerPlus(4, 10)//second argument defaults to '2'
res2 = powerPlus(4, 3, 10)//second argument provided

//calling a function with named parameters:
def powerAdder(a int, raiseATo = 2, b int, raiseBTo = 2) => a**raiseATo + b**raiseBTo
res3 = powerAdder(2, 4, raiseATo=3)//equivalent to: powerAdder(2, 3, 4, 2)

//varargs:
def sum(elms int...) int {
  res = 0
  for(elm in elms){
    res += elm
  }
  res
}

//call our function with a vararg
thesum = sum(1, 2, 3, 4, 5)

//partially defined typedef
typedef NameMap&lt;X> = java.util.ArrayList&lt;java.util.HashMap&lt;String, java.util.HashSet&lt;X>>>

//using typedefs...
nm NameMap&lt;String>= new NameMap&lt;String>()

@Annotation
class MyClass(a int, b int, c String){
  override toString() => 'MyClass({a}, {b}, "{c}")'
}

mc1 = MyClass(12, 14, "hi there")
mc2 = mc1@ //copy mc1

assert mc1 == mc2//same values!
assert mc1 &&lt;> mc2//different objects!

mc3 = mc1@(a = 100)//copy mc1 but overwrite value of a
assert 'MyClass(100, 14, "hi there")' == mc3.toString()

mc4 = mc1@(&lt;a, b>)//copy mc1 but exclude a and b
assert 'MyClass(0, 0, "hi there")' == mc3.toString()
</code></pre>