Polski
huginn - programming language with no quirks, so simple every child can master it.
Fork me on GitHub git clone https://codestation.org/repo/huginn.git
git clone https://github.com/AmokHuginnsson/huginn.git
git clone https://bitbucket.org/huginn/huginn.git
  1. Syntax
  2. Keywords
  3. Types

    Huginn provides several built-in scalar and collection types, as well as user defined compound types.

    integer real string number character boolean list deque dict order lookup set
  4. Built-ins
  5. Core library classes
  6. Packages

try, throw, catch statements:

Editor (vim) - try-throw-catch.hgn (Try it online!) [+line no]
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
#! /bin/sh
exec huginn -E "${0}" "${@}"
#! huginn

import Mathematics as math;
import Algorithms as algo;

solve( a, b, c ) {
	Δ = b ^ $2 - $4 * a * c;
	if ( Δ < $0 ) {
		throw ArithmeticException( "Δ is negative." );
	}
	x1 = ( -b - math.square_root( Δ ) ) / ( $2 * a );
	x2 = ( -b + math.square_root( Δ ) ) / ( $2 * a );
	return ( [ x1, x2 ] );
}

main( argv_ ) {
	argc = size( argv_ ) - 1;
	if ( argc != 3 ) {
		print( "Bad number of arguments, expected 3, got: {}\n".format( argc ) );
		return ( 1 );
	}
	try {
		a = number( argv_[1] );
		b = number( argv_[2] );
		c = number( argv_[3] );
		res = solve( a, b, c );
		res = algo.sorted( res );
		print( "Equation solved for a = {}, b = {}, c = {}\n".format( a, b, c ) );
		if ( res[0] != res[1] ) {
			print( "result: x1 = {}, x2 = {}\n".format( res[0], res[1] ) );
		} else {
			print( "result: x0 = {}\n".format( res[0] ) );
		}
	} catch ( ConversionException e ) {
		print( "A {} caught: {}\n".format( string( type( e ) ), e.message() ) );
		return ( 2 );
	} catch ( ArithmeticException e ) {
		print( "An {} caught: {}\n".format( string( type( e ) ), e.message() ) );
		return ( 3 );
	}
	return ( 0 );
}

Program output:

Terminal - shell session [–line no]
[amok@vegeta](2/1)~/$ ./try-throw-catch.hgn -1 2 3
Equation solved for a = -1, b = 2, c = 3
result: x1 = -1, x2 = 3
[amok@vegeta](2/1)~/$ ./try-throw-catch.hgn 1 a 3
A ConversionException caught: ./try-throw-catch.hgn:26:13: Not a number.
Exit 2
[amok@vegeta](2/1)~/$ ./try-throw-catch.hgn 1 2 3
An ArithmeticException caught: ./try-throw-catch.hgn:11:3: Δ is negative.
Exit 3
[amok@vegeta](2/1)~/$