diff --git a/help/SnapManual.pdf b/help/SnapManual.pdf index 57f50bba..59feac9c 100644 Binary files a/help/SnapManual.pdf and b/help/SnapManual.pdf differ diff --git a/libraries/LIBRARIES b/libraries/LIBRARIES index fd44b4a7..31ae604e 100644 --- a/libraries/LIBRARIES +++ b/libraries/LIBRARIES @@ -1,5 +1,6 @@ iteration-composition.xml Iteration, composition Traditional loop constructs (while, until, etc.) plus the Lisp "named let" (a generalization of FOR) plus functional iteration (repeated invocation of a function) and function composition. list-utilities.xml List utilities Some standard functions on lists (append, reverse, etc.) +apl.xml APL primitives Adds features from the APL language supporting hyperblocks. stream-tools.xml Streams (lazy lists) A variation on the list data type in which each list item aren't computed until it's needed, so you can construct million-item lists without really taking up all that time or memory, or even infinite-sized lists. (A block that reports all the prime numbers is included as an example.) variadic-reporters.xml Variadic reporters Versions of +, x, AND, and OR that take more than two inputs. httpBlocks.xml Web services access (https) An extended version of the HTTP:// block that allows POST, PUT, and DELETE as well as GET requests, allows using the secure HTTPS protocol, and gives control over headers, etc. diff --git a/libraries/apl.xml b/libraries/apl.xml new file mode 100644 index 00000000..4a6b2d88 --- /dev/null +++ b/libraries/apl.xml @@ -0,0 +1 @@ +The first input is a shape list as in SHAPE OF. The output is an array with those dimensions containing the atomic items of the second input, repeating values if more are needed.
0partialpartial
Reports a flat list of the maximum size of the input array along each dimension: number of rows, number of columns, etc. "Maximum" because it works even if the array isn't uniformly shaped.
Reports the greater of its two inputs. Works on strings too.
Reports a flat list of all the atomic elements of sublists of the input list.
Given two arrays A and B, reports an array whose dimensions are APPEND(SHAPE OF (A), SHAPE OF (B)) in which each atomic item of the result is computed by applying the dyadic function input to an item of A and an item of B.
1
Reports its input. This is useful to fit a value into a different-type input slot, e.g., number into list slot.
Reports the number of dimensions of the input.
111
Takes a multidimensional array, and reports an array whose dimensions are reversed (as reported by SHAPE OF). In the case of a two-dimensional array, does the usual transposition of rows and columns.
111
Reverses the order of the (toplevel) items of the input. If the input is a matrix, this means it reverses the order of the rows, which is a reflection through a horizontal axis, as the ⦵ symbol suggests.
Recursively deep-inserts the items of the first input into the items of the second input. If the first input is not a list, then it is inserted with IN FRONT OF in the second unless the second also isn't a list, in which case they are combined with LIST.
1
Like MAP, but can take any number of lists as inputs. The lists must all be the same size. The function input must take a number of inputs equal to the number of lists. MULTIMAP calls the function with all the first items, then all the second items, and so on.
1
Takes a (possibly deep) list as input, and reports a human-readable text form of the list (namely, Lisp notation).
( )
Computes a generalized matrix multiplication. In normal matrix multiplication, each cell of the result is computed by multiplying individual numbers within a row of the left input and a column of the right input, and then adding those products. In APL terms this is +.× ("plus dot times") Any dyadic functions can replace addition and multiplication in this algorithm; a common case is ∨.∧ ("or dot and")
111111
Reports the smaller of its two inputs.
Computes logarithms in any base. The base is the left input. It's usual in APL that if there's a main data input and some sort of control input, the latter comes on the left. This is because APL syntax, unless you use parentheses, groups computations from right to left. APL has a monadic version of this function that computes natural logs (log to the base e).
Computes the number of combinations of right-input things taken left-input at a time, otherwise known as the elements of Pascal's triangle. This block shares the ! symbol with the monadic factorial function, because the formula for computing this function uses factorials.
The factorial of a positive integer n is the product of the integers from 1 to n. In real APL, the domain of this function is extended beyond integers to compute the gamma function.
This function has two names because there are two ways to understand it. Lisp way: A matrix is a list of rows. This block combines the numbers in each row, producing one value for the entire row. APL way: A matrix is made of vectors. This block takes each column as a vector, and does vector arithmetic on the columns, producing one column as the result.
pt:lança o erro _
Acts just like the function selected from the pulldown menu, but hyperized, so comparing two equal-sized lists reports a list of the same length as the inputs, with the results of item-by-item comparisons.
﹦ ≠ identical to and or is _ a _?
Report a list with left-input random integers in the range 1 to right-input. No number appears more than once in the result.
choicechoice11
Reports 1 if the input is positive, 0 if the input is zero, or -1 if the input is negative.
0false
reports 1 divided by its input.
This block reports a random integer between 1 and its input. To roll more than one die, use (for three dice) roll (reshape as 3 items of 6) APL: ?3⍴6 Don't use reshape as 3 items of roll 6, because that would roll one die and report 3 copies of the same random roll.
Reports the greatest common divisor of its inputs. If the inputs are values in {0,1} then this is equivalent to the logical OR of the values, with 0=False, 1=True. Hence the APL symbol ∨. Also accepts Snap! Booleans as inputs.
ab
Takes a dyadic scalar function as input, and hyperizes it, so that it can take lists as inputs.
ab
Reports True if the input is an APL scalar, i.e., either an atomic (non-list) value, or an array (list of lists) of any depth with only one atomic item, e.g., (list (list (list (3)))).
1
The input must be a value for which SCALAR? reports true, i.e., either an atom or a list of any depth but only one scalar item of item of... etc. This function returns the underlying scalar (number, etc.).
1
Reports the least common multiple of its inputs. If the inputs are values in {0,1} then this is equivalent to the logical AND of the values, with 0=False, 1=True. Hence the APL symbol ∧. Also accepts Snap! Booleans as inputs.
ab
Reports the not-and of its inputs, in the form 0 for false, 1 for true.
Reports 1 if the input is False or 0; otherwise reports 0.
Reports the not-and of its inputs, in the form 0 for false, 1 for true.
Reports True if the left input is less than or equal to the right input. Reports a Snap! Boolean, not an integer 0 or 1.
Reports True if the left input is greater than than or equal to the right input. Reports a Snap! Boolean, not an integer 0 or 1.
Reports 0 if its inputs are equal; reports 1 if its inputs are not equal. The inputs can have any non-list values. (Lists are hyperized.) If the inputs are Booleans (True/False or 1/0), this is also the exclusive-or function.
reports True iff the input is 0 or False.
Reports a Snap! Boolean False if the input is False or 0; reports True otherwise.
Make scalar called with non-singleton input
If the input is a positive integer, reports a list of the numbers from 1 to that input. (If the input is 0, reports an empty list.) If the input is a list of positive integers, reports an array with the shape specified by the input (as in ⍴ reshape) in which each item is a list of the indices of that item in the array (so technically the shape has one more dimension than the input, whose size is the size of the input).
If the rank of the left input is one more than the rank of the right input, reports the index of the right input in the left input, or if not found, reports one more than the length of the left input. If the rank of the left input is equal to the rank of the right input, reports a vector of the indices of the items of the right input in the left input (mapping this function over the right input). If the rank of the left input is more than that of the right input by 2 or more, reports a vector, the location of the right input in the left in each dimension. It is an error if the rank of the left input is less than that of the right input.
1result
This isn't an APL function, although it's related to the outer product. It takes any number of lists, and reports a list of all possible tuples with one item from each of the lists. The length of the result is the product of the lengths of the inputs.
Reports an array of Booleans the same shape as the left input, indicating which of the atoms in the left input appear anywhere in the right input. (The structure of the right input doesn't matter.)
Like append, but: A scalar input is treated as a vector of length 1. If the two inputs are of different ranks, the function is mapped over the larger ranked input. Catenate adds new columns, by appending to each row.
If the input is a nesting of length=1 lists, which APL treats as a scalar (the innermost item) for many purposes, report that innermost scalar. Otherwise, report the input as is. Exposing this block for users is important because Snap! /does not/ treat such a nesting as a scalar, so you might need to use this in translating an APL program to Snap!. (But the functions in the APL library already use this block as needed.)
Reports a vector of indices of the items of the input, in order of the values of the items, so that item (grade up (foo)) of (foo) reports the items in sorted order, smallest to largest. For a matrix, sorts the rows based on their first items, or if those are equal, based on their second items, etc.
Reports a sorted version of the list in its first input slot, using the comparison function in the second input slot. For a list of numbers, using < as the comparison function will sort from low to high; using > will sort from high to low.
ca:ordena _ segons criteri _ copy of datasplitmerge11#1#2
Compares two vectors for sorting. Compare first items; if those are equal compare second items; etc.
1111
Reports a vector of indices of the items of the input, in order of the values of the items, so that item (grade down (foo)) of (foo) reports the items in sorted order, largest to smallest. For a matrix, sorts the rows based on their first items, or if those are equal, based on their second items, etc.
The left input must be a vector of Booleans (either Snap! form or APL form); the right input must be an array whose first dimension is equal to the length of the left input. The block reports an array of the same rank as the right input, containing only those items (rows, for a matrix) for which the corresponding Boolean is True (or 1).
The left input must be a vector of Booleans (either Snap! form or APL form); the right input must be an array whose last dimension is equal to the length of the left input. The block reports an array of the same rank as the right input, containing only those items (columns, for a matrix) for which the corresponding Boolean is True (or 1).
Turns a row-wise (in Lisp terminology) into a column-wise one.
Reverses the order of the columns of the input, which is a reflection through a vertical axis, as the ⏀ symbol suggests.
This function has two names because there are two ways to understand it. Lisp way: A matrix is a list of rows. This block turns it into a list of columns, and combines the numbers in each column, producing one value for the entire column. APL way: A matrix is made of vectors. This block takes each row as a vector, and does vector arithmetic on the rows, producing one row as the result.
Like append, but: A scalar input is treated as a vector of length 1. If the two inputs are of different ranks, the function is mapped over the larger ranked input. Catenate vertically adds new rows, by appending to each column.
A hyperblock version of JOIN. The regular JOIN isn't hyperized because it can accept a list as input, representing it as text.
A positive left input selects the first n items of the right input. A negative left input selects the last abs(n) items of the right input. If the right input is a matrix, a numeric left input selects rows; the left input may also be a two-item vector, in which case the first number is applied to the rows and the second number is applied to the columns. Similarly for higher-dimension arrays.
10valueindex
A positive left input selects all but the first n items of the right input. A negative left input selects all but the last abs(n) items of the right input. If the right input is a matrix, a numeric left input selects rows; the left input may also be a two-item vector, in which case the first number is applied to the rows and the second number is applied to the columns. Similarly for higher-dimension arrays.
0valueindex
\ No newline at end of file diff --git a/libraries/iteration-composition.xml b/libraries/iteration-composition.xml index eaaafe59..efea4851 100644 --- a/libraries/iteration-composition.xml +++ b/libraries/iteration-composition.xml @@ -1 +1 @@ -
de:fange _ _ ca:agafa _ _ es:atrapar _ _ fr:attrape _ _ pt:captura _ _ cont3
de:wirf _ ca:llança _ es:lanzar _ fr:lance _ pt:lança _ catchtag
de:fange _ _ ca:agafa _ _ es:atrapar _ _ fr:attrape _ _ pt:captura _ _ cont
de:wirf _ _ ca:llança _ _ es:lanzar _ _ fr:lance _ _ pt:lança _ _ catchtag
de:falls _ dann _ und pause $pause-1-255-220-0 ca:si _ fes _ i atura-ho tot $pause-1-255-220-0 es:si _ haz _ y páralo todo $pause-1-255-220-0 fr:si _ faire _ et mettre tout en pause $pause-1-255-220-0 pt:se _ , então _ e faz pausa em tudo $pause-1-255-220-0
de:ignoriere _ ca:ignora _ es:ignorar _ fr:ignore _ pt:ignora _
Call f(f(f(...(f(x))))) n times where the three input slots are n, f, and x from left to right. The # variable can be used inside f to represent how many times f has been called.
pt:o resultado de _ invocações em cascata de _ com argumento inicial _ _
Call f(f(f(...(f(x))))) until condition is true, where the three input slots are condition, f, and x from left to right. The # variable can be used inside f or condition to indicate how many times f has been called.
pt:o resultado da invocação em cascata até que _ de _ com argumento inicial _ _
Returns the function f(g(x)) where f and g are the two inputs.
pt:a composição de _ com _
Like the built-in REPEAT UNTIL block, except that the ending condition is not tested until the script has been run the first time. So the script is run at least once.
pt:repete _ até que _ $loop-0.7
Run the script repeatedly, as long as the given condition is true. Runs the script at least once before testing the condition.
pt:repete _ enquanto _ $loop-0.7
Runs the script repeatedly, as long as the condition is true. Tests the condition before the first time the script is run. Like the built in REPEAT UNTIL except that in this block the condition must be true, not false.
pt:enquanto _ , repete _ $loop-0.7
Runs the script the specified number of times, like the built-in REPEAT block, but this one provides the # variable that can be used inside the script. Try REPEAT (200) MOVE (#) STEPS RIGHT 92 with the pen down.
pt:repete _ vezes _ _ $loop-0.7
pt:para _ de _ com passo _ a _ _ $loop-0.7 1110
Provides LOOP as a function of one input that runs the body of the LET with A set to the function input, so the body can run itself recursively. See COPY block in Variables for an example of use.
pt:tendo _ o valor inicial _ , executa _ definido como _ new value
\ No newline at end of file +
de:fange _ _ ca:agafa _ _ es:atrapar _ _ fr:attrape _ _ pt:captura _ _ cont
de:wirf _ ca:llança _ es:lanzar _ fr:lance _ pt:lança _ catchtag
de:fange _ _ ca:agafa _ _ es:atrapar _ _ fr:attrape _ _ pt:captura _ _ cont
de:wirf _ _ ca:llança _ _ es:lanzar _ _ fr:lance _ _ pt:lança _ _ catchtag
de:falls _ dann _ und pause $pause-1-255-220-0 ca:si _ fes _ i atura-ho tot $pause-1-255-220-0 es:si _ haz _ y páralo todo $pause-1-255-220-0 fr:si _ faire _ et mettre tout en pause $pause-1-255-220-0 pt:se _ , então _ e faz pausa em tudo $pause-1-255-220-0
de:ignoriere _ ca:ignora _ es:ignorar _ fr:ignore _ pt:ignora _
Call f(f(f(...(f(x))))) n times where the three input slots are n, f, and x from left to right. The # variable can be used inside f to represent how many times f has been called.
pt:o resultado de _ invocações em cascata de _ com argumento inicial _ _
Call f(f(f(...(f(x))))) until condition is true, where the three input slots are condition, f, and x from left to right. The # variable can be used inside f or condition to indicate how many times f has been called.
pt:o resultado da invocação em cascata até que _ de _ com argumento inicial _ _
Returns the function f(g(x)) where f and g are the two inputs.
pt:a composição de _ com _
Like the built-in REPEAT UNTIL block, except that the ending condition is not tested until the script has been run the first time. So the script is run at least once.
pt:repete _ até que _ $loop-0.7
Run the script repeatedly, as long as the given condition is true. Runs the script at least once before testing the condition.
pt:repete _ enquanto _ $loop-0.7
Runs the script repeatedly, as long as the condition is true. Tests the condition before the first time the script is run. Like the built in REPEAT UNTIL except that in this block the condition must be true, not false.
pt:enquanto _ , repete _ $loop-0.7
Runs the script the specified number of times, like the built-in REPEAT block, but this one provides the # variable that can be used inside the script. Try REPEAT (200) MOVE (#) STEPS RIGHT 92 with the pen down.
pt:repete _ vezes _ _ $loop-0.7
pt:para _ de _ com passo _ a _ _ $loop-0.7 1110
Provides LOOP as a function of one input that runs the body of the LET with A set to the function input, so the body can run itself recursively. See COPY block in Variables for an example of use.
pt:tendo _ o valor inicial _ , executa _ definido como _ new value
\ No newline at end of file diff --git a/libraries/list-utilities.xml b/libraries/list-utilities.xml index 88af9cf6..1671dac6 100644 --- a/libraries/list-utilities.xml +++ b/libraries/list-utilities.xml @@ -1 +1 @@ -Take any number of input lists, and create a new list containing the items of the input lists. So APPEND [A B] [C D] where the [...] are lists reports the list [A B C D] not [[A B] [C D]].
ca:concatena _ 11111
Reports a new list containing the items of the input list, but in the opposite order.
ca:capgira _ 1inputresult
Reports a new list whose items are the same as in the input list, except that if two or more equal items appear in the input list, only the last one is kept in the result.
ca:elimina els duplicats de _ 1
Reports a sorted version of the list in its first input slot, using the comparison function in the second input slot. For a list of numbers, using < as the comparison function will sort from low to high; using > will sort from high to low.
ca:ordena _ segons criteri _ copy of datasplitmerge11#1#2
The second input is an "association list," a list of two-item lists. Each of those smaller lists has a "key" as its first item and a "value" as its second. ASSOC reports the first key-value pair in the association list whose key matches the first input.
ca:associació _ _ 11
This block applies the given function to each item of the given list, like the primitive MAP block, but with two differences: 1. The # variable provided will contain the item number of the item currently being used in the given function: 1 for item 1, and so on. You read the variable in your function; don't set it. 2. You can provide more than one input list. If so, the lengths of all the lists should be the same, and the function you supply must expect as many inputs as you have lists (i.e., that many empty input slots in the function).
ca:_ mapeja _ sobre _ #11datacountmapmany##1#1data listscount
This block makes a new list containing selected items from the given list, like the primitive KEEP block. What's different is that it provides the # variable for use in your predicate function. It will contain the item number (in the original list) of the item being examined by the predicate.
ca:_ manté els elements on _ de _ #1datacount1
This block carries out the given script for each item of the given list, like the primitive FOR EACH. What's different is that it provides the # variable, which will contain the item number in the list of each item in turn, 1 while processing item 1, and so on.
ca:_ per cada _ de _ _
\ No newline at end of file +Reports a new list containing the items of the input list, but in the opposite order.
ca:capgira _ 1inputresult
Reports a new list whose items are the same as in the input list, except that if two or more equal items appear in the input list, only the last one is kept in the result.
ca:elimina els duplicats de _ 1
Reports a sorted version of the list in its first input slot, using the comparison function in the second input slot. For a list of numbers, using < as the comparison function will sort from low to high; using > will sort from high to low.
ca:ordena _ segons criteri _ copy of datasplitmerge11#1#2
The second input is an "association list," a list of two-item lists. Each of those smaller lists has a "key" as its first item and a "value" as its second. ASSOC reports the first key-value pair in the association list whose key matches the first input.
ca:associació _ _ 11
This block applies the given function to each item of the given list, like the primitive MAP block, but with two differences: 1. The # variable provided will contain the item number of the item currently being used in the given function: 1 for item 1, and so on. You read the variable in your function; don't set it. 2. You can provide more than one input list. If so, the lengths of all the lists should be the same, and the function you supply must expect as many inputs as you have lists (i.e., that many empty input slots in the function).
ca:_ mapeja _ sobre _ #11datacountmapmany##1#1data listscount
This block makes a new list containing selected items from the given list, like the primitive KEEP block. What's different is that it provides the # variable for use in your predicate function. It will contain the item number (in the original list) of the item being examined by the predicate.
ca:_ manté els elements on _ de _ #1datacount1
This block carries out the given script for each item of the given list, like the primitive FOR EACH. What's different is that it provides the # variable, which will contain the item number in the list of each item in turn, 1 while processing item 1, and so on.
ca:_ per cada _ de _ _
\ No newline at end of file