# HiliteJs Demo: Programming Languages

## Go

    package main

    import "fmt"

    func main() {
        ch := make(chan float64)
        ch <- 1.0e10    // magic number
        x, ok := <- ch
        defer fmt.Println(`exitting now\`)
        go println(len("hello world!"))
        return
    }

## Dart

    library app;
    import 'dart:html';

    part 'app2.dart';

    /**
     * Class description and [link](http://dartlang.org/).
     */
    @Awesome('it works!')
    class SomeClass<S extends Iterable> extends BaseClass<S> implements Comparable {
      factory SomeClass(num param);
      SomeClass._internal(int q) : super() {
        assert(q != 1);
        double z = 0.0;
      }

      /// **Sum** function
      int sum(int a, int b) => a + b;

      ElementList els() => querySelectorAll('.dart');
    }

    String str = ' (${'parameter' + 'zxc'})';
    String str = " (${true ? 2 + 2 / 2 : null})";
    String str = " ($variable)";
    String str = r'\nraw\';
    String str = r"\nraw\";
    var str = '''
    Something ${2+3}
    ''';
    var str = r"""
    Something ${2+3}
    """;

    checkVersion() async {
      var version = await lookUpVersion();
    }

## Rust

    #[derive(Debug)]
    pub enum State {
        Start,
        Transient,
        Closed,
    }

    impl From<&'a str> for State {
        fn from(s: &'a str) -> Self {
            match s {
                "start" => State::Start,
                "closed" => State::Closed,
                _ => unreachable!(),
            }
        }
    }

## Python

    @requires_authorization
    def somefunc(param1='', param2=0):
        r'''A docstring'''
        if param1 > param2: # interesting
            print 'Gre\'ater'
        return (param2 - param1 + 1 + 0b10l) or None

    class SomeClass:
        pass

    >>> message = '''interpreter
    ... prompt'''

## Lua

    --[[
    Simple signal/slot implementation
    ]]
    local signal_mt = {
        __index = {
            register = table.insert
        }
    }
    function signal_mt.__index:emit(... --[[ Comment in params ]])
        for _, slot in ipairs(self) do
            slot(self, ...)
        end
    end
    local function create_signal()
        return setmetatable({}, signal_mt)
    end

    -- Signal test
    local signal = create_signal()
    signal:register(function(signal, ...)
        print(...)
    end)
    signal:emit('Answer to Life, the Universe, and Everything:', 42)

    --[==[ [=[ [[
    Nested ]]
    multi-line ]=]
    comment ]==]
    [==[ Nested
    [=[ multi-line
    [[ string
    ]] ]=] ]==]

## Tcl

    package json

    source helper.tcl
    # randomness verified by a die throw
    set ::rand 4

    proc give::recursive::count {base p} { ; # 2 mandatory params
        while {$p > 0} {
            set result [expr $result * $base]; incr p -1
        }
        return $result
    }

    set a 'a'; set b "bcdef"; set lst [list "item"]
    puts [llength $a$b]

    set ::my::tid($id) $::my::tid(def)
    lappend lst $arr($idx) $::my::arr($idx) $ar(key)
    lreplace ::my::tid($id) 4 4
    puts $::rand ${::rand} ${::AWESOME::component::variable}

    puts "$x + $y is\t [expr $x + $y]"

    proc isprime x {
        expr {$x>1 && ![regexp {^(oo+?)\1+$} [string repeat o $x]]}
    }

## Makefile

    # Makefile

    BUILDDIR      = _build
    EXTRAS       ?= $(BUILDDIR)/extras

    .PHONY: main clean

    main:
    	@echo "Building main facility..."
    	build_main $(BUILDDIR)

    clean:
    	rm -rf $(BUILDDIR)/*

## Bison

    %%

    result:
      list  { std::cout << $1 << '\n'; }
    ;

    %nterm > list;

    list:
      %empty     { /* Generates an empty string list */ }
    | list item  { $$ = $1; $$.push_back ($2); }
    ;

## CMake

    cmake_minimum_required(VERSION 2.8.8)
    project(cmake_example)

    # Show message on Linux platform
    if (${CMAKE_SYSTEM_NAME} MATCHES Linux)
        message("Good choice, bro!")
    endif()

    # Tell CMake to run moc when necessary:
    set(CMAKE_AUTOMOC ON)
    # As moc files are generated in the binary dir,
    # tell CMake to always look for includes there:
    set(CMAKE_INCLUDE_CURRENT_DIR ON)

    # Widgets finds its own dependencies.
    find_package(Qt5Widgets REQUIRED)

    add_executable(myproject main.cpp mainwindow.cpp)
    qt5_use_modules(myproject Widgets)

## C / C++

    #include <iostream>

    int main(int argc, char *argv[]) {

      /* An annoying "Hello World" example */
      for (auto i = 0; i < 0xFFFF; i++)
        cout << "Hello, World!" << endl;

      char c = '\n';
      unordered_map <string, vector<string> > m;
      m["key"] = "\\\\"; // this is an error

      return -2e3 + 12l;
    }

## Vala

    using DBus;

    namespace Test {
      class Foo : Object {
        public signal void some_event ();   // definition of the signal
        public void method () {
          some_event ();                    // emitting the signal (callbacks get invoked)
        }
      }
    }

    /* defining a class */
    class Track : GLib.Object, Test.Foo {              /* subclassing 'GLib.Object' */
      public double mass;                  /* a public field */
      public double name { get; set; }     /* a public property */
      private bool terminated = false;     /* a private field */
      public void terminate() {            /* a public method */
        terminated = true;
      }
    }

    const ALL_UPPER_CASE = "you should follow this convention";

    var t = new Track();      // same as: Track t = new Track();
    var s = "hello";          // same as: string s = "hello";
    var l = new List<int>();       // same as: List<int> l = new List<int>();
    var i = 10;               // same as: int i = 10;

    #if (ololo)
    Regex regex = /foo/;
    #endif

    /*
     * Entry point can be outside class
     */
    void main () {
      var long_string = """
        Example of "verbatim string".
        Same as in @"string" in C#
      """
      var foo = new Foo ();
      foo.some_event.connect (callback_a);      // connecting the callback functions
      foo.some_event.connect (callback_b);
      foo.method ();
    }

## Ruby

    # The Greeter class
    class Greeter
      def initialize(name)
        @name = name.capitalize
      end

      def salute
        puts "Hello #{@name}!"
      end
    end

    g = Greeter.new("world")
    g.salute

## Objective-C

        // First program example

        #import

        int main (int argc, const char * argv[])
        {
                NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
                NSLog (@"Hello, World!");
                [pool drain];
                return 0;
        }

## Swift

    import Foundation

    @objc class Person: Entity {
      var name: String!
      var age:  Int!

      init(name: String, age: Int) {
        /* /* ... */ */
      }

      // Return a descriptive string for this person
      func description(offset: Int = 0) -> String {
        return "\(name) is \(age + offset) years old"
      }
    }

## C#

    using System;

    #pragma warning disable 414, 3021

    /// <summary>Main task</summary>
    async Task<int, int> AccessTheWebAsync()
    {
        Console.WriteLine("Hello, World!");
        string urlContents = await getStringTask;
        return urlContents.Length;
    }