├── LICENSE
├── README.md
├── Sample Code
├── ANTLR
├── ActionScript
├── Ada
├── Assembly
├── AutoHotkey
├── Batch
├── Boo
├── C
├── C#
├── C++
├── CSS
├── Ceylon
├── ChucK
├── Clojure
├── CoffeeScript
├── Cool
├── D
├── Dart
├── Delphi
├── Eiffel
├── Elixir
├── Erlang
├── F#
├── Falcon
├── Fantom
├── Fortran 90
├── Go
├── Groovy
├── Gui4Cli
├── HTML
├── Haskell
├── Haxe
├── ILYC
├── INI
├── Icon
├── Io
├── JSON
├── Java
├── JavaScript
├── Julia
├── Just BASIC
├── KiXtart
├── Kotlin
├── Lean
├── Lisp
├── Lua
├── Nemerle
├── Nim
├── OCaml
├── Objective-C
├── PHP
├── ParaSail
├── Pascal
├── Pike
├── PowerShell
├── Prolog
├── PureScript
├── Python
├── R
├── Registry
├── Resource
├── Rexx
├── Rust
├── SQF
├── SQL
├── Scala
├── Scheme
├── Solidity
├── Spike
├── Swift
├── TCL
├── Thrift
├── TypeScript
├── VB.NET
├── VBScript
├── VHDL
├── Vala
├── Verilog
├── Visual Studio Solution
├── Volt
├── X10
├── XC
├── XML
└── Xtend
└── Syntax
├── ANTLR.xshd
├── ActionScript.xshd
├── Ada.xshd
├── Assembly.xshd
├── AutoHotkey.xshd
├── Batch.xshd
├── Boo.xshd
├── C#.xshd
├── C++.xshd
├── C.xshd
├── CSS.xshd
├── Ceylon.xshd
├── ChucK.xshd
├── Clojure.xshd
├── Cocoa.xshd
├── CoffeeScript.xshd
├── Cool.xshd
├── D.xshd
├── Dart.xshd
├── Delphi.xshd
├── Eiffel.xshd
├── Elixir.xshd
├── Erlang.xshd
├── F#.xshd
├── Falcon.xshd
├── Fantom.xshd
├── Fortran95.xshd
├── Go.xshd
├── Goovy.xshd
├── Gui4Cli.xshd
├── HTML.xshd
├── Haskell.xshd
├── Haxe.xshd
├── ILYC.xshd
├── INI.xshd
├── Icon.xshd
├── Io.xshd
├── JSON.xshd
├── Java.xshd
├── JavaScript.xshd
├── Julia.xshd
├── Just BASIC.xshd
├── KiXtart.xshd
├── Kotlin.xshd
├── Lean.xshd
├── Lisp.xshd
├── Lua.xshd
├── Nemerle.xshd
├── Nim.xshd
├── OCaml.xshd
├── Objective-C.xshd
├── PHP.xshd
├── ParaSail.xshd
├── Pascal.xshd
├── Pike.xshd
├── PowerShell.xshd
├── Prolog.xshd
├── PureScript.xshd
├── Python.xshd
├── R.xshd
├── Registry.xshd
├── Resource.xshd
├── Rexx.xshd
├── Rust.xshd
├── SQF.xshd
├── SQL.xshd
├── Scala.xshd
├── Scheme.xshd
├── Solidity.xshd
├── Spike.xshd
├── Swift.xshd
├── TCL.xshd
├── Thrift.xshd
├── TypeScript.xshd
├── VBNET.xshd
├── VBScript.xshd
├── VHDL.xshd
├── VS Solution.xshd
├── Vala.xshd
├── Verilog.xshd
├── Volt.xshd
├── X10.xshd
├── XC.xshd
├── XML.xshd
└── Xtend.xshd
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Ezra Altahan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Sample Code/ANTLR:
--------------------------------------------------------------------------------
1 | /* ANTLR Glue
2 | ** http://javadude.com/articles/antlrtut/
3 | */
4 |
5 | class XLRecognizer extends Parser;
6 |
7 | options {
8 | defaultErrorHandler = true; // Don't generate parser error handlers
9 | }
10 |
11 | // Define some methods and variables to use in the generated parser.
12 | {
13 | // Define a main
14 | public static void main(String[] args) {
15 |
16 | // Use a try/catch block for parser exceptions
17 | try {
18 | // if we have at least one command-line argument
19 | if (args.length > 0 ) {
20 | System.err.println("Parsing...");
21 |
22 | // for each directory/file specified on the command line
23 | for(int i=0; i< args.length;i++)
24 | doFile(new File(args[i])); // parse it
25 | }
26 | else
27 | System.err.println("Usage: java XLRecogizer ");
28 | }
29 |
30 | catch(Exception e) {
31 | System.err.println("exception: "+e);
32 | e.printStackTrace(System.err); // so we can get stack trace
33 | }
34 | }
35 |
36 | // This method decides what action to take based on the type of
37 | // file we are looking at
38 | public static void doFile(File f) throws Exception {
39 |
40 | // If this is a directory, walk each file/dir in that directory
41 | if (f.isDirectory()) {
42 | String files[] = f.list();
43 |
44 | for(int i=0; i < files.length; i++)
45 | doFile(new File(f, files[i]));
46 | }
47 |
48 | // otherwise, if this is a java file, parse it!
49 | else if ((f.getName().length()>5) &&
50 | f.getName().substring(f.getName().length()-3).equals(".xl")) {
51 |
52 | System.err.println("-------------------------------------------");
53 | System.err.println(f.getAbsolutePath());
54 | parseFile(new FileInputStream(f));
55 | }
56 | }
57 |
58 | // Here's where we do the real work...
59 | public static void parseFile(InputStream s) throws Exception {
60 |
61 | try {
62 | // Create a scanner that reads from the input stream passed to us
63 | XLLexer lexer = new XLLexer(s);
64 | // Create a parser that reads from the scanner
65 | XLRecognizer parser = new XLRecognizer(lexer);
66 | // start parsing at the compilationUnit rule
67 | parser.program();
68 | }
69 |
70 | catch (Exception e) {
71 | System.err.println("parser exception: "+e);
72 | e.printStackTrace(); // so we can get stack trace
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Sample Code/ActionScript:
--------------------------------------------------------------------------------
1 | /* 3D rotation
2 | ** Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
3 | ** http://adobe.com/devnet/actionscript/samples/drawing_5.html
4 | */
5 |
6 | package code
7 | {
8 | /*****************************************
9 | * DrawingSample5 :
10 | * Demonstrates animation in 3D space.
11 | * -------------------
12 | * See 5_3Drotation.fla
13 | ****************************************/
14 |
15 | import flash.events.*;
16 | import flash.display.*;
17 |
18 | public class Drawing5 extends MovieClip
19 | {
20 | //*************************
21 | // Properties:
22 |
23 | public var rX:Number = 0; // X (0-30)
24 | public var rY:Number = 0; // Y (0-30)
25 | public var rZ:Number = 0; // Z (0-30)
26 | public var speed:Number = 0;// S (0-1)
27 |
28 | //*************************
29 | // Constructor:
30 |
31 | public function Drawing5()
32 | {
33 | // Reset when clicked
34 | reset_btn.addEventListener(MouseEvent.CLICK, clickHandler);
35 |
36 | // Animate image at the frame rate
37 | addEventListener(Event.ENTER_FRAME, enterFramehandler);
38 | }
39 |
40 | //*************************
41 | // Event Handling:
42 |
43 | protected function clickHandler(event:MouseEvent):void
44 | {
45 | // Reset controls
46 | sliderX_sl.value = 0;
47 | sliderY_sl.value = 0;
48 | sliderZ_sl.value = 0;
49 | sliderSpeed_sl.value = .3;
50 |
51 | // Reset image
52 | logo_mc.rotationX = 0;
53 | logo_mc.rotationY = 0;
54 | logo_mc.rotationZ = 0;
55 | }
56 |
57 | protected function enterFramehandler(event:Event):void
58 | {
59 | logo_mc.rotationX += sliderX_sl.value * sliderSpeed_sl.value;
60 | logo_mc.rotationY += sliderY_sl.value * sliderSpeed_sl.value;
61 | logo_mc.rotationZ += sliderZ_sl.value * sliderSpeed_sl.value;
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Sample Code/Ada:
--------------------------------------------------------------------------------
1 | -- Linked Stack Client
2 | -- A simple client of the Int_Stack package.
3 | -- http://sandbox.mc.edu/~bennet/ada/examples/l_stack_user_adb.html
4 |
5 | with Gnat.Io; use Gnat.Io;
6 | with L_Stack; use L_Stack;
7 |
8 | procedure L_Stack_User is
9 | -- Here is a stack. We can use the name of the private type,
10 | S, T: Int_Stack;
11 |
12 | -- Here's an exciting integer.
13 | Exciting: Integer;
14 | begin
15 | -- Read in some integers, and push 'em
16 | loop
17 | Put("> ");
18 | Get(Exciting);
19 | exit when Exciting = -1;
20 | Push(S, Exciting);
21 | Push(T, Exciting);
22 | end loop;
23 |
24 | if S = T then
25 | Put_Line("Gee, they're equal.");
26 | end if;
27 |
28 | Push(T, 34);
29 | if S = T then
30 | Put_Line("Ha ha! Found a bug!");
31 | end if;
32 |
33 | -- Pop 'em and print 'em
34 | while not Empty(S) loop
35 | Pop(S, Exciting);
36 | Put(Exciting);
37 | exit when Empty(S);
38 | Put(" ");
39 | end loop;
40 | New_Line;
41 |
42 | if S /= T then
43 | Put_Line("Gosh, they're not equal anymore.");
44 | end if;
45 | end L_Stack_User;
46 |
--------------------------------------------------------------------------------
/Sample Code/Assembly:
--------------------------------------------------------------------------------
1 | ;-------------------------------------------------------------------------------
2 | ; MSP430 Assembler Code Template for use with TI Code Composer Studio
3 | ; This program demonstrates the use of the stack.
4 | ; Rob Frohne November, 2015
5 | ; This program is to play around and see how the stack is manipulated. Try it!
6 | ;-------------------------------------------------------------------------------
7 | .cdecls C,LIST,"msp430.h" ; Include device header file
8 |
9 | ;-------------------------------------------------------------------------------
10 | .def RESET ; Export program entry-point to
11 | ; make it known to linker.
12 | ;-------------------------------------------------------------------------------
13 | .text ; Assemble into program memory.
14 | .retain ; Override ELF conditional linking
15 | ; and retain current section.
16 | .retainrefs ; And retain any sections that have
17 | ; references to current section.
18 |
19 | ;-------------------------------------------------------------------------------
20 | RESET mov #__STACK_END,SP ; Initialize stackpointer
21 | StopWDT mov #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
22 |
23 |
24 | ;-------------------------------------------------------------------------------
25 | ; Main loop here
26 | ;-------------------------------------------------------------------------------
27 | mov #0xffff,r6
28 | mov #0x000f,r7
29 | loop1 push r6
30 | dec r7
31 | jnz loop1
32 |
33 | mov #0x000f,r7
34 | loop2 pop r6
35 | dec r7
36 | jnz loop2
37 |
38 | mov #0x0004,r4
39 | mov #0x0005,r5
40 | mov #0xff06,r6
41 | call #subroutine1
42 | mov r4,&0x43f2
43 | jmp $
44 |
45 | subroutine1 push r4
46 | push r5
47 | push r6
48 | mov #0x4444,r4
49 | mov #0x5555,r5
50 | mov #0x6666,r6
51 | pop r6
52 | pop r5
53 | pop r4
54 | ret
55 |
56 |
57 |
58 | ;-------------------------------------------------------------------------------
59 | ; Stack Pointer definition
60 | ;-------------------------------------------------------------------------------
61 | .global __STACK_END
62 | .sect .stack
63 |
64 | ;-------------------------------------------------------------------------------
65 | ; Interrupt Vectors
66 | ;-------------------------------------------------------------------------------
67 | .sect ".reset" ; MSP430 RESET Vector
68 | .short RESET
69 |
--------------------------------------------------------------------------------
/Sample Code/AutoHotkey:
--------------------------------------------------------------------------------
1 | ; Context Sensitive Help
2 | ; https://autohotkey.com/docs/scripts/ContextSensitiveHelp.htm
3 | ;
4 | ; The hotkey below uses the clipboard to provide compatibility with the maximum
5 | ; number of editors (since ControlGet doesn't work with most advanced editors).
6 | ; It restores the original clipboard contents afterward, but as plain text,
7 | ; which seems better than nothing.
8 |
9 | $^2::
10 | SetWinDelay 10
11 | SetKeyDelay 0
12 | AutoTrim, On
13 |
14 | if A_OSType = WIN32_WINDOWS ; Windows 9x
15 | Sleep, 500 ; Give time for the user to release the key.
16 |
17 | C_ClipboardPrev = %clipboard%
18 | clipboard =
19 | ; Use the highlighted word if there is one (since sometimes the user might
20 | ; intentionally highlight something that isn't a command):
21 | Send, ^c
22 | ClipWait, 0.1
23 | if ErrorLevel <> 0
24 | {
25 | ; Get the entire line because editors treat cursor navigation keys differently:
26 | Send, {home}+{end}^c
27 | ClipWait, 0.2
28 | if ErrorLevel <> 0 ; Rare, so no error is reported.
29 | {
30 | clipboard = %C_ClipboardPrev%
31 | return
32 | }
33 | }
34 | C_Cmd = %clipboard% ; This will trim leading and trailing tabs & spaces.
35 | clipboard = %C_ClipboardPrev% ; Restore the original clipboard for the user.
36 | Loop, parse, C_Cmd, %A_Space%`, ; The first space or comma is the end of the command.
37 | {
38 | C_Cmd = %A_LoopField%
39 | break ; i.e. we only need one interation.
40 | }
41 | IfWinNotExist, AutoHotkey Help
42 | {
43 | ; Determine AutoHotkey's location:
44 | RegRead, ahk_dir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
45 | if ErrorLevel ; Not found, so look for it in some other common locations.
46 | {
47 | if A_AhkPath
48 | SplitPath, A_AhkPath,, ahk_dir
49 | else IfExist ..\..\AutoHotkey.chm
50 | ahk_dir = ..\..
51 | else IfExist %A_ProgramFiles%\AutoHotkey\AutoHotkey.chm
52 | ahk_dir = %A_ProgramFiles%\AutoHotkey
53 | else
54 | {
55 | MsgBox Could not find the AutoHotkey folder.
56 | return
57 | }
58 | }
59 | Run %ahk_dir%\AutoHotkey.chm
60 | WinWait AutoHotkey Help
61 | }
62 | ; The above has set the "last found" window which we use below:
63 | WinActivate
64 | WinWaitActive
65 | StringReplace, C_Cmd, C_Cmd, #, {#}
66 | send, !n{home}+{end}%C_Cmd%{enter}
67 | return
68 |
--------------------------------------------------------------------------------
/Sample Code/Batch:
--------------------------------------------------------------------------------
1 | REM Input Validation
2 | REM 0x141
3 | REM Http://github.com/ei
4 |
5 | @echo off
6 | title Entry Validation
7 | color B
8 | mode con LINES=10 COLS=48
9 |
10 | :LoginAttempt
11 | echo -----------------------------------------------
12 | echo Project: MadFrog - Version 1.0.0
13 | echo -----------------------------------------------
14 | echo.
15 | echo CPanel Login:
16 | echo Enter a correct password to access the CPanel.
17 | echo.
18 | set/p password1=-^>
19 | if "%password1%" EQU "Hipster" goto :LoginNotification
20 | if not "%password1%" EQU "Hipster" goto :IncorrectPassword
21 |
22 | :IncorrectPassword
23 | cls
24 | mode con LINES=10 COLS=48
25 | color C
26 | echo -----------------------------------------------
27 | echo Project: MadFrog - Version 1.0.0
28 | echo -----------------------------------------------
29 | echo.
30 | echo CPanel Login:
31 | echo Incorrect password. Please try again.
32 | echo.
33 | echo Press any key to return...
34 | pause >nul
35 | cls
36 | color B
37 | goto :LoginAttempt
38 |
39 | :LoginNotification
40 | cls
41 | mode con LINES=10 COLS=48
42 | color A
43 | echo -----------------------------------------------
44 | echo Project: MadFrog - Version 1.0.0
45 | echo -----------------------------------------------
46 | echo.
47 | echo CPanel Login:
48 | echo You have successfully logged in!
49 | echo.
50 | echo Press any key to continue to the CPanel...
51 | pause >nul
52 | cls
53 |
54 | :CPanel
55 | cls
56 | mode con LINES=10 COLS=48
57 | color B
58 | echo -----------------------------------------------
59 | echo Project: MadFrog - Version 1.0.0
60 | echo -----------------------------------------------
61 | echo.
62 | echo Select a number, then press ENTER.
63 | echo.
64 | echo 1) Exit
65 | echo.
66 |
67 | set/p input1=-^>
68 | if "%input1%" EQU "1" goto :exit
69 | if not "%input1%" EQU "1" goto :Incorrect#choice
70 |
71 | :Incorrect#choice
72 | cls
73 | mode con LINES=10 COLS=48
74 | color C
75 | echo -----------------------------------------------
76 | echo Project: MadFrog - Version 1.0.0
77 | echo -----------------------------------------------
78 | echo.
79 | echo You have entered an invalid value.
80 | echo.
81 | echo Press any key to return...
82 | pause >nul
83 | cls
84 | color B
85 | goto :CPanel
86 |
87 | :exit
88 |
--------------------------------------------------------------------------------
/Sample Code/Boo:
--------------------------------------------------------------------------------
1 | // Simple test class
2 |
3 | namespace Winterdom.Boo.Test
4 | import System
5 |
6 | class BooTest:
7 | event Done as DoneHandler
8 | callable DoneHandler(sender as object, e as EventArgs)
9 | def Run(args as (string)):
10 | assert args != null
11 | try:
12 | for s in args:
13 | # print if matches pattern
14 | if s =~ /u.+/:
15 | print "This is a string: ${s} of length ${s.length}"
16 | except e:
17 | print "An exception occurred: ${e}"
18 | if Done != null:
19 | Done(self, EventArgs.Empty)
20 | return 0
21 |
22 | static def OnDone(sender as object, e as EventArgs):
23 | print "we're done here!"
24 |
25 | // start of the program
26 | obj = BooTest()
27 | obj.Done += BooTest.OnDone
28 | obj.Run(("uno", "dos", "tres"))
29 |
--------------------------------------------------------------------------------
/Sample Code/C:
--------------------------------------------------------------------------------
1 | /* Prime Numbers Between Two Integers
2 | ** https://www.programiz.com/c-programming/examples/prime-interval-function
3 | */
4 |
5 | #include
6 |
7 | int checkPrimeNumber(int n);
8 | int main()
9 | {
10 | int n1, n2, i, flag;
11 |
12 | printf("Enter two positive integers: ");
13 | scanf("%d %d", &n1, &n2);
14 | printf("Prime numbers between %d and %d are: ", n1, n2);
15 |
16 | for(i=n1+1; i
7 | #include
8 |
9 | using namespace std;
10 |
11 | int** comb(int** a , int row , int col)
12 | {
13 | int mid = col/2;
14 | //clear matrix
15 | for( int i = 0 ; i < row ; i++)
16 | for( int j = 0 ; j < col ; j++)
17 | a[i][j] = 0;
18 | a[0][mid] = 1; //put 1 in the middle of first row
19 | //build up Pascal's Triangle matrix
20 | for( int i = 1 ; i < row ; i++)
21 | {
22 | for( int j = 1 ; j < col - 1 ; j++)
23 | a[i][j] = a[i-1][j-1] + a[i-1][j+1];
24 | }
25 | return a;
26 | }
27 | void disp(int** ptr, int row, int col)
28 | {
29 | cout << endl << endl;
30 | for ( int i = 0 ; i < row ; i++)
31 | {
32 | for ( int j = 0 ; j < col ; j++)
33 | {
34 | if( ptr[i][j] == 0)
35 | cout << " ";
36 | else
37 | cout << setw(4) << right << ptr[i][j];
38 | }
39 | cout << endl;
40 | }
41 | cout << endl << endl;
42 | }
43 | int main()
44 | {
45 | int **ptr, m, n;
46 | cout << "\nEnter number of rows to draw Pascal's Triangle: ";
47 | cin >> m;
48 | n = 2 * m + 1; //column = 2 * row + 1
49 |
50 | ptr = new int*[m];
51 | for( int i = 0 ; i < m ; i++)
52 | ptr[i] = new int[n];
53 |
54 | ptr = comb(ptr, m, n);//calling function for array creation
55 |
56 | disp(ptr, m, n);//calling function for array displaying.
57 |
58 | return 0;
59 | }
60 | /*Programs output
61 | ******************
62 | Enter number of rows to draw Pascal's Triangle: 9
63 |
64 |
65 | 1
66 | 1 1
67 | 1 2 1
68 | 1 3 3 1
69 | 1 4 6 4 1
70 | 1 5 10 10 5 1
71 | 1 6 15 20 15 6 1
72 | 1 7 21 35 35 21 7 1
73 | 1 8 28 56 70 56 28 8 1
74 |
75 | Process returned 0 (0x0) execution time : 2.996 s
76 | Press any key to continue.
77 | */
78 |
--------------------------------------------------------------------------------
/Sample Code/CSS:
--------------------------------------------------------------------------------
1 | @import url(style.css);
2 |
3 | input[type=radio] + label:before {
4 | content: "";
5 | display: inline-block;
6 | width: 15px;
7 | height: 15px;
8 | vertical-align: middle;
9 | margin-right: 8px;
10 | background-color: #aaa;
11 | box-shadow: inset 0px 2px 2px rgba(0, 0, 0, .3);
12 | border-radius: 8px;
13 | }
14 |
15 | /* Apply this style only for printing */
16 | @media print {
17 | body {
18 | color: #000;
19 | background: #fff;
20 | }
21 | }
22 |
23 | /* Embed a custom web font */
24 | @font-face {
25 | font-family: 'DejaVu Sans';
26 | src: local('DejaVu Sans Regular'), url(/fonts/DejaVuSans.ttf);
27 | }
28 |
--------------------------------------------------------------------------------
/Sample Code/Ceylon:
--------------------------------------------------------------------------------
1 | /* Solar System Example
2 | ** http://try.ceylon-lang.org/?gist=bd41b47f325b6d32514a
3 | */
4 |
5 | import ceylon.numeric.float {
6 | pi, cos, sin
7 | }
8 |
9 | "An astronomical body in 2 dimensions."
10 | interface Body {
11 | "The position on the x axis."
12 | shared formal Float x;
13 | "The position on the y axis."
14 | shared formal Float y;
15 | "The radius of the object."
16 | shared formal Float r;
17 | "Draw the object."
18 | shared formal void draw(CanvasRenderingContext2D ctx);
19 | "Move the object in its orbit."
20 | shared formal void orbit();
21 | }
22 |
23 | "The sun."
24 | class Sun(x, y, r, String color)
25 | satisfies Body {
26 |
27 | shared actual Float x;
28 | shared actual Float y;
29 | shared actual Float r;
30 |
31 | draw = (CanvasRenderingContext2D ctx) {
32 | ctx.fillStyle = color;
33 | ctx.beginPath();
34 | ctx.arc(x, y, r, 0.0, pi * 2.0, true);
35 | ctx.closePath();
36 | ctx.fill();
37 | };
38 |
39 | orbit = noop;
40 |
41 | }
42 |
43 | "A planet or moon."
44 | class Planet(name, primary, r, Float v, String color = "#FFF",
45 | rp = 0.0, String? ringColor = null)
46 | satisfies Body {
47 |
48 | shared String name;
49 | shared Body primary;
50 | shared actual Float r;
51 |
52 | "Distance to the primary. (Radius of the orbit.)"
53 | shared Float rp;
54 |
55 | shared actual variable Float x = primary.x;
56 | shared actual variable Float y = primary.y - rp - (r + primary.r);
57 |
58 | variable Float radian = pi/2;
59 |
60 | orbit = () {
61 | radian += v / 360.0 * pi;
62 | x = primary.x - sin(radian) * (primary.r + rp);
63 | y = primary.y + cos(radian) * (primary.r + rp);
64 | };
65 |
66 | draw = (CanvasRenderingContext2D ctx) {
67 | ctx.fillStyle = color;
68 | ctx.beginPath();
69 | ctx.arc(x, y, r, 0.0, pi * 2.0, true);
70 | ctx.closePath();
71 | ctx.fill();
72 |
73 | if (exists ringColor) {
74 | ctx.strokeStyle = ringColor;
75 | ctx.lineWidth = r * 0.75;
76 | ctx.beginPath();
77 | ctx.arc(x, y, r * 1.6, 0.0, pi * 2.0, true);
78 | ctx.closePath();
79 | ctx.stroke();
80 | }
81 | };
82 | }
83 |
--------------------------------------------------------------------------------
/Sample Code/ChucK:
--------------------------------------------------------------------------------
1 | // dither.ck
2 | // demo of dithering
3 | // http://chuck.cs.princeton.edu/doc/examples/deep/dither.ck
4 | //
5 | // can use any UGen as source in play_with_dither()
6 | // qbits : number of bits to quantize to
7 | // do_dither : whether to dither
8 | //
9 | // gewang
10 |
11 | // patch
12 | Impulse imp => dac;
13 |
14 | // sine wave generator
15 | SinOsc s => blackhole;
16 | 220 => s.freq;
17 |
18 | // go
19 | play_with_dither( s, 2::second, 6, false );
20 | play_with_dither( s, 2::second, 6, true );
21 | .5::second => now;
22 |
23 | play_with_dither( s, 2::second, 5, false );
24 | play_with_dither( s, 2::second, 5, true );
25 | .5::second => now;
26 |
27 | play_with_dither( s, 2::second, 4, false );
28 | play_with_dither( s, 2::second, 4, true );
29 | .5::second => now;
30 |
31 | // dither
32 | fun void play_with_dither( UGen src, dur T, int qbits, int do_dither )
33 | {
34 | // sanity check
35 | if( qbits <= 0 || qbits > 24 )
36 | {
37 | <<< "quantization bits out of range (1-24)", "" >>>;
38 | return;
39 | }
40 |
41 | // loop
42 | float sample;
43 | int quantized;
44 | (1 << 24) => int max;
45 | while( T > 0::second )
46 | {
47 | // get the last sample
48 | src.last() => sample;
49 | // quantize it
50 | if( do_dither ) // dither
51 | ((sample + Math.random2f(0,Math.pow(2,-qbits))) * max) $ int => quantized;
52 | else // no dither
53 | (sample * max) $ int => quantized;
54 |
55 | // throw away extra resolution
56 | quantized >> (24-qbits) << (24-qbits) => quantized;
57 | // cast it back for playback
58 | (quantized $ float) / max => imp.next;
59 | // advance time
60 | 1::samp => now;
61 | // decrement
62 | 1::samp -=> T;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Sample Code/Clojure:
--------------------------------------------------------------------------------
1 | ; REPL Socket
2 | ; https://en.wikibooks.org/wiki/Clojure_Programming/Examples/REPL_Socket
3 |
4 | (import '(java.net ServerSocket Socket SocketException)
5 | '(java.io InputStreamReader OutputStreamWriter)
6 | '(clojure.lang LineNumberingPushbackReader))
7 |
8 | (defn on-thread [f]
9 | (doto (new Thread f) (.start)))
10 |
11 | (defn create-server
12 | "creates and returns a server socket on port, will pass the client
13 | socket to accept-socket on connection"
14 | [accept-socket port]
15 | (let [ss (new ServerSocket port)]
16 | (on-thread #(when-not (. ss (isClosed))
17 | (try (accept-socket (. ss (accept)))
18 | (catch SocketException e))
19 | (recur)))
20 | ss))
21 |
22 | (defn repl
23 | "runs a repl on ins and outs until eof"
24 | [ins outs]
25 | (binding [*ns* (create-ns 'user)
26 | *warn-on-reflection* false
27 | *out* (new OutputStreamWriter outs)]
28 | (let [eof (new Object)
29 | r (new LineNumberingPushbackReader (new InputStreamReader ins))]
30 | (loop [e (read r false eof)]
31 | (when-not (= e eof)
32 | (prn (eval e))
33 | (flush)
34 | (recur (read r false eof)))))))
35 |
36 | (defn socket-repl
37 | "starts a repl thread on the iostreams of supplied socket"
38 | [s] (on-thread #(repl (. s (getInputStream)) (. s (getOutputStream)))))
39 |
40 | (def server (create-server socket-repl 13579))
41 | (def client (new Socket "localhost" 13579))
42 |
43 | (def rdr (new LineNumberingPushbackReader
44 | (new InputStreamReader (. client (getInputStream)))))
45 | (def wtr (new OutputStreamWriter (. client (getOutputStream))))
46 |
47 | (binding [*out* wtr]
48 | (prn '(+ 1 2 3))
49 | (flush)
50 | (read rdr))
51 |
52 | (. server (close))
53 | (. client (close))
54 |
--------------------------------------------------------------------------------
/Sample Code/CoffeeScript:
--------------------------------------------------------------------------------
1 | # CoffeeScript Class Example
2 | # http://coffeescript.org/
3 |
4 | class Animal
5 | constructor: (@name) ->
6 |
7 | move: (meters) ->
8 | alert @name + " moved #{meters}m."
9 |
10 | class Snake extends Animal
11 | move: ->
12 | alert "Slithering..."
13 | super 5
14 |
15 | class Horse extends Animal
16 | move: ->
17 | alert "Galloping..."
18 | super 45
19 |
20 | sam = new Snake "Sammy the Python"
21 | tom = new Horse "Tommy the Palomino"
22 |
23 | sam.move()
24 | tom.move()
25 |
--------------------------------------------------------------------------------
/Sample Code/Cool:
--------------------------------------------------------------------------------
1 | (* Refer to Alex Aiken, "The Cool Reference Manual":
2 | http://theory.stanford.edu/~aiken/software/cool/cool-manual.pdf
3 | for language specification.
4 | *)
5 |
6 | -- Exhibit various language constructs
7 | class Sample {
8 | testCondition(x: Int): Bool {
9 | if x = 0
10 | then false
11 | else
12 | if x < (1 + 2) * 3
13 | then true
14 | else false
15 | fi
16 | fi
17 | };
18 |
19 | testLoop(y: Int): Bool {
20 | while y > 0 loop
21 | {
22 | if not condition(y)
23 | then y <- y / 2
24 | else y <- y - 1;
25 | }
26 | pool
27 | };
28 |
29 | testAssign(z: Int): Bool {
30 | i : Int;
31 | i <- ~z;
32 | };
33 |
34 | testCase(var: Sample): SELF_TYPE {
35 | io : IO <- new IO;
36 | case var of
37 | a : A => io.out_string("Class type is A\n");
38 | b : B => io.out_string("Class type is B\n");
39 | s : Sample => io.out_string("Class type is Sample\n");
40 | o : Object => io.out_string("Class type is object\n");
41 | esac
42 | };
43 |
44 | testLet(i: Int): Int {
45 | let (a: Int in
46 | let(b: Int <- 3, c: Int <- 4 in
47 | {
48 | a <- 2;
49 | a * b * 2 / c;
50 | }
51 | )
52 | )
53 | };
54 | };
55 |
56 | -- Used to test subclasses
57 | class A inherits Sample {};
58 | class B inherits A {};
59 |
60 | class C {
61 | main() : Int {
62 | (new Sample).testLet(1)
63 | };
64 | };
65 |
66 | -- "Hello, world" example
67 | class Main inherits IO {
68 | main(): SELF_TYPE {
69 | out_string("Hello, World.\n")
70 | };
71 | };
72 |
--------------------------------------------------------------------------------
/Sample Code/D:
--------------------------------------------------------------------------------
1 | // Simple BubbleSort class implementation that sorts a static array
2 | // http://www.dsource.org/projects/tutorials/wiki/BubbleSort
3 |
4 | import std.stdio;
5 |
6 | /**
7 | * BubbleSort implementation in D
8 | **/
9 | class BubbleSort {
10 |
11 | int[] tobsorted;
12 | public:
13 |
14 | /**
15 | * Constructor
16 | **/
17 | this(int[] array) {
18 | tobsorted = array;
19 | }
20 |
21 | int[] sort() {
22 |
23 | // Iterate through every element in array
24 | foreach( inout int x; tobsorted) {
25 |
26 | // 2nd iteration through array, comparing elements with each other
27 | foreach(inout int y; tobsorted) {
28 |
29 | // comare elements to each other
30 | // If element x < y
31 | // swap elements
32 | if(x < y) {
33 | debug writefln("swap(%d,%d)", x,y);
34 | typeof(x) temp = x;
35 | x = y;
36 | y = temp;
37 | }
38 | }
39 |
40 | // Output current array to console
41 | foreach(int i; tobsorted) {
42 | writef("%02d ",i);
43 | }
44 |
45 | // append newline
46 | writefln();
47 | }
48 |
49 | // return sorted array
50 | return tobsorted;
51 | }
52 | }
53 |
54 | /** Explains itself
55 | * Initialize int-array with 15 elements
56 | * Then calls BubbleSort and outputs the sorted array
57 | **/
58 | int main(char[][] args) {
59 |
60 | // initialize array
61 |
62 | static int[] array = [15,4,3,14,5,2,1,8,7,19,15,13,9,12,6,11];
63 |
64 | writefln("BubbleSort in D");
65 | writefln("---------------");
66 | writef("Sorting following numbers:\t");
67 | foreach(int i; array) {
68 | writef("%02d ",i);
69 | }
70 | writefln("\nStarting now...");
71 | writefln();
72 |
73 | BubbleSort s = new BubbleSort(array);
74 | array = s.sort();
75 |
76 | writefln();
77 | writefln("I finished!");
78 | writef("Here's your sorted array:\t");
79 | foreach(int i; array) {
80 | writef("%02d ",i);
81 | }
82 |
83 | return 0;
84 | }
85 |
--------------------------------------------------------------------------------
/Sample Code/Dart:
--------------------------------------------------------------------------------
1 | // A simple class
2 | // https://en.wikipedia.org/wiki/Dart_(programming_language)
3 |
4 | // Import the math library to get access to the sqrt function.
5 | import 'dart:math' as math;
6 |
7 | // Create a class for Point.
8 | class Point {
9 |
10 | // Final variables cannot be changed once they are assigned.
11 | // Create two instance variables.
12 | final num x, y;
13 |
14 | // A constructor, with syntactic sugar for setting instance variables.
15 | Point(this.x, this.y);
16 |
17 | // A named constructor with an initializer list.
18 | Point.origin()
19 | : x = 0,
20 | y = 0;
21 |
22 | // A method.
23 | num distanceTo(Point other) {
24 | var dx = x - other.x;
25 | var dy = y - other.y;
26 | return math.sqrt(dx * dx + dy * dy);
27 | }
28 |
29 | // Example of Operator Overloading
30 | Point operator +(Point other) => new Point(x + other.x, y + other.y);
31 | }
32 |
33 | // All Dart programs start with main().
34 | void main() {
35 | // Instantiate point objects.
36 | var p1 = new Point(10, 10);
37 | var p2 = new Point.origin();
38 | var distance = p1.distanceTo(p2);
39 | print(distance);
40 | }
41 |
--------------------------------------------------------------------------------
/Sample Code/Delphi:
--------------------------------------------------------------------------------
1 | (*
2 | Determine if two icons are equal
3 | http://www.delphitricks.com/source-code/graphic/determine_if_two_icons_are_equal.html
4 | *)
5 |
6 | function IconsAreEqual(const Icon1, Icon2: TIcon): Boolean;
7 | var
8 | ms1: TMemoryStream;
9 | ms2: TMemoryStream;
10 | begin
11 | Result := False;
12 | ms1 := TMemoryStream.Create;
13 | try
14 | Icon1.SaveToStream(ms1);
15 | ms2 := TMemoryStream.Create;
16 | try
17 | Icon2.SaveToStream(ms2);
18 | if ms1.Size = ms2.Size then
19 | Result := CompareMem(ms1.Memory, ms2.Memory, ms1.Size)
20 | finally
21 | ms2.Free
22 | end
23 | finally
24 | ms1.Free
25 | end
26 | end;
27 |
28 |
29 | procedure TForm1.Button1Click(Sender: TObject);
30 | var
31 | icon1: TIcon;
32 | icon2: TIcon;
33 | begin
34 | icon1 := TIcon.Create;
35 | icon2 := TIcon.Create;
36 | try
37 | icon1.LoadFromFile('c:\Icon1.ico');
38 | icon2.LoadFromFile('c:\Icon2.ico');
39 | if IconsAreEqual(icon1, icon2) then
40 | ShowMessage('Icon 1 and Icon 2 match')
41 | else
42 | ShowMessage('Icon 1 and Icon 2 don''t match');
43 | finally
44 | icon1.Free;
45 | icon2.Free;
46 | end;
47 | end;
48 |
--------------------------------------------------------------------------------
/Sample Code/Eiffel:
--------------------------------------------------------------------------------
1 | -- Class example
2 | -- http://www.maths.tcd.ie/~odunlain/eiffel/eiffel_course/eforb.htm
3 |
4 | class
5 | ENTRY
6 | -- One entrant's time in a race
7 |
8 | feature
9 | entrant: STRING
10 | -- Entrant, identified by sailnumber
11 |
12 | elapsed_seconds: INTEGER
13 | -- Actual elapsed time, not adjusted
14 |
15 | elapsed_minutes: REAL is
16 | -- Actual elapsed time, not adjusted
17 | -- in minutes and decimal minutes
18 | do
19 | Result := elapsed_seconds / 60
20 | end -- elapsed_minutes
21 |
22 | status: INTEGER
23 | -- Status of entrant in this race
24 |
25 | dnc: INTEGER is 0
26 | -- Status value, 'Did not compete'
27 |
28 | ok, rtd, dsq: INTEGER is unique
29 | -- Status values:
30 | -- Finished, Retired, Disqualified
31 |
32 | finish (in_time: INTEGER) is
33 | -- Entrant finished. Note elapsed time, in seconds
34 | do
35 | elapsed_seconds := in_time
36 | status := ok
37 | end -- finish
38 |
39 | retire is
40 | -- Entrant retired from race
41 | do
42 | status := rtd
43 | end -- retire
44 |
45 | disqualify is
46 | -- Do not score this entry
47 | do
48 | status := dsq
49 | end -- disqualify
50 |
51 | started: BOOLEAN is
52 | -- Did the entrant start the race?
53 | do
54 | Result := status = ok or status = rtd
55 | end -- started
56 |
57 | finished: BOOLEAN is
58 | -- Did the entrant finish the race?
59 | do
60 | Result := status = ok
61 | end -- finished
62 |
63 | retired: BOOLEAN is
64 | -- Did the entrant retire?
65 | do
66 | Result := status = rtd
67 | end -- retired
68 |
69 | disqualified: BOOLEAN is
70 | -- Was the entrant disqualified?
71 | do
72 | Result := status = dsq
73 | end -- disqualified
74 |
75 | identify (sailnumber: STRING) is
76 | -- Record or change the entrant
77 | do
78 | entrant := sailnumber
79 | end -- identify
80 |
81 | identity: STRING is
82 | -- Readable form of entrant, even if none
83 | do
84 | Result := entrant
85 | if entrant = Void then
86 | Result := "(Unidentified)"
87 | end
88 | end -- identity
89 |
90 | end -- class ENTRY
91 |
--------------------------------------------------------------------------------
/Sample Code/Elixir:
--------------------------------------------------------------------------------
1 | # Phoenix Endpoint
2 | # https://elixir-examples.github.io/single-page
3 |
4 | defmodule HelloWorld.Endpoint do
5 | use Phoenix.Endpoint, otp_app: :hello_world
6 |
7 | # Serve at "/" the static files from "priv/static" directory.
8 | #
9 | # You should set gzip to true if you are running phoenix.digest
10 | # when deploying your static files in production.
11 | plug Plug.Static,
12 | at: "/", from: :hello_world, gzip: false,
13 | only: ~w(css images js favicon.ico robots.txt)
14 |
15 | # Code reloading can be explicitly enabled under the
16 | # :code_reloader configuration of your endpoint.
17 | if code_reloading? do
18 | plug Phoenix.LiveReloader
19 | plug Phoenix.CodeReloader
20 | end
21 |
22 | plug Plug.Logger
23 |
24 | plug Plug.Parsers,
25 | parsers: [:urlencoded, :multipart, :json],
26 | pass: ["*/*"],
27 | json_decoder: Poison
28 |
29 | plug Plug.MethodOverride
30 | plug Plug.Head
31 |
32 | plug Plug.Session,
33 | store: :cookie,
34 | key: "_hello_world_key",
35 | signing_salt: "0yg9mHDO"
36 |
37 | plug :router, HelloWorld.Router
38 | end
39 |
--------------------------------------------------------------------------------
/Sample Code/Erlang:
--------------------------------------------------------------------------------
1 | %% Code from
2 | %% Erlang Programming
3 | %% Francecso Cesarini and Simon Thompson
4 | %% O'Reilly, 2008
5 | %% http://oreilly.com/catalog/9780596518189/
6 | %% http://www.erlangprogramming.org/
7 | %% (c) Francesco Cesarini and Simon Thompson
8 |
9 | -module(serial).
10 |
11 | -export([treeToList/1,
12 | tree0/0,tree1/0,
13 | listToTree/1]).
14 |
15 | -include_lib("eunit/include/eunit.hrl").
16 |
17 | treeToList({leaf,N}) ->
18 | [2,N];
19 |
20 | treeToList({node,T1,T2}) ->
21 | TTL1 = treeToList(T1),
22 | [Size1|_] = TTL1,
23 | TTL2 = treeToList(T2),
24 | [Size2|_] = TTL2,
25 | [Size1+Size2+1|TTL1++TTL2].
26 |
27 | listToTree([2,N]) ->
28 | {leaf,N};
29 |
30 | listToTree([_|Code]) ->
31 | case Code of
32 | [M|_] ->
33 | {Code1,Code2} = lists:split(M,Code),
34 | {node,
35 | listToTree(Code1),
36 | listToTree(Code2)
37 | }
38 | end.
39 |
40 | tree0() ->
41 | {leaf, ant}.
42 |
43 | tree1() ->
44 | {node,
45 | {node,
46 | {leaf,cat},
47 | {node,
48 | {leaf,dog},
49 | {leaf,emu}
50 | }
51 | },
52 | {leaf,fish}
53 | }.
54 |
--------------------------------------------------------------------------------
/Sample Code/F#:
--------------------------------------------------------------------------------
1 | open System
2 | open System.Text
3 |
4 | // A simple for...to loop.
5 | let function1() =
6 | for i = 1 to 10 do
7 | printf "%d " i
8 | printfn ""
9 |
10 | // A for...to loop that counts in reverse.
11 | let function2() =
12 | for i = 10 downto 1 do
13 | printf "%d " i
14 | printfn ""
15 |
16 | function1()
17 | function2()
18 |
19 | // A for...to loop that uses functions as the start and finish expressions.
20 | let beginning x y = x - 2*y
21 | let ending x y = x + 2*y
22 |
23 | let function3 x y =
24 | for i = (beginning x y) to (ending x y) do
25 | printf "%d " i
26 | printfn ""
27 |
28 | function3 10 4
29 |
--------------------------------------------------------------------------------
/Sample Code/Falcon:
--------------------------------------------------------------------------------
1 | // Table pages
2 | object AccTable from Table( [ "name" , "rate_act" , "rate_pasv" ] )
3 |
4 | init
5 | // in year 2007
6 | self.insertPage( nil , .[
7 | .[ 'basic' 2.3 8.4 ]
8 | .[ 'business' 0.8 4.2 ]
9 | .[ 'premium' 3.2 5.3 ]
10 | ] )
11 |
12 | // in year 2008
13 | self.insertPage( nil , .[
14 | .[ 'basic' 3.2 7.6 ]
15 | .[ 'business' 1.1 4.5 ]
16 | .[ 'premium' 3.4 5.2 ]
17 | ] )
18 | end
19 |
20 | // set the current year
21 | function setYear( year )
22 | if year < 2008
23 | self.setPage( 1 )
24 | else
25 | self.setPage( 2 )
26 | end
27 | end
28 |
29 | // get rates
30 | function activeRate( acct, amount )
31 | return amount + ( self.find( 'name' , acct ).rate_act / 100.0 * amount)
32 | end
33 | end
34 |
35 | // A bit of calcs.
36 |
37 | // what should a premium account get for 1000$ on 2007?
38 | AccTable . setYear( 2007 )
39 | > "Premium account with 1000$ on 2007 was worth: " , \
40 | AccTable.activeRate( 'premium' , 1000 )
41 |
42 | AccTable . setYear( 2008 )
43 | > "Premium account with 1000$ on 2008 was worth: " , \
44 | AccTable.activeRate( 'premium' , 1000 )
45 |
--------------------------------------------------------------------------------
/Sample Code/Fantom:
--------------------------------------------------------------------------------
1 | ** Split a text file up into words and count occurences using:
2 | ** - File IO
3 | ** - String split
4 | ** - Maps
5 | **
6 | ** http://www.fantom.org/doc/examples/sys-wordcount
7 |
8 | class Wordcount
9 | {
10 | static Void main(Str[] args)
11 | {
12 | if (args.size != 1)
13 | {
14 | echo("usage: Wordcount ")
15 | Env.cur.exit(-1)
16 | }
17 |
18 | // Set up our map to count each word, and set its default to zero
19 | wordCounts := Str:Int[:] { def = 0 }
20 |
21 | // Open the file, read each line in order
22 | file := Uri(args[0]).toFile
23 | file.eachLine |line|
24 | {
25 | // skip empty lines
26 | if (line.trim.isEmpty) return
27 |
28 | // split and trim on whitespace into words
29 | words := line.split
30 |
31 | // count each one
32 | words.each |word| { wordCounts[word] += 1 }
33 | }
34 |
35 | // Show each word found, with its count, in alphabetical order
36 | wordCounts.keys.sort.each |key|
37 | {
38 | echo("$key ${wordCounts[key]}")
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Sample Code/Fortran 90:
--------------------------------------------------------------------------------
1 | ! Modules for dynamic array allocation
2 | ! https://web.stanford.edu/class/me200c/tutorial_90/09_modules.html
3 |
4 | MODULE Dyn_Array
5 | !---------------------------------------------------------------------
6 | !
7 | ! Module containing definitions needed to dynamically allocate
8 | ! the values of an array
9 | !
10 | !---------------------------------------------------------------------
11 | INTEGER :: n
12 | REAL, DIMENSION(:), ALLOCATABLE :: A
13 | END MODULE Dyn_Array
14 |
15 | PROGRAM Play_with_Array
16 | !---------------------------------------------------------------------
17 | !
18 | ! This program calls a subroutine to read in the values of
19 | ! a dynamically allocated array A and calls several 1D intrinsic
20 | ! array functions
21 | !
22 | ! Uses: MODULE Dyn_Array
23 | ! SUBROUTINE Get_Data
24 | ! SUBROUTINE Dealloc_Array
25 | !
26 | !---------------------------------------------------------------------
27 | USE Dyn_Array
28 | IMPLICIT NONE
29 |
30 | INTERFACE
31 | SUBROUTINE Get_Data
32 | END SUBROUTINE Get_Data
33 | END INTERFACE
34 |
35 | INTERFACE
36 | SUBROUTINE Dealloc_Array
37 | END SUBROUTINE Dealloc_Array
38 | END INTERFACE
39 |
40 | ! Declare local variables
41 | REAL :: Prod_A, Sum_A
42 |
43 | ! Call subroutine to read in data for array A
44 | CALL Get_Data
45 |
46 | ! Use intrinsic functions to generate data
47 | Prod_A = PRODUCT(A)
48 |
49 | ! Write out product of elements of array A
50 | write(*,100) "The product of the elements of array A area", &
51 | Prod_A
52 |
53 | ! Use intrinsic function to generate more data
54 | Sum_A = SUM(A)
55 |
56 | ! Write out sum of elements of array A
57 | write(*,100) "The sum of the elements of array A are", &
58 | Sum_A
59 |
60 | ! Now, deallocate memory containing array A
61 | CALL Dealloc_Array
62 |
63 | ! Place for format statement to live
64 | 100 format (A, 2x, F11.2)
65 |
66 | END PROGRAM Play_with_Array
67 | !-----Get_Data--------------------------------------------------------
68 | !
69 | ! Subroutine to read in the number of values to fill A array,
70 | ! allocate space, and to assign the values to A
71 | !
72 | ! Uses: MODULE Dyn_Array
73 | !
74 | !---------------------------------------------------------------------
75 | SUBROUTINE Get_Data
76 | USE Dyn_Array
77 |
78 | IMPLICIT NONE
79 |
80 | ! Declare local variables
81 | INTEGER :: AllocateStatus
82 |
83 | ! Read in number of array elements from user
84 | write(*,'(A)', ADVANCE = "NO") "Input the number of elements desired: "
85 | read(*,*) n
86 |
87 | ! Allocate storage for array A accordingly
88 | ALLOCATE( A(n), STAT = AllocateStatus)
89 | IF (AllocateStatus /= 0) STOP "*** Not enough memory ***"
90 |
91 | ! Read in values for A
92 | write(*, '(A)', ADVANCE = "NO") "Input array values: "
93 | read(*,*) A
94 |
95 | END SUBROUTINE Get_Data
96 |
97 | !-----Dealloc_Array---------------------------------------------------
98 | !
99 | ! Subroutine to deallocate array space
100 | !
101 | ! Uses: MODULE Dyn_Array
102 | !
103 | !---------------------------------------------------------------------
104 | SUBROUTINE Dealloc_Array
105 | USE Dyn_Array
106 |
107 | IMPLICIT NONE
108 |
109 | ! Declare local variables
110 | INTEGER :: DeAllocateStatus
111 |
112 | ! Deallocate storage for array A
113 | DEALLOCATE( A, STAT = DeAllocateStatus)
114 | IF (DeAllocateStatus /= 0) STOP "*** Trouble deallocating ***"
115 |
116 | END SUBROUTINE Dealloc_Array
117 |
--------------------------------------------------------------------------------
/Sample Code/Go:
--------------------------------------------------------------------------------
1 | // An implementation of Conway's Game of Life.
2 | // https://golang.org/doc/play/life.go
3 |
4 | package main
5 |
6 | import (
7 | "bytes"
8 | "fmt"
9 | "math/rand"
10 | "time"
11 | )
12 |
13 | // Field represents a two-dimensional field of cells.
14 | type Field struct {
15 | s [][]bool
16 | w, h int
17 | }
18 |
19 | // NewField returns an empty field of the specified width and height.
20 | func NewField(w, h int) *Field {
21 | s := make([][]bool, h)
22 | for i := range s {
23 | s[i] = make([]bool, w)
24 | }
25 | return &Field{s: s, w: w, h: h}
26 | }
27 |
28 | // Set sets the state of the specified cell to the given value.
29 | func (f *Field) Set(x, y int, b bool) {
30 | f.s[y][x] = b
31 | }
32 |
33 | // Alive reports whether the specified cell is alive.
34 | // If the x or y coordinates are outside the field boundaries they are wrapped
35 | // toroidally. For instance, an x value of -1 is treated as width-1.
36 | func (f *Field) Alive(x, y int) bool {
37 | x += f.w
38 | x %= f.w
39 | y += f.h
40 | y %= f.h
41 | return f.s[y][x]
42 | }
43 |
44 | // Next returns the state of the specified cell at the next time step.
45 | func (f *Field) Next(x, y int) bool {
46 | // Count the adjacent cells that are alive.
47 | alive := 0
48 | for i := -1; i <= 1; i++ {
49 | for j := -1; j <= 1; j++ {
50 | if (j != 0 || i != 0) && f.Alive(x+i, y+j) {
51 | alive++
52 | }
53 | }
54 | }
55 | // Return next state according to the game rules:
56 | // exactly 3 neighbors: on,
57 | // exactly 2 neighbors: maintain current state,
58 | // otherwise: off.
59 | return alive == 3 || alive == 2 && f.Alive(x, y)
60 | }
61 |
62 | // Life stores the state of a round of Conway's Game of Life.
63 | type Life struct {
64 | a, b *Field
65 | w, h int
66 | }
67 |
68 | // NewLife returns a new Life game state with a random initial state.
69 | func NewLife(w, h int) *Life {
70 | a := NewField(w, h)
71 | for i := 0; i < (w * h / 4); i++ {
72 | a.Set(rand.Intn(w), rand.Intn(h), true)
73 | }
74 | return &Life{
75 | a: a, b: NewField(w, h),
76 | w: w, h: h,
77 | }
78 | }
79 |
80 | // Step advances the game by one instant, recomputing and updating all cells.
81 | func (l *Life) Step() {
82 | // Update the state of the next field (b) from the current field (a).
83 | for y := 0; y < l.h; y++ {
84 | for x := 0; x < l.w; x++ {
85 | l.b.Set(x, y, l.a.Next(x, y))
86 | }
87 | }
88 | // Swap fields a and b.
89 | l.a, l.b = l.b, l.a
90 | }
91 |
92 | // String returns the game board as a string.
93 | func (l *Life) String() string {
94 | var buf bytes.Buffer
95 | for y := 0; y < l.h; y++ {
96 | for x := 0; x < l.w; x++ {
97 | b := byte(' ')
98 | if l.a.Alive(x, y) {
99 | b = '*'
100 | }
101 | buf.WriteByte(b)
102 | }
103 | buf.WriteByte('\n')
104 | }
105 | return buf.String()
106 | }
107 |
108 | func main() {
109 | l := NewLife(40, 15)
110 | for i := 0; i < 300; i++ {
111 | l.Step()
112 | fmt.Print("\x0c", l) // Clear screen and print field.
113 | time.Sleep(time.Second / 30)
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/Sample Code/Groovy:
--------------------------------------------------------------------------------
1 | // Simple DSL to change the state of a Car object
2 | // http://mrhaki.blogspot.ca/2011/11/groovy-goodness-create-our-own-script.html
3 |
4 | import org.codehaus.groovy.control.CompilerConfiguration
5 |
6 | // Simple Car class to save state and distance.
7 | class Car {
8 | String state
9 | Long distance = 0
10 | }
11 |
12 | // Custom Script with methods that change the Car's state.
13 | // The Car object is passed via the binding.
14 | abstract class CarScript extends Script {
15 | def start() {
16 | this.binding.car.state = 'started'
17 | }
18 |
19 | def stop() {
20 | this.binding.car.state = 'stopped'
21 | }
22 |
23 | def drive(distance) {
24 | this.binding.car.distance += distance
25 | }
26 | }
27 |
28 |
29 | // Use custom CarScript.
30 | def compilerConfiguration = new CompilerConfiguration()
31 | compilerConfiguration.scriptBaseClass = CarScript.class.name
32 |
33 | // Define Car object here, so we can use it in assertions later on.
34 | def car = new Car()
35 | // Add to script binding (CarScript references this.binding.car).
36 | def binding = new Binding(car: car)
37 |
38 | // Configure the GroovyShell.
39 | def shell = new GroovyShell(this.class.classLoader, binding, compilerConfiguration)
40 |
41 | // Simple DSL to start, drive and stop the car.
42 | // The methods are defined in the CarScript class.
43 | def carDsl = '''
44 | start()
45 | drive 20
46 | stop()
47 | '''
48 |
49 | // Run DSL script.
50 | shell.evaluate carDsl
51 |
52 | // Checks to see that Car object has changed.
53 | assert car.distance == 20
54 | assert car.state == 'stopped'
55 |
--------------------------------------------------------------------------------
/Sample Code/Gui4Cli:
--------------------------------------------------------------------------------
1 | // How a Gui4Cli program is structured
2 | // http://gui4cli.com/html/manual/ProgramStructure.htm
3 |
4 | G4C DirView
5 |
6 | WINDOW 168 13 510 471 "Your Computer"
7 | WinAttr Style resize
8 |
9 | xOnLoad
10 | GuiOpen #this
11 |
12 | xOnClose
13 | guiquit #this
14 |
15 | XLISTVIEW 185 0 323 472 "" "#disks" lvar1
16 | attr ID lv1
17 | attr frame sunk
18 | attr Style Grid/Drag/Drop/parent/disk
19 | Attr resize 0022
20 | if $lvar1 > ''
21 | run $lvar1
22 | endif
23 |
24 | xOnLVDir lv1 // happens wherever LV changes dir
25 | gosub #this ChangeDir // change window title
26 | use tv #this tv1
27 | tv cd $dirname // take treeview also to that dir..
28 |
29 | XTREEVIEW 0 0 180 472 "#disks" tvdir
30 | attr ID tv1
31 | attr frame sunk
32 | attr resize 0002
33 | attr style drag/drop
34 | lvuse #this lv1
35 | lvchange $tvdir // Take LV to the same dir
36 | gosub #this ChangeDir // update window title
37 |
38 | XSPLITER 180 0 6 680 tv1 lv1
39 |
40 | xRoutine ChangeDir
41 | if $$lv.dir = "" // empty means "disks" list
42 | setwintitle #this "Your Computer"
43 | else
44 | setwintitle #this $$lv.dir
45 | endif
46 |
--------------------------------------------------------------------------------
/Sample Code/HTML:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | My First Heading
6 |
7 | My first paragraph.
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Sample Code/Haskell:
--------------------------------------------------------------------------------
1 | -- Timeouts
2 | -- https://lotz84.github.io/haskellbyexample/ex/timeouts
3 |
4 | {-# LANGUAGE GADTs #-}
5 | import Control.Concurrent
6 | import Control.Concurrent.STM
7 |
8 | main = do
9 | c1 <- atomically $ newTQueue
10 | forkIO $ do
11 | threadDelay (2 * 1000000)
12 | atomically $ writeTQueue c1 "result 1"
13 |
14 | t1 <- newTimer (1 * 1000000)
15 | select [ Case c1 $ \res -> putStrLn res
16 | , Case t1 $ \_ -> putStrLn "timeout 1"]
17 |
18 | c2 <- atomically $ newTQueue
19 | forkIO $ do
20 | threadDelay (2 * 1000000)
21 | atomically $ writeTQueue c2 "result 2"
22 |
23 | t2 <- newTimer (3 * 1000000)
24 | select [ Case c2 $ \res -> putStrLn res
25 | , Case t2 $ \_ -> putStrLn "timeout 2"]
26 |
27 | type Timer = TMVar ()
28 |
29 | newTimer :: Int -> IO Timer
30 | newTimer delay = do
31 | timer <- atomically newEmptyTMVar
32 | forkIO $ do
33 | threadDelay delay
34 | atomically $ putTMVar timer ()
35 | return timer
36 |
37 | class Selectable f where
38 | tryRead :: f a -> STM (Maybe a)
39 |
40 | instance Selectable TMVar where
41 | tryRead = tryReadTMVar
42 |
43 | instance Selectable TQueue where
44 | tryRead = tryReadTQueue
45 |
46 | data Select a where
47 | Default :: IO a -> Select a
48 | Case :: Selectable s => s b -> (b -> IO a) -> Select a
49 |
50 | select :: [Select a] -> IO a
51 | select [] = error "select: empty list"
52 | select ((Default x):_) = x
53 | select (x@(Case v f):xs) = do
54 | var <- atomically $ tryRead v
55 | case var of
56 | Just b -> f b
57 | Nothing -> select (xs ++ [x])
58 |
--------------------------------------------------------------------------------
/Sample Code/Haxe:
--------------------------------------------------------------------------------
1 | // Stop watch
2 | // http://old.haxe.org/doc/snip/stopwatch
3 |
4 | import haxe.Timer;
5 |
6 | class StopWatch{
7 | public var ms: Float;
8 | public var seconds(getSeconds,null):Float;
9 | private var timer: Timer;
10 | private var startTime:Int;
11 | private var preText:String;
12 | private var lastStamp:Float;
13 |
14 | public inline function new(preText:String='')
15 | {
16 | timer = new Timer(1);
17 | timer.run();
18 |
19 | this.preText = preText;
20 | lastStamp = 0;
21 | }
22 |
23 | public inline function stop():String
24 | {
25 | timer.stop();
26 | ms = getStamp();
27 | return(preText+" "+Std.string(ms)+" ms.");
28 | }
29 |
30 | private inline function getSeconds( ):Float
31 | {
32 | return ms/1000;
33 | }
34 |
35 | private inline function getStamp():Float{
36 | var s:Float = Timer.stamp() - lastStamp;
37 | lastStamp = Timer.stamp();
38 | return s;
39 | }
40 |
41 | public inline function toString():String
42 | {
43 | return(preText+" "+Std.string(ms)+" ms.");
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Sample Code/ILYC:
--------------------------------------------------------------------------------
1 | # Control structures
2 | # http://ilyc.sourceforge.net/en/index.htm
3 |
4 | # Pre-note:
5 | # In this example, you will see the do..done structure.
6 | # It is the statement block.
7 | # You can put as many statements as you like inside a block.
8 |
9 | # Here you also see that the main() function
10 | # can take two arguments, which are an integer
11 | # and an array of string, respectively.
12 | # They are the number of and the values of
13 | # the program's command-line arguments,
14 | # not including the EXE file path.
15 | procedure main(int argc, string[] argv) do
16 | puts("The number of command-line arguments are: " + argc)
17 |
18 | # Let's create some variables to use
19 | int n = 10
20 | string[] a = new string[] { "Langston", "Caine", "Taylor" }
21 |
22 | # First, the if-then-else
23 | if n >= 10 then
24 | puts("Variable n is greater or equal to 10.")
25 |
26 | if a[0] = "Langston" then
27 | puts("The first one is Dr. Raymond Langston.")
28 | else
29 | puts("The first one is somebody.")
30 |
31 | # They can be nested to an abitrary level
32 | if n = 1 then
33 | puts("n = 1")
34 | else if n = 2 then
35 | puts("n = 2")
36 | else if n = 3 then
37 | puts("n = 3")
38 | else
39 | puts("n is not 1, 2 or 3.")
40 |
41 | # Now, the switch-case
42 | switch n
43 | case 1:
44 | puts("n = 1")
45 | case 2, 3:
46 | puts("n is 2 or 3.")
47 | default:
48 | puts("n is not 1, 2 or 3.")
49 | done
50 |
51 | # In some languages, you can not use non-numeric
52 | # values for switch-case.
53 | # But ILYC allows that.
54 | print("What is your name? ")
55 | switch reads()
56 | case "Ray", "Raymond":
57 | puts("Hello, Dr. Langston.")
58 | case "Horatio", "H.":
59 | puts("Good morning, Lt. Caine.")
60 | case "Mac":
61 | puts("Hi, Detector Taylor.")
62 | default:
63 | puts("Salut!")
64 | done
65 |
66 | # Below is the for-loop.
67 | # i is an automatic variable, which is declared
68 | # and deleted by the for loop.
69 | # You can declare your own variable prior to the loop,
70 | # but you have to delete it yourself.
71 | # It should be of int type, and is not an array.
72 | for i from 0 to a.Length - 1 loop
73 | puts(a[i])
74 |
75 | # You also have the while-loop
76 | while n > 0 loop do
77 | puts(n * 10)
78 | n = n - 1 #you should do this, otherwise it will loop forever!
79 | done
80 |
81 | # And the until-loop
82 | until n = 10 loop do
83 | puts(n * n)
84 | n = n + 1
85 | done
86 |
87 | # You can break a loop by the break statement
88 | for i from 0 to n loop do
89 | puts(i - 20)
90 | if i > 5 then do
91 | puts("\ti is greater than 5, and we stop here.")
92 | break
93 | done
94 | done
95 |
96 | # If you think some code may lead to error,
97 | # you can put it in the try-catch
98 | try do
99 | puts("We are going to do some silly thing.")
100 | puts("Such as dividing a number by 0.")
101 | puts(10 / 0)
102 | done
103 | catch (e) do
104 | puts("As you can see, an error has been thrown.")
105 | puts("You can catch it here.")
106 | puts("It is represented by the automatic variable e.")
107 | puts("\tDO NOT declare that variable yourself!")
108 | puts("The error message is: " + e.Message)
109 | puts("And the error code is: " + e.Code)
110 | done
111 | done
112 |
--------------------------------------------------------------------------------
/Sample Code/INI:
--------------------------------------------------------------------------------
1 | ; Do not delete this file
2 |
3 | [Section-1]
4 | BooleanVal=False
5 | IntegerVal=2423
6 |
7 | [Section-2]
8 | BooleanVal=True
9 | IntegerVal=145
10 |
--------------------------------------------------------------------------------
/Sample Code/Icon:
--------------------------------------------------------------------------------
1 | # Concordance Program Using Strings
2 | # http://www2.cs.arizona.edu/icon/progvis/lectures/memmon.htm
3 |
4 | global uses, lineno, width
5 |
6 | procedure main(args)
7 | width := 15 # width of word field
8 | uses := table()
9 | lineno := 0
10 | every tabulate(words()) # tabulate all citations
11 | output() # print the citations
12 | end
13 |
14 | # Add line number to citations for word
15 | #
16 | procedure tabulate(word)
17 | /uses[word] := set()
18 | insert(uses[word], lineno)
19 | return
20 | end
21 |
22 | # Generate words
23 | #
24 | procedure words()
25 | while line := read() do {
26 | lineno +:= 1
27 | write(right(lineno, 6), " ", line)
28 | map(line) ? while tab(upto(&letters)) do {
29 | s := tab(many(&letters))
30 | if *s >= 3 then suspend s# skip short words
31 | }
32 | }
33 | end
34 |
35 | # Print the results
36 | #
37 | procedure output()
38 | write() # blank line
39 | uses := sort(uses, 3) # sort citations
40 | while word := get(uses) do {
41 | line := ""
42 | numbers := sort(get(uses))
43 | while line ||:= get(numbers) || ", "
44 | write(left(word, width), line[1:-2])
45 | }
46 | end
47 |
--------------------------------------------------------------------------------
/Sample Code/Io:
--------------------------------------------------------------------------------
1 | // A minimal web server
2 | // http://iolanguage.org/guide/guide.html
3 |
4 | WebRequest := Object clone do(
5 | handleSocket := method(aSocket,
6 | aSocket streamReadNextChunk
7 | request := aSocket readBuffer \
8 | betweenSeq("GET ", " HTTP")
9 | f := File with(request)
10 | if(f exists,
11 | f streamTo(aSocket)
12 | ,
13 | aSocket streamWrite("not found")
14 | )
15 | aSocket close
16 | )
17 | )
18 |
19 | WebServer := Server clone do(
20 | setPort(8000)
21 | handleSocket := method(aSocket,
22 | WebRequest clone asyncSend(handleSocket(aSocket))
23 | )
24 | )
25 |
26 | WebServer start
27 |
--------------------------------------------------------------------------------
/Sample Code/JSON:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/draft-04/schema#",
3 | "title": "Product",
4 | "description": "A product from Acme's catalog",
5 | "type": "object",
6 | "properties": {
7 | "id": {
8 | "description": "The unique identifier for a product",
9 | "type": "integer"
10 | }
11 | },
12 | "required": ["id"]
13 | }
14 |
--------------------------------------------------------------------------------
/Sample Code/Java:
--------------------------------------------------------------------------------
1 | /**
2 | A class to measure time elapsed.
3 | https://www.cs.utexas.edu/~scottm/cs307/codingSamples.htm
4 | */
5 |
6 | public class Stopwatch
7 | {
8 | private long startTime;
9 | private long stopTime;
10 |
11 | public static final double NANOS_PER_SEC = 1000000000.0;
12 |
13 | /**
14 | start the stop watch.
15 | */
16 | public void start()
17 | {
18 | startTime = System.nanoTime();
19 | }
20 |
21 | /**
22 | stop the stop watch.
23 | */
24 | public void stop()
25 | { stopTime = System.nanoTime(); }
26 |
27 | /**
28 | elapsed time in seconds.
29 | @return the time recorded on the stopwatch in seconds
30 | */
31 | public double time()
32 | { return (stopTime - startTime) / NANOS_PER_SEC; }
33 |
34 | public String toString()
35 | {
36 | return "elapsed time: " + time() + " seconds.";
37 | }
38 |
39 | /**
40 | elapsed time in nanoseconds.
41 | @return the time recorded on the stopwatch in nanoseconds
42 | */
43 | public long timeInNanoseconds()
44 | { return (stopTime - startTime); }
45 | }
46 |
--------------------------------------------------------------------------------
/Sample Code/JavaScript:
--------------------------------------------------------------------------------
1 | // Using Event Delegation
2 | // http://javascriptbook.com/code/c06/js/event-delegation.js
3 |
4 | function getTarget(e) { // Declare function
5 | if (!e) { // If there is no event object
6 | e = window.event; // Use old IE event object
7 | }
8 | return e.target || e.srcElement; // Get the target of event
9 | }
10 |
11 | function itemDone(e) { // Declare function
12 | // Remove item from the list
13 | var target, elParent, elGrandparent; // Declare variables
14 | target = getTarget(e); // Get the item clicked link
15 |
16 | /*
17 | The book used the following code - but it had two shortcomings
18 | - Clicking between list items would remove the whole list
19 | - Clicking on italic text would remove the link - not the list item
20 |
21 | elParent = target.parentNode;
22 | elGrandparent = target.parentNode.parentNode;
23 | elGrandparent.removeChild(elParent);
24 |
25 | The next 10 lines improve that example
26 | */
27 |
28 | if ( target.nodeName.toLowerCase() == "a" ) { // If user clicked on an a element
29 | elListItem = target.parentNode; // Get its li element
30 | elList = elListItem.parentNode; // Get the ul element
31 | elList.removeChild(elListItem); // Remove list item from list
32 | }
33 | if ( target.nodeName.toLowerCase() == "em" ) { // If the user clicked on an em element
34 | elListItem = target.parentNode.parentNode; // Get its li element
35 | elList = elListItem.parentNode; // Get the ul element
36 | elList.removeChild(elListItem); // Remove list item from list
37 | }
38 |
39 | // Prevent the link from taking you elsewhere
40 | if (e.preventDefault) { // If preventDefault() works
41 | e.preventDefault(); // Use preventDefault()
42 | } else { // Otherwise
43 | e.returnValue = false; // Use old IE version
44 | }
45 | }
46 |
47 | // Set up event listeners to call itemDone() on click
48 | var el = document.getElementById('shoppingList');// Get shopping list
49 | if (el.addEventListener) { // If event listeners work
50 | el.addEventListener('click', function(e) { // Add listener on click
51 | itemDone(e); // It calls itemDone()
52 | }, false); // Use bubbling phase for flow
53 | } else { // Otherwise
54 | el.attachEvent('onclick', function(e) { // Use old IE model: onclick
55 | itemDone(e); // Call itemDone()
56 | });
57 | }
58 |
--------------------------------------------------------------------------------
/Sample Code/Julia:
--------------------------------------------------------------------------------
1 | # Julia function example
2 | # https://juliabyexample.helpmanual.io/
3 |
4 | # function to calculate the volume of a sphere
5 | function sphere_vol(r)
6 | # julia allows Unicode names (in UTF-8 encoding)
7 | # so either "pi" or the symbol π can be used
8 | return 4/3*pi*r^3
9 | end
10 |
11 | # functions can also be defined more succinctly
12 | quadratic(a, sqr_term, b) = (-b + sqr_term) / 2a
13 |
14 | # calculates x for 0 = a*x^2+b*x+c, arguments types can be defined in function
15 | # definitions
16 | function quadratic2(a::Float64, b::Float64, c::Float64)
17 | # unlike other languages 2a is equivalent to 2*a
18 | # a^2 is used instead of a**2 or pow(a,2)
19 | sqr_term = sqrt(b^2-4a*c)
20 | r1 = quadratic(a, sqr_term, b)
21 | r2 = quadratic(a, -sqr_term, b)
22 | # multiple values can be returned from a function using tuples
23 | # if the return keyword is omitted, the last term is returned
24 | r1, r2
25 | end
26 |
27 | vol = sphere_vol(3)
28 | # @printf allows number formatting but does not automatically append the \n to
29 | # statements, see below
30 | @printf "volume = %0.3f\n" vol
31 | #> volume = 113.097
32 |
33 | quad1, quad2 = quadratic2(2.0, -2.0, -12.0)
34 | println("result 1: ", quad1)
35 | #> result 1: 3.0
36 | println("result 2: ", quad2)
37 | #> result 2: -2.0
38 |
--------------------------------------------------------------------------------
/Sample Code/Just BASIC:
--------------------------------------------------------------------------------
1 | ' SpriteJump - Using Branch Event Label
2 | ' https://justbasic.wikispaces.com/SpriteJump
3 |
4 | ' OldKey holds last pressed key
5 | OldKey = 0
6 |
7 | ' xDir and yDir hold moving directions
8 | xDir = 0: yDir = 0
9 |
10 | WindowWidth = 757
11 | WindowHeight = 595
12 |
13 | UpperLeftX = Int((DisplayWidth - WindowWidth) /2)
14 | UpperLeftY = Int((DisplayHeight - WindowHeight) /2)
15 |
16 | Menu #demo, "&Options", "E&xit", [Quit]
17 | Graphicbox #demo.gb1, 0, 0, 750, 550
18 |
19 | Open "Controlling Sprites" for Window as #demo
20 | #demo, "Trapclose [Quit]"
21 |
22 | ' Load the background bmp
23 | Loadbmp "bg", "SPRITES\BG1.bmp"
24 | #demo.gb1, "Down; Background bg; Drawsprites"
25 |
26 | ' Load the sprites
27 | Loadbmp "cm1", "SPRITES\cave1.bmp"
28 | Loadbmp "cm2", "SPRITES\cave2.bmp"
29 | #demo.gb1, "Addsprite cm cm1 cm1 cm2 cm2"
30 |
31 | ' Set the initial cyclesprite command to 0
32 | #demo.gb1, "Cyclesprite cm 0"
33 |
34 | ' Set inital x, y variables (cm facing right to start)
35 | #demo.gb1, "Spritexy cm 350 450"
36 |
37 | ' Trap keypresses
38 | #demo.gb1, "When characterInput [KeyPress]"
39 | #demo.gb1, "Setfocus"
40 |
41 | ' Set the timer
42 | Timer 50, [SeeSprites]
43 | Wait
44 |
45 | [Quit]
46 | Timer 0
47 | Unloadbmp "bg"
48 | Close #demo
49 | End
50 |
51 | [KeyPress]
52 | NewKey = Asc(Right$(Inkey$, 1))
53 | #demo.gb1, "Spritexy? cm x y"
54 | Select Case NewKey
55 | Case 37
56 | #demo.gb1, "Spriteorient cm mirror"
57 | If OldKey = NewKey Then
58 | xDir = 0
59 | NewKey = 0
60 | Else
61 | xDir = 1
62 | End If
63 | Case 38
64 | yDir = 1
65 | Case 39
66 | #demo.gb1, "Spriteorient cm normal"
67 | If OldKey = NewKey Then
68 | xDir = 0
69 | NewKey = 0
70 | Else
71 | xDir = 2
72 | End If
73 | End Select
74 | OldKey = NewKey
75 | Wait
76 |
77 | [SeeSprites]
78 | #demo.gb1, "Spritexy? cm x y"
79 | Select Case yDir
80 | Case 1 ' Up
81 | y = y - 10
82 | If y < 350 Then
83 | yDir = 2
84 | y = 350
85 | End If
86 | Case 2 ' Down
87 | y = y + 10
88 | If y > 450 Then
89 | yDir = 0
90 | y = 450
91 | End If
92 | End Select
93 | Select Case xDir
94 | Case 1 ' Left
95 | x = x - 7
96 | If x < 5 Then
97 | xDir = 0
98 | x = 10
99 | End If
100 | Case 2 ' Right
101 | x = x + 7
102 | If x > 710 Then
103 | xDir = 0
104 | x = 700
105 | End If
106 | End Select
107 | If xDir + yDir > 0 Then
108 | #demo.gb1, "Cyclesprite cm 1"
109 | Else
110 | #demo.gb1, "Cyclesprite cm 0"
111 | End If
112 | #demo.gb1, "Spritexy cm ";x;" ";y
113 | #demo.gb1, "Setfocus; Drawsprites"
114 | Wait
115 |
--------------------------------------------------------------------------------
/Sample Code/KiXtart:
--------------------------------------------------------------------------------
1 | ; PMCHOICE.KIX, Version 2.00 for Windows NT
2 | ; Poor Man's replacement for the CHOICE command from the NT Resource Kit.
3 | ; Needs PMCHOICE.BAT to convert original parameters to Kix variables.
4 | ; Requires KiXtart 4.01 or later if a timeout is specified.
5 | ; Batch/KiXtart combination follows the original CHOICE.EXE syntax.
6 | ; Written by Rob van der Woude
7 | ; http://www.robvanderwoude.com
8 |
9 | ; Show text if required
10 | If $Text <> ""
11 | $Text
12 | EndIf
13 |
14 | ; Show prompt if required
15 | If $NoPrompt <> 1
16 | "? [" + $Choices + "]"
17 | EndIf
18 |
19 | :Start
20 | If $TimeOut = 0
21 | ; Wait infinitely for key to be pressed
22 | Get $Key
23 | Else
24 | ; Requires at least KiXtart 4.01
25 | $KixMajorVer = SubStr( @Kix, 1, InStr( @Kix, "." ) - 1 )
26 | If $KixMajorVer < 4
27 | Cls
28 | ? "PMChoice.kix requires KiXtart version 4.01 or later."
29 | ? "Your KiXtart version is " + @KIX + "."
30 | ?
31 | Quit 255
32 | EndIf
33 | ; Check if key is pressed
34 | If KbHit( )
35 | Get $Key
36 | Else
37 | ; Check if key is pressed each second during timeout interval
38 | $Counter = 0
39 | ; Default in case no key will be pressed before end of timeout
40 | $Key = Chr( 13 )
41 | Do
42 | Sleep 1
43 | $Counter = $Counter + 1
44 | If KbHit( )
45 | ; Once pressed, read and then exit loop
46 | Get $Key
47 | $Counter = $TimeOut
48 | EndIf
49 | Until $Counter = $TimeOut
50 | EndIf
51 | EndIf
52 |
53 | ; Pressing Esc results in return code 0
54 | If $Key = Chr( 27 )
55 | Exit 0
56 | EndIf
57 |
58 | ; Pressing Enter results in default (if defined!)
59 | If $Key = Chr( 13 )
60 | $Key = $Default
61 | EndIf
62 |
63 | ; The return code must be the position of the key in the choices string
64 | $Return = InStr( "$Choices", "$Key" )
65 |
66 | ; Beep and start again if an invalid key was pressed
67 | If $Return = 0
68 | Beep
69 | GoTo Start
70 | EndIf
71 |
72 | ; If cases sensitivity was defined, check if the cases match
73 | If $Cs = "1"
74 | If Asc( SubStr( "$Choices", $Return, 1 ) ) <> Asc( $Key )
75 | Beep
76 | GoTo Start
77 | EndIf
78 | EndIf
79 |
80 | ; Exit with the proper return code
81 | Exit $Return
82 |
--------------------------------------------------------------------------------
/Sample Code/Kotlin:
--------------------------------------------------------------------------------
1 | // https://learnxinyminutes.com/docs/kotlin/
2 |
3 | //The "class" keyword is used to declare classes.
4 | class ExampleClass(val x: Int) {
5 | fun memberFunction(y: Int) : Int {
6 | return x + y
7 | }
8 |
9 | infix fun infixMemberFunction(y: Int) : Int {
10 | return x * y
11 | }
12 | }
13 |
14 | /*
15 | Strings can contain template expressions.
16 | A template expression starts with a dollar sign ($).
17 | */
18 | val fooTemplateString = "$fooString has ${fooString.length} characters"
19 | println(fooTemplateString)
20 |
21 | // "when" can be used with an argument.
22 | when (i) {
23 | 0, 21 -> println("0 or 21")
24 | in 1..20 -> println("in the range 1 to 20")
25 | else -> println("none of the above")
26 | }
27 |
28 | // "when" can be used as a function that returns a value.
29 | var result = when (i) {
30 | 0, 21 -> "0 or 21"
31 | in 1..20 -> "in the range 1 to 20"
32 | else -> "none of the above"
33 | }
34 | println(result)
35 |
36 | /*
37 | We can check if an object is a particular type by using the "is" operator.
38 | If an object passes a type check then it can be used as that type without
39 | explicitly casting it.
40 | */
41 | fun smartCastExample(x: Any) : Boolean {
42 | if (x is Boolean) {
43 | // x is automatically cast to Boolean
44 | return x
45 | } else if (x is Int) {
46 | // x is automatically cast to Int
47 | return x > 0
48 | } else if (x is String) {
49 | // x is automatically cast to String
50 | return x.isNotEmpty()
51 | } else {
52 | return false
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Sample Code/Lean:
--------------------------------------------------------------------------------
1 | -- https://github.com/leanprover/lean/blob/master/tests/lean/1207.lean
2 |
3 | example : true :=
4 | begin
5 | assertv H : true := (by trivial),
6 | exact H
7 | end
8 |
9 | example : true :=
10 | begin
11 | assertv H : true := (by tactic.triv),
12 | exact H
13 | end
14 |
15 | meta example (h : tactic unit) : true :=
16 | begin
17 | h, -- ERROR h should not be visible here
18 | trivial
19 | end
20 |
21 | example : false :=
22 | begin
23 | assertv H : true := (by foo), -- ERROR
24 | exact sorry
25 | end
26 |
27 | constant P : Prop
28 | example (p : P) : true :=
29 | begin
30 | assertv H : P := by do { p ← tactic.get_local `p, tactic.exact p },
31 | trivial
32 | end
33 |
--------------------------------------------------------------------------------
/Sample Code/Lisp:
--------------------------------------------------------------------------------
1 | ; SVG.lisp
2 | ; http://landoflisp.com/svg.lisp
3 |
4 | (defmacro let1 (var val &body body)
5 | `(let ((,var ,val))
6 | ,@body))
7 |
8 | (defmacro split (val yes no)
9 | (let1 g (gensym)
10 | `(let1 ,g ,val
11 | (if ,g
12 | (let ((head (car ,g))
13 | (tail (cdr ,g)))
14 | ,yes)
15 | ,no))))
16 |
17 | (defun pairs (lst)
18 | (labels ((f (lst acc)
19 | (split lst
20 | (if tail
21 | (f (cdr tail) (cons (cons head (car tail)) acc))
22 | (reverse acc))
23 | (reverse acc))))
24 | (f lst nil)))
25 |
26 | (defun print-tag (name alst closingp)
27 | (princ #\<)
28 | (when closingp
29 | (princ #\/))
30 | (princ (string-downcase name))
31 | (mapc (lambda (att)
32 | (format t " ~a=\"~a\"" (string-downcase (car att)) (cdr att)))
33 | alst)
34 | (princ #\>))
35 |
36 | (defmacro tag (name atts &body body)
37 | `(progn (print-tag ',name
38 | (list ,@(mapcar (lambda (x)
39 | `(cons ',(car x) ,(cdr x)))
40 | (pairs atts)))
41 | nil)
42 | ,@body
43 | (print-tag ',name nil t)))
44 |
45 | (defmacro svg (&body body)
46 | `(tag svg (xmlns "http://www.w3.org/2000/svg"
47 | "xmlns:xlink" "http://www.w3.org/1999/xlink")
48 | ,@body))
49 |
50 | (defun brightness (col amt)
51 | (mapcar (lambda (x)
52 | (min 255 (max 0 (+ x amt))))
53 | col))
54 |
55 | (defun svg-style (color)
56 | (format nil
57 | "~{fill:rgb(~a,~a,~a);stroke:rgb(~a,~a,~a)~}"
58 | (append color
59 | (brightness color -100))))
60 |
61 | (defun polygon (points color)
62 | (tag polygon (points (format nil
63 | "~{~a,~a ~}"
64 | (mapcan (lambda (tp)
65 | (list (car tp) (cdr tp)))
66 | points))
67 | style (svg-style color))))
68 |
--------------------------------------------------------------------------------
/Sample Code/Lua:
--------------------------------------------------------------------------------
1 | -- TextProcessing
2 | -- http://lua-users.org/wiki/TextProcessing
3 |
4 | -- Write a line adding \n to the end
5 | -- [fp]: file handle
6 | -- s: string to write
7 | function writeLine(fp, s)
8 | if not s then s, fp = fp, nil end
9 | if fp then write(fp, s .. "\n")
10 | else write(s .. "\n")
11 | end
12 | end
13 |
14 | -- Remove any final \n from a string.
15 | -- s: string to process
16 | -- returns
17 | -- s: processed string
18 | function chomp(s)
19 | return gsub(s, "\n$", "")
20 | end
21 |
22 | -- Escape a string to be used as a pattern
23 | -- s: string to process
24 | -- returns
25 | -- s: processed string
26 | function escapePattern(s)
27 | s = gsub(s, "(%W)", "%%%1")
28 | return s
29 | end
30 |
31 | -- Escape a string to be used as a shell token (quote spaces and \s)
32 | -- s: string to process
33 | -- returns
34 | -- s: processed string
35 | function escapeShell(s)
36 | s = gsub(s, "([ %(%)])", "\\%1")
37 | return s
38 | end
39 |
40 | -- Turn a list of strings into a sep-separated string
41 | -- sep: separator
42 | -- l: list of strings to join
43 | -- returns
44 | -- s: joined up string
45 | function join(sep, l)
46 | local len = getn(l)
47 | if len == 0 then return "" end
48 | local s = l[1]
49 | for i = 2, len do s = s .. sep .. l[i] end
50 | return s
51 | end
52 |
53 | -- Justify a string
54 | -- s: string to justify
55 | -- width: width to justify to (+ve means right-justify; negative
56 | -- means left-justify)
57 | -- [padder]: string to pad with (" " if omitted)
58 | -- returns
59 | -- s: justified string
60 | function pad(s, width, padder)
61 | padder = strrep(padder or " ", abs(width))
62 | if width < 0 then return strsub(padder .. s, width) end
63 | return strsub(s .. padder, 1, width)
64 | end
65 |
66 | -- Wrap a string into a paragraph
67 | -- s: string to wrap
68 | -- w: width to wrap to [78]
69 | -- i1: indent of first line [0]
70 | -- i2: indent of subsequent lines [0]
71 | -- returns
72 | -- s: wrapped paragraph
73 | function wrap(s, w, i1, i2)
74 | w = w or 78
75 | i1 = i1 or 0
76 | i2 = i2 or 0
77 | affirm(i1 < w and i2 < w,
78 | "wrap: the indents must be less than the line width")
79 | s = strrep(" ", i1) .. s
80 | local lstart, len = 1, strlen(s)
81 | while len - lstart > w do
82 | local i = lstart + w
83 | while i > lstart and strsub(s, i, i) ~= " " do i = i - 1 end
84 | local j = i
85 | while j > lstart and strsub(s, j, j) == " " do j = j - 1 end
86 | s = strsub(s, 1, j) .. "\n" .. strrep(" ", i2) ..
87 | strsub(s, i + 1, -1)
88 | local change = i2 + 1 - (i - j)
89 | lstart = j + change
90 | len = len + change
91 | end
92 | return s
93 | end
94 |
95 | -- readLines: read _INPUT into a list of lines
96 | -- returns
97 | -- line: list of lines
98 | function readLines()
99 | local line = {}
100 | repeat
101 | local l = read("*l")
102 | if not l then break end
103 | tinsert(line, l)
104 | until nil
105 | return line
106 | end
107 |
--------------------------------------------------------------------------------
/Sample Code/Nemerle:
--------------------------------------------------------------------------------
1 | // Longest Common Subsequence
2 | // https://github.com/rsdn/nemerle/blob/master/snippets/lcs.n
3 |
4 | using Nemerle.IO;
5 | using System;
6 | using System.Math;
7 |
8 | class LCS
9 | {
10 | private _M : array [2, int];
11 | private _l : array [char];
12 | private _r : array [char];
13 |
14 | private static Max (x : int, y : int, z : int) : int
15 | {
16 | Max (Max (x, y), z)
17 | }
18 |
19 | private Step (i : int, j : int) : int
20 | {
21 | if (i == 0 || j == 0)
22 | {
23 | _M [i, j] = 0;
24 | 0
25 | }
26 | else {
27 | def value =
28 | if (_l [i - 1] != _r [j - 1])
29 | Max (Step (i, j - 1), Step (i - 1, j))
30 | else
31 | Max (Step (i - 1, j - 1) + 1, Step (i - 1, j), Step (i, j - 1));
32 |
33 | _M [i, j] = value;
34 | value
35 | }
36 | }
37 |
38 | public this (l : string, r : string)
39 | {
40 | printf ("Calculating LCS of %s and %s...\n", l, r);
41 |
42 | _M = array (l.Length + 1, r.Length + 1);
43 | _l = l.ToCharArray ();
44 | _r = r.ToCharArray ();
45 |
46 | printf ("%d\n", this.Step (l.Length, r.Length));
47 | }
48 |
49 |
50 | public static Main () : void
51 | {
52 | _ = LCS ("alamakotazz", "komarezzk");
53 | _ = LCS ("axbyczd", "exfygzh");
54 | _ = LCS ("This is not", "This is not");
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Sample Code/Nim:
--------------------------------------------------------------------------------
1 | # Closure Iterators
2 | # https://nim-by-example.github.io/for_iterators/
3 |
4 | proc countTo(n: int): iterator(): int =
5 | return iterator(): int =
6 | var i = 0
7 | while i <= n:
8 | yield i
9 | inc i
10 |
11 | let countTo20 = countTo(20)
12 |
13 | echo countTo20()
14 |
15 | var output = ""
16 | # Raw iterator usage:
17 | while true:
18 | # 1. grab an element
19 | let next = countTo20()
20 | # 2. Is the element bogus? Its the end of the loop, discard it
21 | if finished(countTo20):
22 | break
23 | # 3. Loop body goes here:
24 | output.add($next & " ")
25 |
26 | echo output
27 |
28 | output = ""
29 | let countTo9 = countTo(9)
30 | for i in countTo9():
31 | output.add($i)
32 | echo output
33 |
--------------------------------------------------------------------------------
/Sample Code/OCaml:
--------------------------------------------------------------------------------
1 | (* OCaml Graphics *)
2 | (* https://ocaml.org/learn/tutorials/structure_of_ocaml_programs.html *)
3 |
4 | (* To compile this example: ocamlc graphics.cma grtest1.ml -o grtest1 *)
5 | open Graphics;;
6 |
7 | open_graph " 640x480";;
8 | for i = 12 downto 1 do
9 | let radius = i * 20 in
10 | set_color (if i mod 2 = 0 then red else yellow);
11 | fill_circle 320 240 radius
12 | done;;
13 | read_line ();;
14 |
15 | (* To compile this example: ocamlc graphics.cma grtest2.ml -o grtest2 *)
16 |
17 | Random.self_init ();;
18 | Graphics.open_graph " 640x480";;
19 |
20 | let rec iterate r x_init i =
21 | if i = 1 then x_init
22 | else
23 | let x = iterate r x_init (i-1) in
24 | r *. x *. (1.0 -. x);;
25 |
26 | for x = 0 to 639 do
27 | let r = 4.0 *. (float_of_int x) /. 640.0 in
28 | for i = 0 to 39 do
29 | let x_init = Random.float 1.0 in
30 | let x_final = iterate r x_init 500 in
31 | let y = int_of_float (x_final *. 480.) in
32 | Graphics.plot x y
33 | done
34 | done;;
35 |
36 | read_line ();;
37 |
--------------------------------------------------------------------------------
/Sample Code/Objective-C:
--------------------------------------------------------------------------------
1 | // Forwarder.m
2 | // https://en.wikipedia.org/wiki/Objective-C
3 |
4 | #import "Forwarder.h"
5 |
6 | @implementation Forwarder
7 |
8 | - (retval_t)forward:(SEL)sel args:(arglist_t) args {
9 | /*
10 | * Check whether the recipient actually responds to the message.
11 | * This may or may not be desirable, for example, if a recipient
12 | * in turn does not respond to the message, it might do forwarding
13 | * itself.
14 | */
15 | if([recipient respondsToSelector:sel]) {
16 | return [recipient performv:sel args:args];
17 | } else {
18 | return [self error:"Recipient does not respond"];
19 | }
20 | }
21 | - (id)setRecipient:(id)_recipient {
22 | [recipient autorelease];
23 | recipient = [_recipient retain];
24 | return self;
25 | }
26 |
27 | - (id) recipient {
28 | return recipient;
29 | }
30 | @end
31 |
--------------------------------------------------------------------------------
/Sample Code/PHP:
--------------------------------------------------------------------------------
1 | // Loop through a multidimensional array
2 | // http://www.w3schools.com/php/showphp.asp?filename=demo_array_multi2
3 |
4 | Row number $row
";
15 | echo "";
16 | for ($col = 0; $col < 3; $col++) {
17 | echo "- ".$cars[$row][$col]."
";
18 | }
19 | echo "
";
20 | }
21 | ?>
22 |
--------------------------------------------------------------------------------
/Sample Code/ParaSail:
--------------------------------------------------------------------------------
1 | // https://forge.open-do.org/plugins/moinmoin/parasail/
2 |
3 | import PSL::Short_Names::*, *
4 |
5 | func Greetings() is
6 | Println("Hello, World!")
7 | end func Greetings
8 |
9 | func Fib(N : Int) {N >= 0} -> Int is
10 | // '{N >= 0}' is a precondition to this function
11 | // Preconditions are built in the language and checked by the compiler
12 | if N <= 1 then
13 | return N
14 | else
15 | // Left and right side of the '+' are computed in Parellel here
16 | return Fib(N - 1) + Fib(N - 2)
17 | end if Fib
18 |
19 | func Increment_All(var Nums : Vector) is
20 | // This function takes a 'var' parameter.
21 | // The modification made here will be seen by caller
22 | for each Elem of Nums concurrent loop
23 | // The 'concurrent' keyword tells the compiler than
24 | // iterations of the loop can happen in any order.
25 | // It will choose the most optimal number of picothreads to use
26 | Elem += 1
27 | end loop
28 | end func Increment_All
29 |
30 | func Sum_Of_Squares(N : Int) -> Int is
31 | // Built-in and inherntly parallel map-reduce
32 | // Initial value is enclosed with angle brackets
33 | return (for I in 1 .. N => <0> + I ** 2)
34 | end func Sum_Of_Squares
35 |
--------------------------------------------------------------------------------
/Sample Code/Pascal:
--------------------------------------------------------------------------------
1 | (* A simple bubble sort program *)
2 | (* http://sandbox.mc.edu/~bennet/cs404/doc/sort_pas.html *)
3 |
4 | PROGRAM Sort(input, output);
5 | CONST
6 | (* Max array size. *)
7 | MaxElts = 50;
8 | TYPE
9 | (* Type of the element array. *)
10 | IntArrType = ARRAY [1..MaxElts] OF Integer;
11 |
12 | VAR
13 | (* Indexes, exchange temp, array size. *)
14 | i, j, tmp, size: integer;
15 |
16 | (* Array of ints *)
17 | arr: IntArrType;
18 |
19 | (* Read in the integers. *)
20 | PROCEDURE ReadArr(VAR size: Integer; VAR a: IntArrType);
21 | BEGIN
22 | size := 1;
23 | WHILE NOT eof DO BEGIN
24 | readln(a[size]);
25 | IF NOT eof THEN
26 | size := size + 1
27 | END
28 | END;
29 |
30 | BEGIN
31 | (* Read *)
32 | ReadArr(size, arr);
33 |
34 | (* Sort using bubble sort. *)
35 | FOR i := size - 1 DOWNTO 1 DO
36 | FOR j := 1 TO i DO
37 | IF arr[j] > arr[j + 1] THEN BEGIN
38 | tmp := arr[j];
39 | arr[j] := arr[j + 1];
40 | arr[j + 1] := tmp;
41 | END;
42 |
43 | (* Print. *)
44 | FOR i := 1 TO size DO
45 | writeln(arr[i])
46 | END.
47 |
--------------------------------------------------------------------------------
/Sample Code/Pike:
--------------------------------------------------------------------------------
1 | // Written in 2000 by Robert J. Budzynski
2 | // Current address:
3 | // do whatever you like with it, but I'll take no blame
4 |
5 | #if !constant(readlink)
6 | #error Sorry, symbolic links not supported here
7 | #endif
8 | #pragma strict_types
9 |
10 | void reportboguslinks( string prefix )
11 | {
12 | array(string) names;
13 | string target;
14 | object fstat;
15 |
16 | sort( names = get_dir( "." ) );
17 |
18 | foreach( names, string name )
19 | {
20 | if ( !(fstat = file_stat( name, 1 )) )
21 | {
22 | werror( prefix + name + ": can't stat file\n" );
23 | continue;
24 | }
25 | switch ( fstat->type )
26 | {
27 | case "lnk": // symlink
28 | if ( ! file_stat( name ) )
29 | write( prefix + name + " -> " + readlink( name ) + "\n" );
30 | break;
31 | case "dir": // dir
32 | if ( cd( name ) )
33 | {
34 | reportboguslinks( prefix + name + "/" );
35 | cd( ".." );
36 | }
37 | else
38 | {
39 | write( prefix + name + ": can't cd\n" );
40 | }
41 | break;
42 | default:
43 | continue;
44 | }
45 | }
46 | }
47 |
48 | int
49 | main( int argc, array(string) argv )
50 | {
51 | string prefix;
52 |
53 | prefix = (argc > 1 ) ? argv[1] : "";
54 | if (strlen( prefix ) )
55 | {
56 | cd( prefix ) || error( "%s\: invalid argument (can't cd)\n", prefix);
57 | ( prefix[-1] == '/' ) || ( prefix += "/" );
58 | reportboguslinks( prefix );
59 | }
60 | else
61 | {
62 | reportboguslinks( "" );
63 | }
64 | return 0;
65 | }
66 |
--------------------------------------------------------------------------------
/Sample Code/PowerShell:
--------------------------------------------------------------------------------
1 | #
2 | # LeapYear.ps1, Version 1.00
3 | #
4 | # Usage: .\LEAPYEAR.PS1 [ year ]
5 | #
6 | # Where: "year" is the year which you want to test
7 | # (default is current year)
8 | #
9 | # Written by Rob van der Woude
10 | # http://www.robvanderwoude.com
11 | #
12 |
13 | # Get the specified year
14 | param( [int]$year = ( Get-Date ).Year )
15 |
16 | # Get the current year
17 | [int]$thisyear = ( Get-Date ).Year
18 |
19 | # Format the output text (past, present or future?)
20 | $is1 = "is"
21 | $is2 = ""
22 | If ( $year -lt $thisyear ) {
23 | $is1 = "was"
24 | }
25 | If ( $year -gt $thisyear ) {
26 | $is1 = "will"
27 | $is2 = " be"
28 | }
29 |
30 | # Check if the specified year is a leap year
31 | [boolean]$leapyear = ( [boolean]!( $year % 4 ) -and [boolean]( $year % 100 ) ) -or [boolean]!( $year % 400 )
32 |
33 | # Display the result
34 | If ( $leapyear ) {
35 | Write-Host "$year $is1$is2 a leap year"
36 | }
37 | Else {
38 | Write-Host "$year $is1 NOT$is2 a leap year"
39 | }
40 |
--------------------------------------------------------------------------------
/Sample Code/Prolog:
--------------------------------------------------------------------------------
1 | % N-Queens Problem
2 | % https://www.cs.ccu.edu.tw/~dan/prologProgs.html
3 |
4 | sel(X, [X|Y], Y).
5 | sel(U, [X|Y], [X|V]) :- sel(U,Y,V).
6 |
7 | safe([ ]).
8 | safe([X|Y]) :- check(X,Y), safe(Y).
9 |
10 | check(_,[ ]).
11 | check(P, [Q|R]) :-
12 | not_on_diag(P,Q), check(P,R).
13 |
14 | not_on_diag(p(X1,Y1),p(X2,Y2)) :-
15 | DX is X1-X2, DY is Y1-Y2,
16 | MDY is Y2-Y1, DX=\=DY, DX=\=MDY.
17 |
18 | queens(Rows, [Col|RestCols], Points):-
19 | sel(Row,Rows,RestRows),
20 | safe([p(Row,Col) | Points]),
21 | queens(RestRows,RestCols,
22 | [p(Row,Col) | Points]).
23 |
24 | queens( [ ], [ ], Points) :-
25 | print('Solution: '),print(Points),nl.
26 |
27 | ?- queens([1,2,3,4,5,6,7,8],
28 | [1,2,3,4,5,6,7,8], [ ]), fail.
29 |
--------------------------------------------------------------------------------
/Sample Code/PureScript:
--------------------------------------------------------------------------------
1 | -- http://www.purescript.org/learn/getting-started/
2 |
3 | module Main where
4 |
5 | import Prelude
6 |
7 | import Euler (answer)
8 | import Control.Monad.Eff.Console (log)
9 |
10 | main = do
11 | log ("The answer is " <> show answer)
12 |
--------------------------------------------------------------------------------
/Sample Code/Python:
--------------------------------------------------------------------------------
1 | # 8-Queens Problem (recursion)
2 | # https://wiki.python.org/moin/SimplePrograms
3 |
4 | BOARD_SIZE = 8
5 |
6 | def under_attack(col, queens):
7 | left = right = col
8 |
9 | for r, c in reversed(queens):
10 | left, right = left - 1, right + 1
11 |
12 | if c in (left, col, right):
13 | return True
14 | return False
15 |
16 | def solve(n):
17 | if n == 0:
18 | return [[]]
19 |
20 | smaller_solutions = solve(n - 1)
21 |
22 | return [solution+[(n,i+1)]
23 | for i in xrange(BOARD_SIZE)
24 | for solution in smaller_solutions
25 | if not under_attack(i+1, solution)]
26 | for answer in solve(BOARD_SIZE):
27 | print answer
28 |
--------------------------------------------------------------------------------
/Sample Code/R:
--------------------------------------------------------------------------------
1 | # Goals: To write functions
2 | # To write functions that send back multiple objects.
3 | # http://www.mayin.org/ajayshah/KB/R/html/b4.html
4 |
5 | # FIRST LEARN ABOUT LISTS --
6 | X = list(height=5.4, weight=54)
7 | print("Use default printing --")
8 | print(X)
9 | print("Accessing individual elements --")
10 | cat("Your height is ", X$height, " and your weight is ", X$weight, "\n")
11 |
12 | # FUNCTIONS --
13 | square <- function(x) {
14 | return(x*x)
15 | }
16 | cat("The square of 3 is ", square(3), "\n")
17 |
18 | # default value of the arg is set to 5.
19 | cube <- function(x=5) {
20 | return(x*x*x);
21 | }
22 | cat("Calling cube with 2 : ", cube(2), "\n") # will give 2^3
23 | cat("Calling cube : ", cube(), "\n") # will default to 5^3.
24 |
25 | # LEARN ABOUT FUNCTIONS THAT RETURN MULTIPLE OBJECTS --
26 | powers <- function(x) {
27 | parcel = list(x2=x*x, x3=x*x*x, x4=x*x*x*x);
28 | return(parcel);
29 | }
30 |
31 | X = powers(3);
32 | print("Showing powers of 3 --"); print(X);
33 |
34 | # WRITING THIS COMPACTLY (4 lines instead of 7)
35 |
36 | powerful <- function(x) {
37 | return(list(x2=x*x, x3=x*x*x, x4=x*x*x*x));
38 | }
39 | print("Showing powers of 3 --"); print(powerful(3));
40 |
41 | # In R, the last expression in a function is, by default, what is
42 | # returned. So you could equally just say:
43 | powerful <- function(x) {list(x2=x*x, x3=x*x*x, x4=x*x*x*x)}
44 |
--------------------------------------------------------------------------------
/Sample Code/Registry:
--------------------------------------------------------------------------------
1 | Windows Registry Editor Version 5.00
2 |
3 | ; Created by Guy Thomas. Purpose to display the Build Number on the desktop
4 | [HKEY_CURRENT_USER\Control Panel\Desktop]
5 | "PaintDesktopVersion"=dword:00000001
6 |
--------------------------------------------------------------------------------
/Sample Code/Resource:
--------------------------------------------------------------------------------
1 | #include "shapes.h"
2 |
3 | ShapesCursor CURSOR SHAPES.CUR
4 | ShapesIcon ICON SHAPES.ICO
5 |
6 | ShapesMenu MENU
7 | {
8 | POPUP "&Shape"
9 | {
10 | MENUITEM "&Clear", ID_CLEAR
11 | MENUITEM "&Rectangle", ID_RECT
12 | MENUITEM "&Triangle", ID_TRIANGLE
13 | MENUITEM "&Star", ID_STAR
14 | MENUITEM "&Ellipse", ID_ELLIPSE
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Sample Code/Rexx:
--------------------------------------------------------------------------------
1 | /* REXX SHORTPG Operates on an Enterprize-PL/I listing to
2 | eliminate the spurious blank line at the
3 | bottom of each page.
4 |
5 | http://www.rexxla.org/freerepo/REXX/shortpg.txt
6 | */
7 | address ISREDIT
8 | "MACRO (opts)"
9 | upper opts
10 | parse var opts "TRACE" tv .
11 | parse value tv "N" with tv .
12 | rc = Trace("O"); rc = Trace(tv)
13 |
14 | "RESET"
15 | "F p'=' LAST"
16 | do while rc = 0 /* while found */
17 | "(text) = LINE .zcsr" /* acquire text */
18 | if Substr(text,2) = "" then, /* it's blank */
19 | "XSTATUS .zcsr = X" /* hide it */
20 | "F '1' 1 PREV"
21 | "F p'=' PREV" /* line before */
22 | end /* rc = 0 */
23 | rc = Trace("O"); rc = Trace(tv)
24 | "DEL ALL X"
25 |
26 | exit /*@ SHORTPG */
27 |
--------------------------------------------------------------------------------
/Sample Code/Rust:
--------------------------------------------------------------------------------
1 | // Tuples example
2 | // http://rustbyexample.com/primitives/tuples.html
3 |
4 | // Tuples can be used as function arguments and as return values
5 | fn reverse(pair: (i32, bool)) -> (bool, i32) {
6 | // `let` can be used to bind the members of a tuple to variables
7 | let (integer, boolean) = pair;
8 |
9 | (boolean, integer)
10 | }
11 |
12 | // The following struct is for the activity.
13 | #[derive(Debug)]
14 | struct Matrix(f32, f32, f32, f32);
15 |
16 | fn main() {
17 | // A tuple with a bunch of different types
18 | let long_tuple = (1u8, 2u16, 3u32, 4u64,
19 | -1i8, -2i16, -3i32, -4i64,
20 | 0.1f32, 0.2f64,
21 | 'a', true);
22 |
23 | // Values can be extracted from the tuple using tuple indexing
24 | println!("long tuple first value: {}", long_tuple.0);
25 | println!("long tuple second value: {}", long_tuple.1);
26 |
27 | // Tuples can be tuple members
28 | let tuple_of_tuples = ((1u8, 2u16, 2u32), (4u64, -1i8), -2i16);
29 |
30 | // Tuples are printable
31 | println!("tuple of tuples: {:?}", tuple_of_tuples);
32 |
33 | let pair = (1, true);
34 | println!("pair is {:?}", pair);
35 |
36 | println!("the reversed pair is {:?}", reverse(pair));
37 |
38 | // To create one element tuples, the comma is required to tell them apart
39 | // from a literal surrounded by parentheses
40 | println!("one element tuple: {:?}", (5u32,));
41 | println!("just an integer: {:?}", (5u32));
42 |
43 | //tuples can be destructured to create bindings
44 | let tuple = (1, "hello", 4.5, true);
45 |
46 | let (a, b, c, d) = tuple;
47 | println!("{:?}, {:?}, {:?}, {:?}", a, b, c, d);
48 |
49 | let matrix = Matrix(1.1, 1.2, 2.1, 2.2);
50 | println!("{:?}", matrix)
51 | }
52 |
--------------------------------------------------------------------------------
/Sample Code/SQF:
--------------------------------------------------------------------------------
1 | private ["_item", "_player"];
2 |
3 | _npc = _this select 0;
4 | _player = _this select 1;
5 | _action = _this select 2;
6 |
7 | _npc removeAction _action;
8 |
9 | _itemHeld = _this select 3 select 0;
10 | _item = switch (_itemHeld) do {
11 | case "watchHolder": {"ItemWatch"};
12 | case "mapHolder": {"ItemMap"};
13 | case "compassHolder": {"ItemCompass"};
14 | };
15 |
16 | if (_player getVariable _itemHeld == _npc) then {
17 | hint "Found it!";
18 | _player addWeapon _item;
19 | } else {
20 | hint "Sorry, I have nothing for you!";
21 | };
22 |
--------------------------------------------------------------------------------
/Sample Code/SQL:
--------------------------------------------------------------------------------
1 | -- PL/SQL Block
2 | -- https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/a_samps.htm
3 |
4 | -- available online in file 'sample4'
5 | DECLARE
6 | CURSOR c1 IS
7 | SELECT account_id, oper_type, new_value FROM action
8 | ORDER BY time_tag
9 | FOR UPDATE OF status;
10 | BEGIN
11 | FOR acct IN c1 LOOP -- process each row one at a time
12 |
13 | acct.oper_type := upper(acct.oper_type);
14 |
15 | /*----------------------------------------*/
16 | /* Process an UPDATE. If the account to */
17 | /* be updated doesn't exist, create a new */
18 | /* account. */
19 | /*----------------------------------------*/
20 | IF acct.oper_type = 'U' THEN
21 | UPDATE accounts SET bal = acct.new_value
22 | WHERE account_id = acct.account_id;
23 |
24 | IF SQL%NOTFOUND THEN -- account didn't exist. Create it.
25 | INSERT INTO accounts
26 | VALUES (acct.account_id, acct.new_value);
27 | UPDATE action SET status =
28 | 'Update: ID not found. Value inserted.'
29 | WHERE CURRENT OF c1;
30 | ELSE
31 | UPDATE action SET status = 'Update: Success.'
32 | WHERE CURRENT OF c1;
33 | END IF;
34 |
35 | /*--------------------------------------------*/
36 | /* Process an INSERT. If the account already */
37 | /* exists, do an update of the account */
38 | /* instead. */
39 | /*--------------------------------------------*/
40 | ELSIF acct.oper_type = 'I' THEN
41 | BEGIN
42 | INSERT INTO accounts
43 | VALUES (acct.account_id, acct.new_value);
44 | UPDATE action set status = 'Insert: Success.'
45 | WHERE CURRENT OF c1;
46 | EXCEPTION
47 | WHEN DUP_VAL_ON_INDEX THEN -- account already exists
48 | UPDATE accounts SET bal = acct.new_value
49 | WHERE account_id = acct.account_id;
50 | UPDATE action SET status =
51 | 'Insert: Acct exists. Updated instead.'
52 | WHERE CURRENT OF c1;
53 | END;
54 |
55 | /*--------------------------------------------*/
56 | /* Process a DELETE. If the account doesn't */
57 | /* exist, set the status field to say that */
58 | /* the account wasn't found. */
59 | /*--------------------------------------------*/
60 | ELSIF acct.oper_type = 'D' THEN
61 | DELETE FROM accounts
62 | WHERE account_id = acct.account_id;
63 |
64 | IF SQL%NOTFOUND THEN -- account didn't exist.
65 | UPDATE action SET status = 'Delete: ID not found.'
66 | WHERE CURRENT OF c1;
67 | ELSE
68 | UPDATE action SET status = 'Delete: Success.'
69 | WHERE CURRENT OF c1;
70 | END IF;
71 |
72 | /*--------------------------------------------*/
73 | /* The requested operation is invalid. */
74 | /*--------------------------------------------*/
75 | ELSE -- oper_type is invalid
76 | UPDATE action SET status =
77 | 'Invalid operation. No action taken.'
78 | WHERE CURRENT OF c1;
79 |
80 | END IF;
81 |
82 | END LOOP;
83 | COMMIT;
84 | END;
85 |
--------------------------------------------------------------------------------
/Sample Code/Scala:
--------------------------------------------------------------------------------
1 | // Window system example
2 | // https://en.wikipedia.org/wiki/Scala_(programming_language)
3 |
4 | abstract class Window {
5 | // abstract
6 | def draw()
7 | }
8 |
9 | class SimpleWindow extends Window {
10 | def draw() {
11 | println("in SimpleWindow")
12 | // draw a basic window
13 | }
14 | }
15 |
16 | trait WindowDecoration extends Window { }
17 |
18 | trait HorizontalScrollbarDecoration extends WindowDecoration {
19 | // "abstract override" is needed here in order for "super()" to work because the parent
20 | // function is abstract. If it were concrete, regular "override" would be enough.
21 | abstract override def draw() {
22 | println("in HorizontalScrollbarDecoration")
23 | super.draw()
24 | // now draw a horizontal scrollbar
25 | }
26 | }
27 |
28 | trait VerticalScrollbarDecoration extends WindowDecoration {
29 | abstract override def draw() {
30 | println("in VerticalScrollbarDecoration")
31 | super.draw()
32 | // now draw a vertical scrollbar
33 | }
34 | }
35 |
36 | trait TitleDecoration extends WindowDecoration {
37 | abstract override def draw() {
38 | println("in TitleDecoration")
39 | super.draw()
40 | // now draw the title bar
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Sample Code/Scheme:
--------------------------------------------------------------------------------
1 | ; Binary Tree sort
2 | ; http://cs.gmu.edu/~white/CS363/Scheme/SchemeSamples.html
3 |
4 | ; We are going to represent each node in a binary tree as:
5 | ; (value (left child)(right child)) If the node has no left
6 | ; and/or right child, this is represented with (). So,
7 | ; (2 (1()())(3()())) is the tree: 2
8 | ; / \
9 | ; 1 3
10 |
11 |
12 | (define (binarysort L)
13 | (if (null? L) '()
14 | (traverse (btree L))
15 | ))
16 |
17 | (define (btree L)
18 | (if (= (length L) 1) (leaf (car L))
19 | (binsert (btree (cdr L)) (car L))
20 | )
21 | )
22 |
23 |
24 | (define (binsert T A) ; insert A into the tree
25 | (cond ( (null? T) (leaf A) ) ; insert here
26 | ( (> (car T) A) (list (car T)
27 | (binsert (car (cdr T)) A)
28 | (car (cdr (cdr T))))
29 | ) ; left subtree
30 | ( else (list (car T)
31 | (car (cdr T))
32 | (binsert (car (cdr (cdr T))) A)) ; right subtree
33 | )
34 | )
35 | )
36 |
37 | (define (leaf A) ; add a leaf to the tree (A ()())
38 | (list A '() '())
39 | )
40 |
41 | (define (traverse L) ; output sorted list by traversing the tree
42 | (cond ( (null? L) L)
43 | ( else
44 | (append (traverse (car (cdr L)))
45 | (cons (car L)(traverse (car (cdr (cdr L))))))
46 | )
47 | )
48 | )
49 |
50 | (define (length L)
51 | (if (null? L) 0
52 | (+ 1 (length (cdr L)))
53 | )
54 | )
55 |
--------------------------------------------------------------------------------
/Sample Code/Solidity:
--------------------------------------------------------------------------------
1 | // Safe Remote Purchase
2 | // http://solidity.readthedocs.io/en/develop/solidity-by-example.html
3 |
4 | contract Purchase {
5 | uint public value;
6 | address public seller;
7 | address public buyer;
8 | enum State { Created, Locked, Inactive }
9 | State public state;
10 |
11 | function Purchase() payable {
12 | seller = msg.sender;
13 | value = msg.value / 2;
14 | if (2 * value != msg.value) throw;
15 | }
16 |
17 | modifier require(bool _condition) {
18 | if (!_condition) throw;
19 | _;
20 | }
21 |
22 | modifier onlyBuyer() {
23 | if (msg.sender != buyer) throw;
24 | _;
25 | }
26 |
27 | modifier onlySeller() {
28 | if (msg.sender != seller) throw;
29 | _;
30 | }
31 |
32 | modifier inState(State _state) {
33 | if (state != _state) throw;
34 | _;
35 | }
36 |
37 | event aborted();
38 | event purchaseConfirmed();
39 | event itemReceived();
40 |
41 | /// Abort the purchase and reclaim the ether.
42 | /// Can only be called by the seller before
43 | /// the contract is locked.
44 | function abort()
45 | onlySeller
46 | inState(State.Created)
47 | {
48 | aborted();
49 | state = State.Inactive;
50 | if (!seller.send(this.balance))
51 | throw;
52 | }
53 |
54 | /// Confirm the purchase as buyer.
55 | /// Transaction has to include `2 * value` ether.
56 | /// The ether will be locked until confirmReceived
57 | /// is called.
58 | function confirmPurchase()
59 | inState(State.Created)
60 | require(msg.value == 2 * value)
61 | payable
62 | {
63 | purchaseConfirmed();
64 | buyer = msg.sender;
65 | state = State.Locked;
66 | }
67 |
68 | /// Confirm that you (the buyer) received the item.
69 | /// This will release the locked ether.
70 | function confirmReceived()
71 | onlyBuyer
72 | inState(State.Locked)
73 | {
74 | itemReceived();
75 | // It is important to change the state first because
76 | // otherwise, the contracts called using `send` below
77 | // can call in again here.
78 | state = State.Inactive;
79 | // This actually allows both the buyer and the seller to
80 | // block the refund.
81 | if (!buyer.send(value) || !seller.send(this.balance))
82 | throw;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/Sample Code/Spike:
--------------------------------------------------------------------------------
1 | // A simple class
2 | // http://spike.sourceforge.net/
3 |
4 | #!/usr/bin/env spike-1
5 |
6 | class Point {
7 | var x, y;
8 |
9 | // initializing
10 | init(newX, newY) {
11 | x = newX;
12 | y = newY;
13 | }
14 |
15 | // accessing
16 | x { return x; }
17 | y { return y; }
18 | x = newX { x = newX; }
19 | y = newY { y = newY; }
20 |
21 | self x: newX y: newY {
22 | x = newX;
23 | y = newY;
24 | return self;
25 | }
26 |
27 | // arithmetic
28 | self + delta {
29 | return self.class
30 | x: x + delta.x
31 | y: y + delta.y;
32 | }
33 | self * scale {
34 | return self.class
35 | x: scale * x
36 | y: scale * y;
37 | }
38 | -self {
39 | return self.class
40 | x: -x
41 | y: -y;
42 | }
43 | self + 1 {
44 | return self.class
45 | x: x + 1
46 | y: y + 1;
47 | }
48 | self - 1 {
49 | return self.class
50 | x: x - 1
51 | y: y - 1;
52 | }
53 |
54 | // printing
55 | print() {
56 | stdout.printf("(%d, %d)\n", x, y);
57 | }
58 |
59 | } meta {
60 |
61 | self x: xValue y: yValue {
62 | return self.new() x: xValue y: yValue;
63 | }
64 | }
65 |
66 |
67 | main(argv) {
68 | var a, b, c;
69 |
70 | a = (Point) x: 4 y: 2;
71 | b = (Point) x: 22 y: 44;
72 |
73 | stdout.printf("a is "); a.print();
74 | stdout.printf("b is "); b.print();
75 | c = a + b;
76 | stdout.printf("c is "); c.print();
77 | return 0;
78 | }
79 |
--------------------------------------------------------------------------------
/Sample Code/Swift:
--------------------------------------------------------------------------------
1 | // Dynamic Type Expression
2 |
3 | class SomeBaseClass {
4 | class func printClassName() {
5 | print("SomeBaseClass")
6 | }
7 | }
8 |
9 | class SomeSubClass: SomeBaseClass {
10 | override class func printClassName() {
11 | print("SomeSubClass")
12 | }
13 | }
14 |
15 | let someInstance: SomeBaseClass = SomeSubClass()
16 | // someInstance has a static type of SomeBaseClass at compile time, and
17 | // it has a dynamic type of SomeSubClass at runtime
18 | type(of: someInstance).printClassName()
19 | // Prints "SomeSubClass"
20 |
--------------------------------------------------------------------------------
/Sample Code/TCL:
--------------------------------------------------------------------------------
1 | # Sort script
2 | # http://wiki.tcl.tk/460
3 |
4 | proc sort {args} {
5 |
6 | ### Parse the arguments
7 | set idx [lsearch -exact $args --]
8 | if {$idx >= 0} {
9 | set files [lrange $args [expr {$idx+1}] end]
10 | set opts [lrange $args 0 [expr {$idx-1}]]
11 | } else {
12 | # We need to guess which are files and which are options
13 | set files [list]
14 | set opts [list]
15 | foreach arg $args {
16 | incr idx
17 | if {[file exists $arg]} {
18 | set files [lrange $args $idx end]
19 | break
20 | } else {
21 | lappend opts $arg
22 | }
23 | }
24 | }
25 |
26 | ### Read the files
27 | set lines [list]
28 | if {[llength $files] == 0} {
29 | # Read from stdin
30 | while {[gets stdin line] >= 0} {lappend lines $line}
31 | } else {
32 | foreach file $files {
33 | if {[string equal $file "-"]} {
34 | set f stdin
35 | set close 0
36 | } else {
37 | set f [open $file r]
38 | set close 1
39 | }
40 | while {[gets $f line] >= 0} {lappend lines $line}
41 | if {$close} {close $f}
42 | }
43 | }
44 |
45 | ### Sort the lines in-place (need 8.3.0 or later for efficiency)
46 | set lines [eval [list lsort] $opts \
47 | [lrange [list $lines [set lines {}]] 0 0]]
48 |
49 | ### Write the sorted lines out to stdout
50 | foreach line $lines {
51 | puts stdout $line
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Sample Code/Thrift:
--------------------------------------------------------------------------------
1 | // http://thrift-tutorial.readthedocs.io/en/latest/usage-example.html
2 |
3 | include "shared.thrift"
4 |
5 | namespace cpp tutorial
6 | namespace d tutorial
7 | namespace java tutorial
8 | namespace php tutorial
9 | namespace perl tutorial
10 |
11 | /**
12 | * Thrift also lets you define constants for use across languages. Complex
13 | * types and structs are specified using JSON notation.
14 | */
15 | const i32 INT32CONSTANT = 9853
16 | const map MAPCONSTANT = {'hello':'world', 'goodnight':'moon'}
17 |
18 | /**
19 | * You can define enums, which are just 32 bit integers. Values are optional
20 | * and start at 1 if not supplied, C style again.
21 | */
22 | enum Operation {
23 | ADD = 1,
24 | SUBTRACT = 2,
25 | MULTIPLY = 3,
26 | DIVIDE = 4
27 | }
28 |
29 | /**
30 | * Structs are the basic complex data structures. They are comprised of fields
31 | * which each have an integer identifier, a type, a symbolic name, and an
32 | * optional default value.
33 | *
34 | * Fields can be declared "optional", which ensures they will not be included
35 | * in the serialized output if they aren't set. Note that this requires some
36 | * manual management in some languages.
37 | */
38 | struct Work {
39 | 1: i32 num1 = 0,
40 | 2: i32 num2,
41 | 3: Operation op,
42 | 4: optional string comment,
43 | }
44 |
45 | /**
46 | * Structs can also be exceptions, if they are nasty.
47 | */
48 | exception InvalidOperation {
49 | 1: i32 what,
50 | 2: string why
51 | }
52 |
53 | /**
54 | * Ahh, now onto the cool part, defining a service. Services just need a name
55 | * and can optionally inherit from another service using the extends keyword.
56 | */
57 | service Calculator extends shared.SharedService {
58 |
59 | /**
60 | * A method definition looks like C code. It has a return type, arguments,
61 | * and optionally a list of exceptions that it may throw. Note that argument
62 | * lists and exception lists are specified using the exact same syntax as
63 | * field lists in struct or exception definitions.
64 | */
65 |
66 | void ping(),
67 |
68 | i32 add(1:i32 num1, 2:i32 num2),
69 |
70 | i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch),
71 |
72 | /**
73 | * This method has a oneway modifier. That means the client only makes
74 | * a request and does not listen for any response at all. Oneway methods
75 | * must be void.
76 | */
77 | oneway void zip()
78 | }
79 |
--------------------------------------------------------------------------------
/Sample Code/TypeScript:
--------------------------------------------------------------------------------
1 | // TypeScript class example
2 | // https://www.typescriptlang.org/docs/handbook/classes.html
3 |
4 | class Animal {
5 | name: string;
6 | constructor(theName: string) { this.name = theName; }
7 | move(distanceInMeters: number = 0) {
8 | console.log(`${this.name} moved ${distanceInMeters}m.`);
9 | }
10 | }
11 |
12 | class Snake extends Animal {
13 | constructor(name: string) { super(name); }
14 | move(distanceInMeters = 5) {
15 | console.log("Slithering...");
16 | super.move(distanceInMeters);
17 | }
18 | }
19 |
20 | class Horse extends Animal {
21 | constructor(name: string) { super(name); }
22 | move(distanceInMeters = 45) {
23 | console.log("Galloping...");
24 | super.move(distanceInMeters);
25 | }
26 | }
27 |
28 | let sam = new Snake("Sammy the Python");
29 | let tom: Animal = new Horse("Tommy the Palomino");
30 |
31 | sam.move();
32 | tom.move(34);
33 |
--------------------------------------------------------------------------------
/Sample Code/VB.NET:
--------------------------------------------------------------------------------
1 | Module loops
2 | Sub Main()
3 | ' local variable definition
4 | Dim i, j As Integer
5 | For i = 2 To 100
6 | For j = 2 To i
7 | ' if factor found, not prime
8 | If ((i Mod j) = 0) Then
9 | Exit For
10 | End If
11 | Next j
12 | If (j > (i \ j)) Then
13 | Console.WriteLine("{0} is prime", i)
14 | End If
15 | Next i
16 | Console.ReadLine()
17 | End Sub
18 | End Module
19 |
--------------------------------------------------------------------------------
/Sample Code/VBScript:
--------------------------------------------------------------------------------
1 | ' Sort three Numbers
2 | ' http://courses.washington.edu/css341/zander/Code/sortThreeNumsWithSubs.vbs
3 |
4 | Option Explicit
5 |
6 | dim num1, num2, num3 ' used for input
7 | dim largeNum ' variable for largest number
8 | dim middleNum ' variable for second largest number
9 | dim smallNum ' variable for smallest number
10 |
11 | num1 = InputBox("Please enter the first number")
12 | num2 = InputBox("Please enter the second number")
13 | num3 = InputBox("Please enter the third number")
14 |
15 | ' check to make sure all input are "numeric" - integer/float/double
16 | if IsNumeric(num1) and IsNumeric(num2) and IsNumeric(num3) then
17 | MsgBox "You have entered: " & num1 & " " & num2 & " " _
18 | & num3, vbOKOnly, "Entered Values"
19 |
20 | largeNum = CDbl(num1)
21 | middleNum = CDbl(num2)
22 | smallNum = CDbl(num3)
23 |
24 | call compareAndSwap(largeNum, middleNum)
25 | call compareAndSwap(largeNum, smallNum)
26 | call compareAndSwap(middleNum, smallNum)
27 |
28 | MsgBox "The numbers sorted: " & smallNum & " " & middleNum & " " _
29 | & largeNum, vbOKOnly, "Sorted Numbers"
30 | else
31 | MsgBox "You must enter three numbers! Try Again", vbOKOnly, _
32 | "Invalid Input"
33 | end if
34 |
35 | '----------------------------------------------------------------------
36 | ' compareAndSwap
37 | ' Compare num1 to num2 and swap if they are out of order.
38 | ' Result is that at the end of the routine, num1 is always less than num2.
39 | sub compareAndSwap(num1, num2)
40 | dim temp
41 | if num1 < num2 then
42 | temp = num1
43 | num1 = num2
44 | num2 = temp
45 | end if
46 | end sub
47 |
--------------------------------------------------------------------------------
/Sample Code/VHDL:
--------------------------------------------------------------------------------
1 | -- Using Protected Types
2 | -- https://www.aldec.com/en/support/resources/documentation/articles/1179/print_page
3 |
4 | shared variable my_flag : flag_type;
5 |
6 | -- architecture statement part:
7 | prc1: process
8 |
9 | begin
10 | report "PRC1: Process started...";
11 |
12 | while my_flag.inactive loop -- reference point 1 (iteration 21)
13 | wait for 1 ns; -- (simulation time 20 ns)
14 | end loop;
15 |
16 | report "PRC1: Flag activation detected!";
17 |
18 | while my_flag.active loop
19 | wait for 1 ns;
20 | end loop;
21 |
22 | report "PRC1: Flag deactivation detected! Suspending...";
23 | wait;
24 | end process;
25 |
26 |
27 | prc2: process
28 |
29 | begin
30 | report "PRC2: Process started...";
31 | wait for 20 ns;
32 | report "PRC2: Setting the flag..."; -- reference point 1
33 |
34 | my_flag.set; -- (simulation time 20 ns)
35 | wait for 20 ns;
36 | wait for 0 ns; -- additional delta delay!
37 | report "PRC2: Resetting the flag...";
38 |
39 | my_flag.reset; -- (simulation time 40 ns, delta cycle 1)
40 | report "PRC2: Suspending...";
41 | wait;
42 | end process;
43 |
--------------------------------------------------------------------------------
/Sample Code/Vala:
--------------------------------------------------------------------------------
1 | // Async method to run a slow calculation in a background thread.
2 | // https://wiki.gnome.org/Projects/Vala/AsyncSamples
3 |
4 | async double do_calc_in_bg(double val) throws ThreadError {
5 | SourceFunc callback = do_calc_in_bg.callback;
6 | double[] output = new double[1];
7 |
8 | // Hold reference to closure to keep it from being freed whilst
9 | // thread is active.
10 | ThreadFunc run = () => {
11 | // Perform a dummy slow calculation.
12 | // (Insert real-life time-consuming algorithm here.)
13 | double result = 0;
14 | for (int a = 0; a<10000000; a++)
15 | result += val * a;
16 |
17 | // Pass back result and schedule callback
18 | output[0] = result;
19 | Idle.add((owned) callback);
20 | return null;
21 | };
22 | Thread.create(run, false);
23 |
24 | // Wait for background thread to schedule our callback
25 | yield;
26 | return output[0];
27 | }
28 |
29 | void main(string[] args) {
30 | var loop = new MainLoop();
31 | do_calc_in_bg.begin(0.001, (obj, res) => {
32 | try {
33 | double result = do_calc_in_bg.end(res);
34 | stderr.printf(@"Result: $result\n");
35 | } catch (ThreadError e) {
36 | string msg = e.message;
37 | stderr.printf(@"Thread error: $msg\n");
38 | }
39 | loop.quit();
40 | });
41 | loop.run();
42 | }
43 |
--------------------------------------------------------------------------------
/Sample Code/Verilog:
--------------------------------------------------------------------------------
1 | // Single Port RAM Synchronous Read/Write
2 | // http://www.asic-world.com/examples/verilog/ram_sp_sr_sw.html
3 |
4 | //-----------------------------------------------------
5 | // Design Name : ram_sp_sr_sw
6 | // File Name : ram_sp_sr_sw.v
7 | // Function : Synchronous read write RAM
8 | // Coder : Deepak Kumar Tala
9 | //-----------------------------------------------------
10 | module ram_sp_sr_sw (
11 | clk , // Clock Input
12 | address , // Address Input
13 | data , // Data bi-directional
14 | cs , // Chip Select
15 | we , // Write Enable/Read Enable
16 | oe // Output Enable
17 | );
18 |
19 | parameter DATA_WIDTH = 8 ;
20 | parameter ADDR_WIDTH = 8 ;
21 | parameter RAM_DEPTH = 1 << ADDR_WIDTH;
22 |
23 | //--------------Input Ports-----------------------
24 | input clk ;
25 | input [ADDR_WIDTH-1:0] address ;
26 | input cs ;
27 | input we ;
28 | input oe ;
29 |
30 | //--------------Inout Ports-----------------------
31 | inout [DATA_WIDTH-1:0] data ;
32 |
33 | //--------------Internal variables----------------
34 | reg [DATA_WIDTH-1:0] data_out ;
35 | reg [DATA_WIDTH-1:0] mem [0:RAM_DEPTH-1];
36 | reg oe_r;
37 |
38 | //--------------Code Starts Here------------------
39 |
40 | // Tri-State Buffer control
41 | // output : When we = 0, oe = 1, cs = 1
42 | assign data = (cs && oe && !we) ? data_out : 8'bz;
43 |
44 | // Memory Write Block
45 | // Write Operation : When we = 1, cs = 1
46 | always @ (posedge clk)
47 | begin : MEM_WRITE
48 | if ( cs && we ) begin
49 | mem[address] = data;
50 | end
51 | end
52 |
53 | // Memory Read Block
54 | // Read Operation : When we = 0, oe = 1, cs = 1
55 | always @ (posedge clk)
56 | begin : MEM_READ
57 | if (cs && !we && oe) begin
58 | data_out = mem[address];
59 | oe_r = 1;
60 | end else begin
61 | oe_r = 0;
62 | end
63 | end
64 |
65 | endmodule // End of Module ram_sp_sr_sw
66 |
--------------------------------------------------------------------------------
/Sample Code/Visual Studio Solution:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio 14
3 | VisualStudioVersion = 14.0.25123.0
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Proj", "Proj\Proj.vbproj", "{BFBC8474-6F6D-4303-9ED1-737CB13F926C}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|Any CPU = Debug|Any CPU
10 | Release|Any CPU = Release|Any CPU
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {BFBC8474-6F6D-4303-9ED1-737CB13F926C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14 | {BFBC8474-6F6D-4303-9ED1-737CB13F926C}.Debug|Any CPU.Build.0 = Debug|Any CPU
15 | {BFBC8474-6F6D-4303-9ED1-737CB13F926C}.Release|Any CPU.ActiveCfg = Release|Any CPU
16 | {BFBC8474-6F6D-4303-9ED1-737CB13F926C}.Release|Any CPU.Build.0 = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(SolutionProperties) = preSolution
19 | HideSolutionNode = FALSE
20 | EndGlobalSection
21 | EndGlobal
22 |
--------------------------------------------------------------------------------
/Sample Code/Volt:
--------------------------------------------------------------------------------
1 | // Getting Input
2 | // http://www.volt-lang.org/doc/tvpl/c3-steps.html
3 |
4 | import watt.io;
5 | import watt.conv;
6 |
7 | fn main() i32
8 | {
9 | writeln("Enter a number.");
10 | n := toInt(readln());
11 | writeln("Your number doubled is");
12 | writeln(n * 2);
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/Sample Code/X10:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the X10 project (http://x10-lang.org).
3 | *
4 | * This file is licensed to You under the Eclipse Public License (EPL);
5 | * You may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | * http://www.opensource.org/licenses/eclipse-1.0.php
8 | *
9 | * (C) Copyright IBM Corporation 2006-2014.
10 | */
11 |
12 | public class Histogram {
13 | public static def compute(data:Rail[Int], numBins:Int) {
14 | val bins = new Rail[Int](numBins);
15 | finish for (i in data.range) async {
16 | val b = data(i) % numBins;
17 | atomic bins(b)++;
18 | }
19 | return bins;
20 | }
21 |
22 | public static def run(N:Int, S:Int):Boolean {
23 | val a = new Rail[Int](N, (i:long)=> i as int);
24 | val b = compute(a, S);
25 | val v = b(0);
26 | var ok:Boolean = true;
27 | for (x in b.range) ok &= (b(x)==v);
28 | return ok;
29 | }
30 |
31 | public static def main(args:Rail[String]) {
32 | if (args.size != 2L) {
33 | Console.OUT.println("Usage: Histogram SizeOfArray NumberOfBins");
34 | return;
35 | }
36 | val N = Int.parse(args(0));
37 | val S = Int.parse(args(1));
38 | val ok = run(N,S);
39 | if (ok) {
40 | Console.OUT.println("Test ok.");
41 | } else {
42 | Console.OUT.println("Test failed.");
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Sample Code/XC:
--------------------------------------------------------------------------------
1 | /* Case Study: UART
2 | * The program below defines a UART transmitter
3 | */
4 | #include
5 |
6 | #define BIT_RATE 115200
7 | #define BIT_TIME 100000000 / BIT_TATE
8 |
9 | out port TXD = XS1_PORT_1A
10 | out port RXD = XS1_PORT_1B
11 |
12 | void transmitter(out port TXD) {
13 | unsigned byte, time;
14 | timer t;
15 |
16 | while (1) {
17 | // get next byte to transmit
18 | byte = getByte();
19 | t :> time;
20 |
21 | // output start bit
22 | TXD <: 0;
23 | time += BIT_TIME;
24 | t when timerafter(time) :> void;
25 |
26 | // output data bits
27 | for (int i=0; 1<8; i++) {
28 | TXD <: >> byte;
29 | time =+ BIT_TIME;
30 | t when timerafter(time) :> void;
31 | }
32 |
33 | // output stop bit
34 | TXD <: 1;
35 | time += BIT_TIME;
36 | t when timerafter(time) :> void;
37 | }
38 | }
39 |
40 | /* Case Study: Ethernet MII
41 | * The function below receives a single error free frame and outputs it to
42 | * another thread. For simplicity, the error signal and CRC are ignored
43 | */
44 | #define MORE 0
45 | #define DONE 1
46 |
47 | void receiveFrame(in buffered port:32 RXD, in port RXDV, streaming chanend c) {
48 | int notDone = 1;
49 | int data, tail;
50 |
51 | // wait for start of frame
52 | RXD when pinseq(0xD) :> void;
53 |
54 | // receive frame data/crc
55 | do {
56 | select {
57 | case RXD :> data :
58 | // input next 32 bits of data
59 | c <: MORE;
60 | c <: data;
61 | case RXDV when pinseq(0) :> notDone :
62 | // input any bits remaining in port
63 | tail = endin(RXD);
64 | for (int byte=tail>>>3; byte > 0; byte -=4) {
65 | RXD :> data;
66 | c <: MORE;
67 | c <: data;
68 | }
69 | c <: DONE;
70 | c <: tail >> 3;
71 | break;
72 | }
73 |
74 | } while (notDone);
75 | }
76 |
--------------------------------------------------------------------------------
/Sample Code/XML:
--------------------------------------------------------------------------------
1 |
2 |
3 | Jani
4 | Tove
5 | Remember me this weekend
6 |
7 |
--------------------------------------------------------------------------------
/Sample Code/Xtend:
--------------------------------------------------------------------------------
1 | class HelloWorld {
2 | def static void main(String[] args) {
3 | println("Hello World")
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/Syntax/ANTLR.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/Syntax/ChucK.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/Syntax/Cocoa.xshd:
--------------------------------------------------------------------------------
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 | COMPILER
48 | TOKENNAMES
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/Syntax/Cool.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | class
60 | inherits
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 |
90 |
91 |
--------------------------------------------------------------------------------
/Syntax/Erlang.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/Syntax/HTML.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | <script>
50 | </script>
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 |
90 |
91 |
--------------------------------------------------------------------------------
/Syntax/ILYC.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/Syntax/INI.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
--------------------------------------------------------------------------------
/Syntax/Io.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 | &<>~$!@%^*()-+=|\#/{}[]:;"' , .?
101 |
102 |
103 | #{
104 | }
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/Syntax/JSON.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
--------------------------------------------------------------------------------
/Syntax/ParaSail.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | void
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/Syntax/Pike.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/Syntax/PureScript.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
90 |
91 |
92 |
93 |
94 |
95 | &<>~!@%^*()-+=|\#/{}[]:;"' , .?
96 |
97 |
98 | {-
99 | -}
100 |
101 |
102 |
103 |
104 |
--------------------------------------------------------------------------------
/Syntax/Registry.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
--------------------------------------------------------------------------------
/Syntax/Rexx.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 | &<>~!@%^*()-+=|\#/{}[]:;"' , .?
112 |
113 |
114 | /*
115 | */
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/Syntax/Spike.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | class
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/Syntax/Thrift.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | ~!%^*()-+=|\#/{}[];"'<> , .?
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/Syntax/TypeScript.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | class
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
--------------------------------------------------------------------------------
/Syntax/VS Solution.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
--------------------------------------------------------------------------------
/Syntax/Volt.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/Syntax/XC.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | #include
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/Syntax/XML.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | <![CDATA[
50 | ]]>
51 |
52 |
53 |
54 | <!DOCTYPE
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 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/Syntax/Xtend.xshd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | class
69 | @
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------