Skip to content

Latest commit

 

History

History
263 lines (214 loc) · 4.1 KB

babix.org

File metadata and controls

263 lines (214 loc) · 4.1 KB

Babel Evaluation Test

Execute code of arbitrary languages!

Use C-c C-c on any #+begin_src or #+end_src line.

Anyone wanna see something cool?

Awk

Hello world

BEGIN { print "Hello from Awk."; }

Bash

Hello world

echo "Hello from Bash."

C

Hello world

int main() {
   printf("Hello from C.");
   return 0;
}

C++

Hello world

#include<iostream>
using namespace std;

int main() {
  cout << "Hello World!";
  return 0;
}

C#

Hello world

using System;

class Program {
    static void Main(string[] args) {
        Console.WriteLine("Hello from C#.");
    }
}

Example of out parameters

using System;

class OutExample {

    static void Adder(int a, int b, out int result) {
        result = a + b;
    }

    static void Main() {
        var a = 5;
        var b = 10;
        int result;
        Adder(a, b, out result);
        Console.WriteLine($"r = {result}");
    }
}

D

Hello world

import std.stdio;

void main()
{
    writeln("Hello from D!");
}

Elisp

Hello world

(message "Hello from Elisp.")

F#

Hello world

printfn "Hello from F#."

Fortran

Hello world

program hello
  print *, "Hello from Fortran."
end program

Go

Hello world

fmt.Println("Hello from Go.")

Javascript

Hello world

console.log("Hello from Javascript.");

Lua

Hello world

print("Hello from Lua.")

NASM

These examples are all for linux 64 bit.

Hello world

global main

extern write, exit

section .rodata
  msg: db "Hello from NASM.", 13
  msglen: equ $ - msg

section .text

main:
  mov rdi, 1        ;   STDOUT_FILENO
  mov rsi, msg      ;   "Hello from NASM.",
  mov rdx, msglen   ;   sizeof("Hello from NASM.")
  call write

  mov rdi, 0        ;   EXIT_SUCCESS
  call exit

Nested loops

global main

extern putchar

section .text

putstar:
        mov rdi, '*'
        call putchar
        ret
putbreak:
        mov rdi, 10
        call putchar
        ret
main:
        mov rbx, 1              ; outer loop counter
outerloop:
        mov rcx, rbx            ; inner loop counter
innerloop:
        push rcx
        push rbx

        call putstar

        pop rbx
        pop rcx

        dec rcx
        jrcxz innerdone
        jmp innerloop

innerdone:
        call putbreak

        inc rbx
        cmp rbx, 6
        jne outerloop

        ret

OCaml

Hello world

print_string "Hello from OCaml.\n"

Perl

Hello world

print("Hello from Perl.");

Python

Hello world

print("Hello from Python.")

R

Hello world

print("Hello from R.")

Ruby

Hello world

puts "Hello from Ruby."

Rust

Hello world

println!("Hello from Rust.");

Scheme

Hello world

(begin (display "Hello from Scheme.")
       (newline))

Post processors

F#

(with-temp-buffer
  (insert out)
  (beginning-of-buffer)
  (search-forward "val it :")
  (beginning-of-line)
  (call-interactively 'set-mark-command)
  (end-of-buffer)
  (call-interactively 'kill-region)
  (buffer-string))

R

(s-chop-prefix "[1] " out)