Debian Codegraph @

examples/prism-concurnas.html

raw symbols SCIP
1 <h2>Comments</h2>
2 <pre><code>// This is a comment
3 /* This is a comment
4 on multiple lines */</code></pre>
5
6 <h2>Numbers</h2>
7 <pre><code>12
8 12e5
9 12.f
10 12f
11 12d
12 12.d
13 12.0
14 12.0f
15 12.0d</code></pre>
16
17 <h2>strings and language extensions</h2>
18 <pre><code>"hi"
19 'hi'
20 'c'
21 'what "yach"'
22 s'c'
23 "c"
24 r"[a-z|A-Z]+"</code></pre>
25
26 <h2>Functions</h2>
27 <pre><code>def add(a int, b int) => a + b</code></pre>
28
29 <h2>Language Extensions</h2>
30 <pre><code>dcalc = mylisp||(+ 1 2 (* 2 3))|| // == 9
31
32 myFortran || program hello
33 print *, "Hello World!"
34 end program hello|| //prints "Hello World!"
35
36 lotto = myAPL || x[⍋x←6?40] || //6 unique random numbers from 1 to 40</code></pre>
37
38 <h2>Full example</h2>
39 <pre><code>//an overloaded function
40 def adder(a int, b int) => a + b
41 def adder(a int, b float) => adder(a, b as int)
42 def adder(a int) => adder(a, 10)
43
44 //a default value
45 def powerPlus(a int, raiseTo = 2, c int) => a ** raiseTo + c
46
47 //call our function with a default value
48 res1 = powerPlus(4, 10)//second argument defaults to '2'
49 res2 = powerPlus(4, 3, 10)//second argument provided
50
51 //calling a function with named parameters:
52 def powerAdder(a int, raiseATo = 2, b int, raiseBTo = 2) => a**raiseATo + b**raiseBTo
53 res3 = powerAdder(2, 4, raiseATo=3)//equivalent to: powerAdder(2, 3, 4, 2)
54
55 //varargs:
56 def sum(elms int...) int {
57 res = 0
58 for(elm in elms){
59 res += elm
60 }
61 res
62 }
63
64 //call our function with a vararg
65 thesum = sum(1, 2, 3, 4, 5)
66
67 //partially defined typedef
68 typedef NameMap&lt;X> = java.util.ArrayList&lt;java.util.HashMap&lt;String, java.util.HashSet&lt;X>>>
69
70 //using typedefs...
71 nm NameMap&lt;String>= new NameMap&lt;String>()
72
73 @Annotation
74 class MyClass(a int, b int, c String){
75 override toString() => 'MyClass({a}, {b}, "{c}")'
76 }
77
78 mc1 = MyClass(12, 14, "hi there")
79 mc2 = mc1@ //copy mc1
80
81 assert mc1 == mc2//same values!
82 assert mc1 &&lt;> mc2//different objects!
83
84 mc3 = mc1@(a = 100)//copy mc1 but overwrite value of a
85 assert 'MyClass(100, 14, "hi there")' == mc3.toString()
86
87 mc4 = mc1@(&lt;a, b>)//copy mc1 but exclude a and b
88 assert 'MyClass(0, 0, "hi there")' == mc3.toString()
89 </code></pre>