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

The list is a collection type that is used to represent and operate on list of values. It supports basic subscript and range operators. It also supports efficient operations of addition and removal of its elements from its (right) end.

Methods
  • add( other ) - append all elements from other collection at the end of this list
  • append( other ) - append all elements from other collection at the end of this list
  • clear() - erase list's content, list becomes empty
  • equals( other ) - test if otherlist has the same content
  • hash() - calculate hash value for this list
  • insert( index, elem ) - insert given element at given index
  • less( other ) - test if this list comes lexicographically before otherlist
  • pop() - remove last element from the list, list shrinks by 1
  • push( elem ) - add new elem at the end of the list, list grows in size by 1
  • resize( size, elem ) - resize list to given size optionally filling new elements with copies of value elem
  • sort( [callable] ) - in-place sort this list, using callable to retrieve keys for element comparison
Editor (vim) - list.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
#! /bin/sh
exec huginn --no-argv -E "${0}" "${@}"
#! huginn

show_state( x, n ) {
	print( "type of {} list is {}\n".format( n, type( x ) ) );
	print( "size of {} list is {}\n".format( n, size( x ) ) );
	print( "content of {} list: [".format( n ) );
	next = false;
	for ( e : x ) {
		if ( next ) {
			print( ", " );
		}
		next = true;
		print( e );
	}
	print( "]\n" );
}

main() {
	l = list();
	show_state( l, "l" );
	l2 = list( 1, 2, 4 );
	show_state( l2, "l2" );
	l3 = [2, 3, 5, 7];
	print( "type of l3[1] element is {}\n".format( type( l3[1] ) ) );
	print( "value of l3[1] element is {}\n".format( l3[1] ) );
	show_state( l3, "l3" );
	l = l2;
	l.push( 8 );
	show_state( l[::-1], "l" );
	show_state( l2, "l2" );
	l3.pop();
	show_state( l3, "l3" );
	l.clear();
	show_state( l, "l" );
}

Program output:

Terminal - shell session [–line no]
[amok@vegeta](2/1)~/$ ./list.hgn
type of l list is list
size of l list is 0
content of l list: []
type of l2 list is list
size of l2 list is 3
content of l2 list: [1, 2, 4]
type of l3[1] element is integer
value of l3[1] element is 3
type of l3 list is list
size of l3 list is 4
content of l3 list: [2, 3, 5, 7]
type of l list is list
size of l list is 4
content of l list: [8, 4, 2, 1]
type of l2 list is list
size of l2 list is 4
content of l2 list: [1, 2, 4, 8]
type of l3 list is list
size of l3 list is 3
content of l3 list: [2, 3, 5]
type of l list is list
size of l list is 0
content of l list: []
[amok@vegeta](2/1)~/$