This is an interactive tutorial for the NESL
interface.
At each code box you can Submit the code in the box to the
NESL interpreter, and use your browser's Back button to get
back to this page.
To try out different things you can also modify the code in the boxes
before sending it.
NESL supports simple arithmetic expressions on scalar values. Scalar values
include integers, floating-point numbers, booleans, and characters. You
can try some of the following:
Booleans are denoted with t and f.
Characters are denoted using a back-quote followed by the character.
Local binding can be made with a let expression. In the
following example, the variable a is locally bound to the
result of the expression 3*4 and then used in the
expression a+(a*1):
Multiple assignments are allowed in a let expression. They
must be separated by semicolons.
Conditional expressions use the syntax
Pairs are a way to pass around multiple values in NESL. A pair is
denoted by to values separated by a comma. For example:
This can be used to return multiple values from a function, and pattern matching can be done.
Parallelism on sequences can be achieved in two ways: the ability to
apply any function concurrently over each element of a sequence, and a
set of built-in parallel functions that operate on sequences.
Any function can be applied over the elements of a sequence in
parallel. This is expressed using a set-like notation similar to
set-formers in SETL and list-comprehensions in
Miranda and Haskell. For example,
This construct can be read as: in parallel for each x
in the sequence [1.0,3.0,9.0], take the square root of
x.
Any function including user defined functions can be applied over the
elements of a sequence:
The apply-to-each form can also be used to subselect elements based
on a predicate, for example:
It can also be nested:
There are many built in sequence operations in NESL. Here is a list of
some of them:
#a -- the length of a sequence a
a[i] -- get the ith element of a
a ++ b -- append a and b
take(a,n) -- take the first n elements of a
[s,e] -- generate a sequence of integers from s to e
sum(a) -- sum the elements of a sequence
sort(a) -- sort the elements of a sequence
Feel free to try some of them. You can type multiple expressions after the
variable definitions and use the variables.
The description of any of the sequence functions (in fact, any
function) can be found by using the expression describe funcname
You might try finding the description of one of following functions: