nial
DESCRIPTION
Nested Interactive Array Language Dennis Brown Northern Kentucky University CSC 507 – November 2005. NIAL. Origins of NIAL. Based on nested array theory developed by Dr. Trenchard More, Jr. Invented in 1981 by Michael Jenkins of Queen’s University in Kingston, Ontario - PowerPoint PPT PresentationTRANSCRIPT
NIAL
Nested Interactive Array Language
Dennis Brown
Northern Kentucky University
CSC 507 – November 2005
Origins of NIAL
• Based on nested array theory developed by Dr. Trenchard More, Jr.
• Invented in 1981 by Michael Jenkins of Queen’s University in Kingston, Ontario
• Influenced by APL and Lisp• NIAL is an acronym for Nested Interactive
Array Language, but is also a reference to Njal’s Saga (a Nordic legend)
APL vs. NIAL
• APL was invented in 1962
• Very efficient for some types of calculation, but required a special character set:
APL vs. NIAL (cont.)
• NIAL uses keywords instead of symbols, so no custom keyboard is required– For example, ρ (rho) in APL becomes “reshape” in
NIAL
• NIAL also adds control structures (from imperative languages) that APL did not have
• The original version of APL did not support nested arrays
NIAL Data Types
• Numbers– integers
– floating points– booleans (l, o, True, False)
• Characters– `X, `v, `3
• Lists– 3 `C 5 (strand notation)
– [3 `C 5]– [] (empty list)
• Strings– ‘abc’
– `a `b `c
• Phrases– “dog
– phrase ‘dog’
• Faults– ‘?conform’
Strings vs. Phrases
A string is a list:first ‘abc’ `a last ‘abc’ `c
A phrase is atomic:first “abc “abc last “abc “abc
Lists – Examples
• sum 2 3 4– 9
• sum [2 3 4]– [2 3 4]
• sum (2 3 4) (1 2 3)– 3 5 7
• each sum (2 3 4) (1 2 3)
– 9 6
• x y z := 5 6 7– assigns 5 to x, 6 to y,
7 to z
• [1 2 3] * 2– [2 4 6]
• [1 2 3] * [3 2 1]– [3 4 3]
• [1 2 3] * 3 2 1– [3 6 9] [2 4 6] [1 2 3]
Lisp vs. NIAL
• (car 1 2 3)1
• (cdr 1 2 3)(2 3)
• (cons 1 (2 3))(1 2 3)
• first 1 2 31
• rest 1 2 32 3
• hitch 1 (2 3)1 2 3
Tables
• A table is a multi-dimensional list• The reshape function can be used to create a table
with a specified number of rows and columns• 2 3 reshape 1 2 3 4 5 6 7 8
1 2 34 5 6
• 2 3 reshape 1 2 3 41 2 34 1 2
Tables – Continued
• x := 3 3 reshape count 91 2 34 5 67 8 9
• x | [2,] (row slice)7 8 9
• x | [,2] (col. slice)3 6 9
• x @ (1 2)6
• post 1 2 31
2
3
Functions
• Functions are defined using the syntax “is operation,” followed by the formal parameters, and then the function body enclosed in braces
• Functions are evaluated using right associativity
Examples:• factorial IS OPERATION x { * count x }• nthroot IS OPERATION x n { power x
( reciprocal n ) }
Transformers
• A transformer changes how functions are applied• “each” is a built-in transformer that applies a
function to each value of a list• each first (“abc “def) (3 7 8) (`z `x `q)
– “abc 3 `z
• New transformers can be created using IS TRANSFORMER
• Transformers were a novel feature in NIAL, and allow the language to support parallel architectures efficiently
Atlases
• An atlas is a list of functions that can be applied to a data item, producing a list of results
• [first, last, reverse] `a `b `c– [`a `c ‘cba’] brackets are used because ‘cba’ is a list!
• [+, -, *, /, quotient] 12 7– 19 5 84 1.71 1
Different Ways of Saying the Same Thing
• x := ‘aeiou’
• x := True• x := 3 + 4• x := 3 + 4• x gets 3 * 4 * 5• x @ (0 3)• x @ (0 3)
• x := `a `e `i `o `u
• x := l • x gets 3 plus 4• x gets plus 3 4• x := 3 times prod 4 5• [0 3] choose x• x | [0, 3]
IF Statements
• IF, ELSE, ELSEIF, and ENDIF are supported
• Comparison operators and boolean operations are available
IF (x >= 3.4) and (y < 7) THEN
out_of_range := True
ELSE
out_of_range := False
ENDIF
CASE Statements
• CASE statements allow selection based on a value (not necessarily an integer)
• An optional ELSE clause handles the default case• Each non-default case must end with END – there is no
fall-through like in C and Java
CASE n FROM1: value := ‘one’ END2: value := ‘two’ ENDELSE value := ‘unknown’
ENDCASE
Loops
• NIAL supports the three usual types of loops:– WHILE {condition} DO {expressions} ENDWHILE– REPEAT {expressions} UNTIL {condition}
ENDREPEAT– FOR {variable} WITH {range} DO {expressions}
ENDFOR
• The count function is useful with FOR loops– FOR i WITH count 10 DO write(i) ENDFOR
• It is better to use the EACH transformer, however• The EXIT statement can be used to force a loop to
terminate
Q’Nial Interpreter
• Q’Nial allows NIAL statements to be entered and interpreted dynamically
• Windows version is now available free from NIAL Systems (www.nial.com)
• C++ source code for Q’Nial is also available free of charge
The Future of NIAL
• NIAL has been used in academic research (particularly in AI) and at some insurance companies, but has declined in popularity since the 1980s
• Newer languages in its niche can do the same tasks just as well or better– APL version 2– J and its successors
• J is available for free; NIAL was very expensive until recently
• NIAL is not easy to integrate with native C libraries• Best use of NIAL is as a prototyping language
References
• Nial Systems Limitedhttp://www.nial.com
• Q’nial Research Projecthttp://www.qnial.net
• “A Quick Look at Nial,” Journal of J/APLhttp://www.apl.demon.co.uk/aplandj/qnial.html
• Comparison of array languages, Keith Smilliehttp://www.cs.ualberta.ca/~smillie/ComputerAndMe/Part23.html
• “APL programming language,” Wikipediahttp://en.wikipedia.org/wiki/APL_programming_language