Nial

Nial
Nial
Paradigm(s) array
Appeared in 1981
Designed by Mike Jenkins
Developer Nial Systems Ltd
Stable release 6.3 (August 2006)
Typing discipline dynamic
Major implementations Q'Nial
Influenced by APL Lisp

Nial (from "Nested Interactive Array Language") is a high-level array programming language developed from about 1981 by Mike Jenkins of Queen's University, Kingston, Ontario, Canada.

Nial combines a functional programming notation for arrays based on Array Theory developed by Trenchard More with structured programming concepts for numeric, character and symbolic data.

It is most often used for prototyping and artificial intelligence.

In 1982, Jenkins formed a company Nial Systems Ltd to market the language and the Q'Nial implementation of Nial. As of 2006, the company website supports an Open Source project for the Q'Nial software with the binary and source available for download under the terms of an Artistic Licence.

Contents

Nial Concepts

Nial uses a generalized and expressive Array Theory in its Version 4, but sacrificed some of the generality of functional model, and modified the Array Theory in the Version 6. Only Version 6 is available now.

Nial defines all its datatypes as nested rectangular arrays. ints, booleans, chars etc. are considered as a solitary array or an array containing a single member. Arrays themselves can contain other arrays to form arbitrarily deep structures. Nial also provides Records. They are defined as non-homogenous array structure.

Functions in Nial are called Operations. From Nial manual: "An operation is a functional object that is given an argument array and returns a result array. The process of executing an operation by giving it an argument value is called an operation call or an operation application."

Application of Operations

Nial like other APL derived languages allow the unification of binary operators and operations. Thus the below notations have the same meaning. Note: sum is same as +

binary operation

2 + 3 
2 sum 3

in array notation

+ [2,3]
sum [2,3]

strand notation

+ 2 3
sum 2 3

grouped notation

+ (2 3)
sum (2 3)

Nial also uses transformers which are higher order functions. They use the argument operation to construct a new modified operation.

twice is transformer f (f f) 
twice rest [4, 5, 6, 7, 8] 
|6 7 8

Atlas

An atlas in Nial is an operation made up of an array of component operations. When an atlas is applied to a value, each element of the atlas is applied in turn to the value to provide an end result. This is used to provide point free (without-variables) style of definitions. It is also used by the transformers. In the below examples 'inner [+,*]' the list '[+,*]' is an atlas.

Examples

Creating Arrays

count 6
|1 2 3 4 5 6

Arrays can also be literal

Arr := [5, 6, 7, 8, 9]
|5 6 7 8 9

Shape gives the array dimensions and reshape can be used to reshape the dimensions.

shape Arr
|5
a := 2 3 reshape Arr
# reshape is a binary operation with two arguments. It can also be written in infix as
# a := reshape [[2,3], Arr]
|5 6 7
|8 9 5
b := 3 2 reshape Arr
|5 6
|7 8
|9 5
a inner[+,*] b
|130 113
|148 145

Computing Average

Definitions are of the form '<name> is <expression>'

average is / [sum, tally] 
average Arr
|7.

Computing Factorial

fact is recur [ 0 =, 1 first, pass, product, -1 +]
fact 4
|24

Reversing an array

rev is reshape [ shape, across [pass, pass, converse append ] ]
rev [1, 2, 3, 4]
|4 3 2 1

Generating Primes

Contrast with APL

primes is sublist [ each (2 = sum eachright (0 = mod) [pass,count]), pass ] rest count
primes 10
|2 3 5 7

Explanation

Checking the divisibility of A by B
is_divisible is 0 = mod [A,B]

Defining is_prime filter

is_prime is 2 = sum eachright is_divisible [pass,count]

Count generates an array [1..N] and pass is N (identity operation). eachright applies is_divisible(pass,element) in each element of count-generated array. Thus this transforms the count-generated array into an array where numbers that can divide N are replaced by '1' and others by '0'. Hence if the number N is prime, sum [transformed array] must be 2 (itself and 1).

Now all that remains is to generate another array using count N, and filter all that are not prime.

primes is sublist [each is_prime, pass] rest count

QuickSort

link joins together its argument arrays
sublist [A,B] returns a list of items of B chosen according to the list of booleans given in A, selecting those items of B where the corresponding item of A is true.
In a Fork [A,B,C] X the first A is a predicate, and if A(X) is true, then B(X) is returned else C(X) is returned.
Pass is an identity operation for arrays.

quicksort is fork [ >= [1 first,tally],
   pass,
   link [
       quicksort sublist [ < [pass, first], pass ],
       sublist [ match [pass,first],pass ],
       quicksort sublist [ > [pass,first], pass ]
   ]
]

Using it.

quicksort [5, 8, 7, 4, 3]
|3 4 5 7 8

External links


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • nial — (de «nidal»; Sal.) m. *Almiar. * * * nial. (De nidal). m. almiar (ǁ montón de paja). * * * ► mascul …   Enciclopedia Universal

  • nial — s. m. [Portugal: Trás os Montes] Ninho …   Dicionário da Língua Portuguesa

  • nial — (De nidal). m. almiar (ǁ montón de paja) …   Diccionario de la lengua española

  • nial — cer·e·mo·nial·ism; cer·e·mo·nial·ist; cer·e·mo·nial·ly; cer·e·mo·nial·ness; con·ge·nial; con·ge·nial·i·ty; con·ge·nial·ly; con·ge·nial·ness; en·nial; ge·nial·i·ty; ge·nial·ize; ge·nial·ly; ge·nial·ness; mat·ri·mo·nial; me·nial·ly; pe·ren·nial·ly; …   English syllables

  • Nial — This interesting name is of Irish, Scottish and English origin, and derives from a given name of Gaelic origin, Niall , thought to mean Champion . The personal name was carried to Ireland by the Scandinavians in the form of Njall , and then to… …   Surnames reference

  • NIAL — Nested Interactive Array Language ( > M.A. Jenkins et al., Programming Styles in NIAL , IEEE Software 1/86 ) …   Acronyms

  • NIAL — Nested Interactive Array Language ( > M.A. Jenkins et al., Programming Styles in NIAL , IEEE Software 1/86 ) …   Acronyms von A bis Z

  • nial —    significado: nido de cualquier naturaleza: ferres, xarricas, buitres... Especialmente era respetado en el monte, el nial d avispas (las avispas), por lo peligroso que resultaba para guajes, adultos, animales..., siempre disimulado como está… …   Etimologías léxico asturiano

  • Nial Fulton — Born Nial Fulton Enniskillen, County Fermanagh, Northern Ireland Nial Fulton is an Irish born, Australian film and …   Wikipedia

  • Nial class heavy fighter — Nial class First appearance And the Sky Full of Stars (airdate) In the Beginning (chronological) Affiliation Minbari Federation General characteristics Armaments 3 Light Neutron Fusion Cannons[1] …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”