NESL is not case sensitive. In the syntax below we use uppercase to present literal symbols.
| Syntax | Example |
|---|---|
FUNCTION name(args) = exp ;
|
FUNCTION double(a) = 2*a;
|
IF e1 THEN e2 ELSE e3
| IF (a > 22) THEN a ELSE 5*a
|
LET binding* IN exp
|
LET a = b*6;
|
{e1 : pattern IN e2}
|
{a + 22 : a IN [2, 1, 9]}
|
{pattern IN e1 | e2}
|
{a IN [2, 1, 9] | a < 8}
|
{e1 : p1 IN e2 ; p2 in e3}
|
{a + b : a IN [2,1]; b IN [7,11]}
|
| Scalar Functions | |
|---|---|
| logical | not or and xor nor nand
|
| comparison | == /= < > <= >=
|
| predicates | plusp minusp zerop oddp evenp
|
| arithmetic |
+ - * / rem abs max min
|
| conversion |
btoi code_char char_code
|
| random numbers |
rand rand_seed
|
| constants |
pi max_int min_int
|
| Basic Sequence Functions | |
|---|---|
| Basic Operations | |
#a
| Length of a
|
a[i]
| ith element of a
|
dist(a,n)
|
Create sequence of length n with a
in each element.
|
zip(a,b)
| Elementwise zip two sequences together into a sequence of pairs. |
[s:e]
|
Create sequence of integers from s
to e (not inclusive of e)
|
[s:e:d]
|
Same as [s:e] but with a stride d.
|
| Scans | |
plus_scan(a)
|
Execute a scan on a using the + operator
|
min_scan(a)
|
Execute a scan on a using the minimum operator
|
max_scan(a)
|
Execute a scan on a using the maximum operator
|
or_scan(a)
|
Execute a scan on a using the or operator
|
and_scan(a)
|
Execute a scan on a using the and operator
|
| Reductions | |
sum(a)
|
Sum the elements of a
|
max_val(a)
|
Return maximum value of a
|
min_val(a)
|
Return minimum value of a
|
any(a)
|
Return true if any values of a are true.
|
all(a)
|
Return true only if all values of a are true.
|
count(a)
|
Count number of true values in a.
|
max_index(a)
| Return position (index) of maximum value. |
min_index(a)
| Return position (index) of minimum value. |
| Reordering Functions | |
read(a, i)
|
Read values in a from indices i
|
write(a, iv_pairs)
|
Write values in a using integer values pairs in
iv_pairs
|
permute(a,i)
|
Permute elements in a to indices in i
|
rotate(a,i)
|
Rotate sequence a by i locations
|
reverse(a)
|
Reverse order of sequence a.
|
drop(a,i)
|
Drop first i elements of a.
|
take(a,i)
|
Take first i elements of a.
|
odd_elts(a)
|
Return the odd elements of a
|
even_elts(a)
|
Return the even elements of a
|
interleave(a,b)
|
Interleave the elements of a and b.
|
subseq(a,i,j)
|
Return the subsequence of a from position i
to j (not inclusive of j)
|
a -> i
|
Same as read(a, i)
|
a <- iv_pairs
|
Same as write(a, iv_pairs)
|
| Nesting/Unnesting | |
flatten(a)
| Flatten a nested sequence by one level. |
partition(a,l)
|
Partition a sequence into a nested sequence using lengths in l
|
bottop(a)
| Split a sequence in two and return as nested sequence. |
describe in
the window that appears with each group and submit (make sure the line
ends with a semicolon).
length_from_flags sort rank collect int_collect kth_smallest find search_for_subseqs remove_duplicates mark_duplicates union intersection name transpose eql hash select identity
@ exp_string || linify wordify lowercase uppercase string_eql parse_int parse_float
print_char,
print_string, write_char,
write_string, and write_check can be called in
parallel.
print_char print_string write_object_to_file write_string_to_file append_string_to_file read_object_from_file read_string_from_file read_int_seq_from_file read_float_seq_from_file open_in_file open_out_file close_file write_char write_string read_char read_string read_line read_word open_check write_check read_check close_check nullstr stdin stdout stderr
w_make_window command and then can add various features
to the window. The most important features are boxes and buttons.
A scale box can be used to create a virtual coordinate system on the
window on which points, lines, rectangles and polygons can be drawn.
A text box can be used to create a box in which text can be written.
A button can be used along with the input functions to get information
back from the window.
In all the functions in this section colors are specified
by one of w_black, w_white, w_red, w_blue, w_green, w_cyan, w_yellow, w_magenta, w_pink, w_light_green, w_light_blue, w_purple, w_gray, w_dark_gray, w_orange.
display w_make_window w_kill_window w_add_box w_add_text_box w_add_button w_add_button_stack w_add_text w_get_named_box w_reset_box_size w_clear_box w_bounds_from_box w_box_scale w_bounding_box w_draw_point w_draw_big_point w_draw_points w_draw_segments w_draw_string w_draw_rectangle w_shade_rectangle w_shade_polygon w_write_text_centered w_write_text_left w_write_paragraph w_get_input w_get_input_noblock w_get_button_input w_get_zoom_box
shell_command get_environment_variable spawn time
back to the NESL page