Satimage
Le dictionnaire de Satimage
Accueil Les dictionnaires Le dictionnaire de Satimage  
Satimage Text Additions
Satimage File Additions
Resource Suite
Mathematical Functions
Arrays
Array and List Utilities
Satimage Text Additions
mailto:support@satimage-software.com

matchrecord n : the record returned by "find text"

properties

matchPos integer : offset of the first character found

matchLen integer : length of the match

matchResult string : the matching string (possibly formatted according to the "using" parameter)}


find text v : find text literally or using regular expression syntax. syn ufind text

find text string : the substring to search for

in string : a string or an alias

[starting at integer] : default: 0

[for integer] : length of text after starting

[case sensitive boolean] : default true

[regexp boolean] : use regular expression, default false

[whole word boolean] : default false

[regexpflag list of string] : a subset of {"IGNORECASE", "EXTEND", "MULTILINE", "SINGLELINE", "FIND LONGEST", "FIND NOT EMPTY", "DONT CAPTURE GROUP", "NOTBOL", "NOTEOL", "NEWLINE IN NEGATIVE CC"}; default {}

[using string] : the pattern to generate the string (regexp). Useful for constructs with backward references in regexp, ex.: using "name: \\1". May be a list of strings, in this case matchResult is a list of strings.

[all occurrences boolean] : returns a list of all occurrences. Default: false

[string result boolean] : return only the matching string instead of the whole record

[syntax string] : the syntax for regular expressions. Relevant if regexp parameter is true. A string among ("POSIX" | "POSIX_EXTENDED" | "EMACS" | "GREP" | "GNU_REGEX" | "JAVA" | "PERL" | "RUBY"). Default: "RUBY"

→ record : {matchLen: length of the match, matchPos: offset of the match, matchResult: the matching string (possibly formatted according to the "using" parameter)}

Discussion
Definitions of options of regexpflag's parameters:

SINGLELINE'^' -> '\A', '$' -> '\z', '\Z' -> '\z'
MULTILINE'.' match newline
IGNORECASEignore case (case-insensitive)
EXTENDextended pattern form: [:spaces:] are ignored if not escaped
FIND_LONGESTfind longest match when using alternations |
FIND_NOT_EMPTYignore empty match
NEGATE_SINGLELINEclear SINGLELINE which is default on in POSIX, POSIX_EXTENDED, PERL and JAVA syntaxes.
DONT_CAPTURE_GROUPonly named group captured: (?<name>subexp)
NOTBOLbegin of text isn't considered as begin of line
NOTEOLend of text isn't considered as end of line
NEWLINE IN NEGATIVE CCnegative character classes match newline, for instance [^a-z]

Example
set the_str to pi as string find text "3" in the_str -- {matchPos:0, matchLen:1, matchResult:"3"} set s to "2007-12-24" find text "([[:digit:]]+)" in s using "\\1" with regexp, all occurrences and string result -- {"2007", "12", "24"}

change v : replace all occurrences of a substring syn uchange

change string or list of string : the substring(s) to search for

into string or list of string : the unicode replacement string(s)

in string, list of string, or alias

[starting at integer] : default: 0

[for integer] : length of text after starting

[case sensitive boolean] : default true

[regexp boolean] : default false

[whole word boolean] : default false

[regexpflag list of string] : see the documentation for find text

[syntax string] : see the documentation for find text

anything : the new string if the "in" parameter is a string, otherwise the number of changes performed in the file

Example
set the_str to "hello" change "e" into "u" in the_str -- "hullo" change {"e", "o"} into {"E", "O"} in "hello world" -- "hEllO wOrld" change "([0-9]{1,2})/([0-9]{1,2})" into "\\2/\\1" in {"31/12/2007", "29/2/2008"} with regexp -- {"12/31/2007", "2/29/2008"}

re_compile v : check a regular expression

re_compile string : the regular expression

[syntax string] : the syntax for regular expressions. Relevant if regexp parameter is true. A string among ("POSIX" | "POSIX_EXTENDED" | "EMACS" | "GREP" | "GNU_REGEX" | "JAVA" | "PERL" | "RUBY"). Default: "RUBY"

splittext v : split a text according to a given separator pattern. Optional matching parameters work like with the "find text" command

splittext string : the string to split

using string : the separator

[case sensitive boolean] : default true

[regexp boolean] : consider the separator pattern as a regular expression, default false

[whole word boolean] : consider only whole word separators. default false

→ list of string : the splitted text. If no separator found, the returned list contains one element: the original string.

filter text v : parse a string (or a text file) into a plist

filter text string : the pattern

in string : a string or an alias

key string : the pattern to generate the keys in the plist

[using string] : the pattern to generate the strings of the plist. Default: "\\0"

[as type] : list or string. Default: string, the plist contains for each key a concatenation of the matches separated by a linefeed character. Otherwise the plist contains for each key an array of matches.

[duplicates boolean] : relevant if the "as" parameter is list. Without duplicates, only new strings are added. Default: true

[case sensitive boolean] : default: true

[whole word boolean] : default: false

[regexpflag list of string] : like in the find text command

[syntax string] : like in the find text command

[into file or CFRef] : the file destination for the plist or an existing plist (see the XMLLib.osax dictionary)

→ string : the XML data if the into parameter is missing

Example
set s to "John is ten Anna is twelve John is at school Anna sleeps" filter text "^([A-z]+) is (.*)" in s key "\\1" using "\\2" as list
returns a plist containing:
<dict> <key>Anna</key> <array> <string>twelve</string> </array> <key>John</key> <array> <string>ten</string> <string>at school</string> </array> </dict>

file offset v : find a string in a file and return the offset in byte.

file offset string : the character(s) to find

in alias

[starting at integer] : the initial offset in byte

[encoding string] : a IANA charset name ("MACINTOSH", "UTF-8", "UTF-16", "ISO-8859-1", "windows-1252"…). Default: "UTF-8"

[inclusive boolean] : default: false. If true, the offset includes the requested string

→ integer

readtext v : read a text file. readtext is aware of the presence of BOM.

readtext alias : or an url

[for integer] : the maximum number of bytes to read

[starting at integer] : the initial offset in byte

[encoding string] : a IANA charset name ("MACINTOSH", "UTF-8", "UTF-16", "ISO-8859-1", "windows-1252"…)

→ string

writetext v : write a string in a file.

writetext string

to file : or an url

[append boolean] : default: false. If true, append the string at the end of the file

[encoding string] : a IANA charset name ("MACINTOSH", "UTF-8", "UTF-16", "ISO-8859-1", "windows-1252"…). Default: "UTF-8"

[missing char string] : characters that cannot be converted to the specified encoding are represented with this character. Default: writetext returns an error if it encounters an untranslatable character

→ string

uppercase v : move to uppercase.

uppercase string : the original string

→ string : the uppercase string

lowercase v : move to lowercase.

lowercase string : the original string

→ string : the lowercase string

format v : format a real number using a specification string. Ex: format pi into "##.##"->"3.14". '0' instead of '#' forces trailing zeros. '^' adds a space. "+f1;-f2;f3" provides formats for numbers >0, <0, =0. Encapsulate custom strings with "'".

format real : the number

into string : the formatting string, using #,^,O,.,%,',(,),+,-

[underflow test boolean] : switch to scientific format if the number is too small with respect to the formatting string (default: false)

→ string : the formatted number

atof v : convert a string into a number. Ex: atof "1.5"

atof string or list of string

→ real

encode entities v : substitutes the 5 reserved XML characters found in the direct parameter with the corresponding XML entities.

encode entities string

→ string

Example
encode entities "'foo' > 'Foo'" -- "&apos;foo&apos; &gt; &apos;Foo&apos;"

resolve entities v : substitutes the XML character entities found in the direct parameter (not the html entities such as &eacute;) with the corresponding Unicode characters.

resolve entities string

→ string

Example
resolve entities "&apos;foo&apos; &gt; &apos;Foo&apos;" -- "'foo' > 'Foo'"

escapeURL v : encode a URI by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character

escapeURL string : a URI or a URI component

[escaping string] : additional characters to escape. Default "". To translate URI component (for a GET request for instance) into legal URI component use ";,/?:@&=+$"

→ string : a legal URI

unescapeURL v : decode a URI previously encoded with "escapeURL".

unescapeURL string

[keeping string] : characters to leave escaped. Default "".

→ string

normalize unicode v : normalize Unicode text (canonical composition or decomposition)

normalize unicode string

[decomposition boolean] : want canonical decomposition. default: false. For example, HFS Plus converts all file names to decomposed Unicode, while Macintosh keyboards generally produce precomposed Unicode.

→ string

hash v : normalize (KD) and hash a string

hash string

→ integer

join v : coerce as Unicode text

join list of string

using string : the text delimiter

→ string

printf v : format a string like the C function printf.

printf string : the format string

parameters list of anything

→ string : the formatted string

Example
printf "printf prints integers like %d, floats like %g, strings like \"%s\"." parameters {12, pi, "hello"} -- "printf prints integers like 12, floats like 3.14159, strings like \"hello\"." printf "escape %% with %%%% like in %2.f%%" parameters {39.12} -- "escape % with %% like in 39%" -- use of positional parameters: set params to {"car", "red"} printf "The %s is %s." parameters params -- "The car is red." printf "The %2$s %1$s." parameters params -- "The red car." -- use of list parameters: printf ("%.1g %.3g" & return) parameters {randomarray 4, randomarray 4} --"0.3 0.846 0.1 0.348 1 0.0174 0.6 0.444 "

strftime v : format a date using a specification string like in the C function strftime.

strftime date or list of date

into string : the formatting string. To obtain ISO 8601 dates, use "%FT%TZ" or "%GW%V-%uT%TZ" (using the 'with GMT' parameter)

[GMT boolean] : if true, output date as GMT. Default: false, the ouput date is local.

→ string : the formatted date

Example
set d to current date -- some ISO 8601 formats: strftime d into "%FT%T%z" -- "2007-01-15T16:10:56+0100" strftime d into "%GW%V-%uT%T%z" -- "2007W03-1T16:10:56+0100" --if you need to store the date d as UTC: strftime d into "%FT%TZ" with GMT -- "2007-01-15T15:10:56Z" strftime d into "%a, %b %d, %Y %H:%M:%S %z" -- "Mon, Jan 15, 2007 16:10:56 +0100"

strptime v : Reverse of strftime.

strptime string or list of string : the date string(s)

encoding string : the format of the date corresponding to the into parameter of strftime.

[GMT boolean] : the intput date string is GMT (if unspecified by the format). Default: false

[as type] : date or real (seconds since January 1 2001). Default: date

→ date or real : the date

Example
strptime "2007-01-15T16:10:56+0100" encoding "%FT%T%z" -- date "Monday, January 15, 2007 16:10:56" strptime "2007-01-15T16:10:56Z" encoding "%FT%T" -- date "Monday, January 15, 2007 16:10:56" strptime "2007-01-15T16:10:56Z" encoding "%FT%T" with GMT -- date "Monday, January 15, 2007 17:10:56" strptime "Mon, Jan 15, 2007 16:25:36 +0100" encoding "%a, %b %d, %Y %H:%M:%S %z" -- date "Monday, January 15, 2007 16:25:36"
Satimage File Additions

URL information n : Reply record for the ‘URL info for’ command

properties

scheme Unicode text : the access scheme

host Unicode text : the host specified by this URL

path Unicode text : the (escaped) location of the target on the host

unix path Unicode text : the (unescaped) location of the target on the host

name Unicode text : the name of the item

user name Unicode text : the user name by which to access this URL

password Unicode text : the password by which to access this URL

name extension Unicode text : the name extension of the URL

url parameters Unicode text

url query Unicode text

url fragment Unicode text

type identifier Unicode text : the item’s type identifier


alias description for v : provide info needed to refer to a remote item

alias description for alias : the remote item

→ list of string : {the AppleTalk zone name, the server machine name, the server volume name, folder name, […], item name}

navchoose file v : choose file with navigation services

navchoose file

[with prompt string] : a prompt to be displayed in the file chooser

[of type list of string] : restrict the files shown to only these file types

[starting at alias] : the default file or folder

[multiple files boolean] : allow multiple files selection (default true)

[show packages boolean] : (default true)

[open packages boolean] : (default false)

[of extension list of string] : list of allowed file extensions

[invisibles boolean] : Show invisible files and folders? (default is false)

[key integer] : associate a key to the folder that the user will select. If no 'starting at' parameter is provided, assume the corresponding folder as the default folder.

→ list of alias : the chosen files

navchoose folder v : choose folder with navigation services

navchoose folder

[with prompt string] : a prompt to be displayed in the folder chooser

[starting at alias] : the default folder

[multiple files boolean] : allow multiple folders selection (default true)

[open packages boolean] : (default false)

[key integer] : associate a key to the folder that the user will select. If no 'starting at' parameter is provided, assume the corresponding folder as the default folder.

→ list of alias : the chosen folders

navchoose object v : choose file or folder with navigation services

navchoose object

[with prompt string] : a prompt to be displayed in the folder chooser

[starting at alias] : the default folder

[multiple files boolean] : allow multiple objects selection (default true)

[show packages boolean] : (default true)

[open packages boolean] : (default false)

[key integer] : associate a key to the folder that the user will select. If no 'starting at' parameter is provided, assume the corresponding folder as the default folder.

→ list of alias : the chosen objects

navchoose volume v : choose volume with navigation services

navchoose volume

[with prompt string] : a prompt to be displayed in the folder chooser

[starting at alias] : the default folder

→ list of alias : the chosen folders

navask save v : prompt for save

navask save

[file name string] : name of the file

[action integer] : 1 = before closing, 2 = before quitting, 0 = none

→ integer : 1 save, 2 cancel, 3 don't save

navchoose file name v : Get a new file specification from the user, without creating the file. Uses navigation services

navchoose file name

[with prompt string] : the text to display in the file creation dialog box

[default name string] : the default name for the new file

[with menu list of string] : list of menu items

[menu index integer] : index of the menu item to display

[starting at alias] : the default folder

[show packages boolean] : (default true)

[open packages boolean] : (default false)

[key integer] : associate a key to the folder that the user will select, and assume the corresponding folder as the default folder.

file specification : the file the user specified

navnew folder v : Get a new folder specification from the user. Uses navigation services

navnew folder

[with prompt string] : the text to display in the file creation dialog box

[starting at alias] : the default folder

[open packages boolean] : (default false)

file specification : the folder the user specified

URL info for v : Parse an URL and returns an URL information record

URL info for string : an URL or an alias

URL information

absoluteURL v : resolve a relative URL using a base URL or coerce an absolute URL.

absoluteURL string or alias : a (possibly) relative URL. (Or a list of such.)

[from string or alias] : the base URL

[as type] : Unicode text, alias, unix path, path...

→ string : an absolute URL

Example
set f to path to library folder from local domain absoluteURL f --"file://localhost/Library/" absoluteURL "Application%20Support" from f --"file://localhost/Library/Application%20Support" absoluteURL "Application%20Support" from f as unix path --"/Library/Application Support" absoluteURL "/Library/Application Support" --"file://localhost/Library/Application%20Support" absoluteURL "Application%20Support" from f as alias absoluteURL "en/smile/index.html#top" from "http://www.satimage-software.com" "http://www.satimage-software.com/en/smile/index.html#top"

relativeURL v : translate an URL into the most suitable relative URL with respect to a given base.

relativeURL string or alias : an absolute URL

from string or alias : the base URL

→ string : a relative or absolute URL

list files v : make a list of the files contained in the folder

list files alias : a folder

[recursively boolean] : default: true. If false, list files and folders.

[invisibles boolean] : default: false

[of extension list of string] : the required file extension(s)

[not conforming to list of string] : the forbidden Universal Type Identifier(s) (UTI)

[after date] : list only files whose modification date is after the after date parameter

[before date] : list only files whose modification date is before the before date parameter

[names only boolean] : allowed only with recursively false. Default: false

[as type] : string (URL), alias, unix path, path...

→ list of string or list of alias

Example
set {f} to navchoose folder set x to list files f not conforming to {"public.image", "public.movie", "public.archive"} ¬ after ((get current date) - 3600) without recursively

glob v : list the files or the folders matching a unix pathname pattern

glob string : the pattern

[invisibles boolean] : default: false

[of extension string] : the required file extension(s)

[not conforming to string] : the forbidden Universal Type Identifier(s) (UTI)

[after date] : list only items whose modification date is after the after date parameter

[before date] : list only items whose modification date is before the before date parameter

[names only boolean] : default: false

[as type] : string (URL), alias, unix path, path...

→ list of string or list of alias

backup v : synchronizes 2 folders. backup will resolve the alias located at the first level in the source or destination folders, and no other alias.

backup file specification : the source folder

onto file specification : the destination folder

[level integer] : 0: report only, 1: synchronize folders, 2 : synchronize and report. Default 0.

[after date] : files older than this date are not considered.

[recursively boolean] : recursively synchronize subfolders. Default true.

[except folders list of string] : names of folders to be omitted

[except extensions list of string] : file extensions to be omitted

[only extensions list of string] : consider only these file extensions

→ string : the (optional) report

Resource Suite
Utilities to read and write resources from/to a file.

load resource v : get the resource of the given type and id from the specified file

load resource integer : index of the desired resource

type string : type of the desired resource

from alias : file to read from

[as type] : an AppleScript type for the returned result

anything : any AppleScript data that is stored in the resource: data, object specification, reference, etc.

list resources v : return the list of the ids of the resources of the specified type stored in the specified file

list resources type : type of desired resources

from file specification : file to read from

anything : the list of ids

get resource name v : return the name of the resource of the specified type and id from the specified file

get resource name integer : index of the desired resource

type type : type of the desired resource

from file specification : file to read from

→ string : the name of the resource

put resource v : write the given resource to the specified file with specified type and id

put resource anything : the AppleScript data that will be stored in the resource

to file specification : the destination file

type type : the resource type

index integer : the resource id

[with name string] : the resource name

Mathematical Functions
Some mathematical functions. Most functions support as their direct parameter (and return) a list or an array of real. Notice: you may need more parentheses than is intuitive. Ex: cos(a) - b returns cos(a - b), so you may want to write (cos(a)) - b.

abs v : absolute value of direct parameter

abs real

→ real

acos v : arc cosine of direct parameter

acos real : -1 <= x <= 1

→ real : in radians

acosh v : hyperbolic arc cosine of direct parameter

acosh real : a positive number

→ real

asin v : arc sine of direct parameter

asin real : -1 <= x <= 1

→ real : in radians

asinh v : hyperbolic arc sine of direct parameter

asinh real

→ real

atan v : arc tangent of direct parameter

atan real

→ real : in radians

atan2 v : the angle of the line whose direction is the vector (x , y)

atan2 list of real : 2 real numbers : y (ordinate) and x (abscissa)

→ real : in radians

atanh v : hyperbolic arc tangent of direct parameter

atanh real : -1 < x < 1

→ real

ceil v : round up

ceil real

→ real

cosh v : hyperbolic cosine of direct parameter

cosh real

→ real

cos v : cosine of direct parameter

cos real : the angle (in radians). If the angle is in degrees, multiply it by pi / 180 before taking the cosine.

→ real

erf v : the error function

erf real

→ real

erfc v : the complementary error function

erfc real

→ real

exp v : exponential of direct parameter

exp real

→ real

floor v : round down

floor real

→ real

gamma v : the gamma function

gamma real : a positive number

→ real

hypot v : the square root of the sum of the squares of its arguments

hypot list of real : 2 real numbers

→ real

lgamma v : base-e logarithm of the absolute value of gamma

lgamma real : a positive number

→ real

ln v : base-e logarithm of direct parameter

ln real : a positive real

→ real

log10 v : decimal logarithm of direct parameter

log10 real : a positive real

→ real

sin v : sine of direct parameter

sin real : the angle (in radians)

→ real

sinh v : hyperbolic sine of direct parameter

sinh real

→ real

sqr v : square of direct parameter

sqr real

→ real

sqrt v : square root of direct parameter

sqrt real : a positive number

→ real

tan v : tangent of direct parameter

tan real : the angle (in radians)

→ real

tanh v : hyperbolic tangent of direct parameter

tanh real

→ real

trunc v : round toward zero

trunc real

→ real

Arrays

array of real n, pl arrays of real : a packed list of real. Can be coerced to an AppleScript list with "as list of real" or "as list of integer". Conversely, a list of real may be translated using "as array of real" for fast computation.

list of real n, pl list of real : an abstract type provided to coerce arrays of real into list of real

list of integer n, pl list of integer : an abstract type provided to coerce arrays of real into list of integer

polynomial n : list of its coefficients, 0th degree first. Supports "as string" and "as list of real" coercions.


matrix n : An AppleScript representation of a 2D array of real numbers as a record:

properties

ncols integer : the number of columns

nrows integer : the number of rows

array of real array of real : the data, as an array of real or as a standard AppleScript list of real numbers. Ordering: the first numbers are the data for the first row.

Example
set m to {class:matrix, ncols:10, nrows:3, array of real:(createarray 3 * 10)}

fitrecord n : result of "fitpolynomial"

properties

fit error real : the mean error

fit result anything : the list of the coefficients (constant term first)

fit string string : the polynomial formula as text

statsrecord n : result of "statlist"

properties

maximum real

minimum real

sum real

mean real

variance real

stdev real

median real

skewness real

kurtosis real

maximum index integer

minimum index integer


createarray v : create an array of real

createarray integer : the requested size of the array

[range list of real] : {min,max}

array of real

Example
set x to createarray 10 range {2, 3} -- «data Lido4E6F74206120...»

creatematrix v : create an array of real of size ncols*nrows

creatematrix string : "1": array of 1.0, "x": array of x values, "y": array of y values, "d": diagonal square matrix

ncols integer : or a list of real with the "x" option, will make an array with identical rows

nrows integer : or a list of real with the "y" option, will make an array with identical columns

[range list of real] : a range {min,max} for the "x" and "y" options

[diagonal array of real] : the diagonal values for the "d" option. You can also provide a real, in which case the matrix dimensions are specified by ncols=nrows. Default: 1.0 (identity matrix).

[as type] : array of real or matrix, default: array of real

array of real : or matrix

Example
set x to creatematrix "x" ncols 12 nrows 15 --result is an array of real: «data Lido4E6F74206120...» set m to creatematrix "x" ncols 12 nrows 15 as matrix --result is a matrix: {class:matrix, ncols:12, nrows:15, array of real:«data Lido4E6F74206120...»} display (creatematrix "d" diagonal {1, 3, 5, 7, 9} as matrix) -- "1.0000000 0.0 0.0 0.0 0.0 0.0 3.0000000 0.0 0.0 0.0 0.0 0.0 5.0000000 0.0 0.0 0.0 0.0 0.0 7.0000000 0.0 0.0 0.0 0.0 0.0 9.0000000" set a to createarray 5 range {-1, 1} display (creatematrix "x" ncols a nrows 3 as matrix) -- "-1.0000000 -0.50000000 0.0 0.50000000 1.0000000 -1.0000000 -0.50000000 0.0 0.50000000 1.0000000 -1.0000000 -0.50000000 0.0 0.50000000 1.0000000" set a to createarray 4 range {0, 1} display (creatematrix "y" ncols 3 nrows a as matrix) -- "0.0 0.0 0.0 0.33333333 0.33333333 0.33333333 0.66666667 0.66666667 0.66666667 1.0000000 1.0000000 1.0000000"

randomarray v : create a random array of real

randomarray integer : the requested size of the array

[range list of real] : {min,max}

[seed integer]

array of real

Example
set x to randomarray 10 range {2, 3} seed 12345 -- «data Lido4E6F74206120...»

replacemissingvalue v : replace missing values (or NAN's) in a list, or an array of real, or a list of such.

replacemissingvalue array of real : or a list of arrays

with real

array of real : or a list of arrays

Example
set x to divlist 1 with ({-2, -1, 0, 1, 2} as array of real) set xx to replacemissingvalue x with "999" display xx -- "-0.50000000 -1.0000000 999.00000 1.0000000 0.50000000"

extractitem v : (obsolete: use extractarray instead)

extractitem integer

[thru integer]

[step integer]

in array of real

[blocksize integer]

[as type]

array of real

extractarray v : extract values from an array of real

extractarray array of real

[at integer] : the first item to read or a list of indexes (in which case, the "for", "step" and "blocksize" parameters are not taken into account). 1-based. Default 1

[for integer] : the number of blocks to read. If <0 then read as many blocks as possible. Default 1

[blocksize integer] : size of the block to read at each step. blocksize must be smaller than step

[step integer] : the interval between the beginnings of successive blocks to read. Must be larger than blocksize. Default: blocksize

[as type] : default is array of real, you can provide small real or real for 1 item

array of real

Example
set a to createarray 50 a as list of real -- {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, ...} set b to extractarray a for 3 at 1 step 10 blocksize 2 b as list of real -- {0.0, 1.0, 10.0, 11.0, 20.0, 21.0}

changearray v : change items in an array of real

changearray array of real : the array to modify

[at integer] : the index of the first item to change (1 based) or a list of indexes (in which case, the "step" and "blocksize" parameters are not taken into account). default: 1

into array of real : the new values

[blocksize integer] : size of the blocks to copy at each step. The "into" parameter must have a size multiple of blocksize. Default: 1

[step integer] : the interval between the beginnings of successive blocks to write. Must be larger than blocksize. Default: blocksize

array of real

Example
set a to createarray 50 set b to changearray a at 1 step 10 blocksize 2 into (createarray 6 range {-99, -99}) b as list of real -- {-99.0, -99.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, -99.0, -99.0, 12.0, 13.0, 14.0, ...}

insertarray v : insert items into an array of real

insertarray array of real : the values to insert

into array of real : the array to modify

[at integer] : the index of the first item to insert (0: at the beginning) or a list of indexes of the same size as the direct parameter (in which case, the "for", "step" and "blocksize" parameters are not taken into account). default -1 (insert values at the end)

[for integer] : number of blocks to insert. default 1

[step integer] : the number of values between each insertion. default 0

[blocksize integer] : size of the blocks to insert after each step. The direct parameter must have a size multiple of blocksize. Default: 1 if "for" is defined, else the size of the direct parameter.

array of real

Example
set a to createarray 30 set b to createarray 10 range {-10, -1} set c to insertarray b blocksize 2 into a step 5 at 1 for 3 c as list of real -- {0.0, -10.0, -9.0, 1.0, 2.0, 3.0, 4.0, 5.0, -8.0, -7.0, 6.0, 7.0, 8.0, 9.0, 10.0, -6.0, -5.0, 11.0, 12.0, ...}

resamplematrix v : resample a matrix. The incoming matrix is divided into rectangular blocks. Each block may be replaced by its mean value or by another statistical value.

resamplematrix matrix : the matrix to resample

blocksize list of integer : {i,j}, defines the horizontal and vertical sizes of the blocks used for resampling. i and j may be integers (identical blocks) or lists of integers (irregular grid, the items of the lists define the successive sizes of the blocks).

[wanted string] : the following strings or a list of such: "mean", "minimum", "maximum", "stdev", "missing value", "sum", "median", "dispersion". Specify the statistical function computed on each block. Default: "mean".

matrix : the resampled matrix, or a list of matrices if 'wanted' is a list. The dimensions of the resampled matrix correspond to the numbers of blocks defined with 'blocksize'.

Example
set m to ArrayToMatrix(randomarray 10 * 9, 10, 9) -- a 10x9 random matrix set {m1, m2} to resamplematrix m blocksize {5, 3} wanted {"mean", "stdev"} -- result is a list of two 2x3 matrices

reversearray v : returns reverse of the direct parameter.

reversearray list of real : ... or an array of real

array of real

Example
(reversearray {1, 2, 3}) as list of real -- {3.0, 2.0, 1.0}

multlist v : performs the product of the parameters. Each parameter may be a list, an array of real, a matrix or a number. multlist {x1,x2...} with {y1,y2...} returns {x1.y1, x2.y2, ...}; multlist x with {y1,y2...} returns {x.y1, x.y2, ...}

divlist v : same as multlist, but for quotient

addlist v : same as multlist, but for sums

sublist v : same as multlist, but for subtraction

runningsum v : returns the running sum of an array of real

runningsum array of real

array of real

Example
(runningsum {1, 2, 3, 4}) as list of real -- {1.0, 3.0, 6.0, 10.0}

statlist v : returns as a record the min, max, min index, max index, mean, sum, standard deviation, variance.

statlist list of real : ... or an array of real

[kurtosis boolean] : if true, statlist compute also skewness, kurtosis and median calculations.

statsrecord

Example
set stl to statlist (randomarray 100) with kurtosis -- {maximum:0.993787646526, maximum index:60, minimum:0.001816140488, minimum index:31, sum:45.616940173553, mean:0.456169401736, variance:0.071985153475, stdev:0.268300491007, missing value:0, skewness:0.100799135751, kurtosis:1.791678255678, median:0.45719872578} mean of stl -- 0.456169401736

histogram v : given an array of real numbers, return a list of 2 arrays : {sampling values,frequencies}

histogram array of real

samples integer : number of intervals

[minimum real] : lower bound of the intervals

[maximum real] : upper bound of the intervals

→ list of array of real : {sampling values,frequencies}

Example
set {x, y} to histogram (randomarray 100 range {1, 10}) samples 10 set c to QuickCurve(x, y, 0) set properties of c to {pattern style:10, line style:0, histogram bar width:0.75} set limits of container of c to {0, 11, 0, 20} draw window of c

evalformula v : apply C-like mathematical expressions to arrays of real. Ex: evalformula "a*x^2+y^2" with {"a",2.4,"x",anarray,"y",anotherarray} (or by using a record: evalformula "a*x^2+y^2" with {a:2.4,x:anarray,y:anotherarray})

evalformula string : the formula to compute

with list or record : the definition of the variables occurring in the formula. If a list, an alternation of reference names (strings) and data (number, list of numbers or array of real). Prefer lists because you can't use reserved words with records.

as type : matrix or array of real: the requested type if parameters are matrices. Default: array of real

array of real : or real

Example
set a to createarray 10000 range {0, 2*pi} set s2 to evalformula "2*cos(x)*sin(x)" with {"x", a} evalformula ("atan2(y,x)") with {y:sqrt (3), x:1} -- 1.047197551197 (that is, pi/3) evalformula ("norm(cos(x))/sqrt(count(x))") with {"x", randomarray 10000 range {0, 2 * pi}} -- 0.701118610115 (that is, ~1/sqrt(2)) set n1 to 100 set x1 to creatematrix "x" ncols n1 nrows n1 range {-1, 1} as matrix set y1 to creatematrix "y" ncols n1 nrows n1 range {-1, 1} as matrix set {px, py} to {1,0} set pot1 to evalformula "r=hypot(x,y);(px*x+py*y)/(r*r*r)" with {"px",px, "py",py, "x",x1, "y",y1} as matrix set s to QuickScalarMap(0, 0, pot1, 0) set limits of s to {-10, 10} draw window of s

Discussion
  • The expression of evalformula may include logical operators, yet all values remain real numbers: true expressions evaluate to 1.0, false expressions evaluate to 0.0. Conversely when implied in a logical expression any non null number is considered as true (1.0).
  • The direct parameter of evalformula may be a sequence of elementary expressions, provided they are separated with semi-colon ;. You can also use return as the separator, so in complex cases when the expression may require several intermediate steps you can easily use the contents of a text window as the expression. When you use such a composite construct evalformula will return the result of the last (rightmost) expression.
  • Instead of one expression you can pass a list of expressions to evalformula: evalformula will return a list of arrays of real.
  • Here is the list of the operators and functions that evalformula supports.
    operators (higher precedence first)
    • - (unary)
    • * /, + -, ^ (exponentiation)
    • >= > <= <== != (equal - not equal), & (logical AND), | (logical OR), ! (boolean not, evaluates to 1 if the operand is 0 and to 0 otherwise).
    algebra
    • sqr, sqrt, hypot, pow
    • abs, ceil, floor, trunc, max, min
    • mod (modulo), remainder
    • isnan (test whether the quantity is a ``NAN''. NAN = Not A Number.)
    transcendental
    • ln or log (neperian), log10, exp
    • cos, sin, tan, acos, asin, atan, atan2 (atan2(y,x))
    • cosh, sinh, tanh, acosh, asinh, atanh
    • erf, erfc, gamma, lgamma
    functions on arrays
    • norm and norm2, respectively the euclidian norm and its square (numbers),
    • sum and runsum, respectively the sum (a number) and the running sum (an array),
    • count, the number of elements (a number).

maskarray v : suppress items (or rows) out of an array of real (or a matrix) with respect to a mask of 0's and 1's.

maskarray array of real : the array(s) or matrix to be filtered. For a matrix, the rows are deleted.

with array of real : the filter: an array of real, 0's mean that the corresponding items are to be deleted in the direct object(s).

array of real : the resulting array(s) or matrix

Example
set x to randomarray 10 range {1, 2} set m to evalformula "(x<1.2)|(x>1.5)" with {x:x} set y to maskarray x with m count y -- 6

filter v

filter matrix

using array of real : a list of 9 real numbers representing the 3x3 convolution matrix

[reduced boolean] : the resulting matrix is smaller (the 2 extremal columns and rows are removed. Default true.)

matrix

evalpolynomial v

evalpolynomial list of real : the polynomial, given as the list of its coefficients, 0th degree (constant term) first. Or an array of real coerced with "as polynomial"

at real : or array of real

→ real

Example
set x to runningsum (randomarray 10) set y to runningsum x set p to fitpolynomial {x, y} degree 3 evalpolynomial (fit result of p) at 1 -- 2.364091741891

roots of v

roots of list of real : the polynomial, given as the list of its coefficients, 0th degree (constant term) first

[complex boolean] : default : false. Also compute the complex roots

list of real : roots of the polynomial. Complex roots are returned as a list of 2 real numbers

Example
set x to runningsum (randomarray 10) set y to runningsum x set p to fit result of (fitpolynomial {x, y} degree 3) set {xx} to roots of p evalpolynomial p at xx -- -5.6843418860808E-14

composepolynomial v : you can provide arrays of real instead of polynomials

composepolynomial polynomial : or an array of real: the polynomial P(X), given as the list of its coefficients, 0th degree (constant term) first.

with polynomial : Q(X)

polynomial : P(Q(X))

pade approximant v : given a polynomial P(X), compute the Padé approximant as the rational function NUM(X)/DEN(X). NUM and DEN are polynomials and the constant term of DEN is 1. syn pade

pade approximant polynomial : or an array of real: the polynomial P(X), given as the list of its coefficients, 0th degree (constant term) first.

numerator integer : the requested degree for NUM(X)

denominator integer : the requested degree for DEN(X)

→ list of polynomial : {NUM(X), DEN(X)}

fitpolynomial v : given two arrays of real {x,y} returns the best polynomial fit y=P(x)

fitpolynomial list of array of real : a list of two arrays of real {x,y}

degree integer : the degree of the resulting polynomial

[number formatting string] : the format string for the formula output. If you don't specify this parameter, no fit string will be provided in the result record.

fitrecord

Example
set x to runningsum (randomarray 10) set y to runningsum x fitpolynomial {x, y} degree 3 number formatting "%.3g" -- {fit error:0.66209535022, fit result:{2.229178877341, -2.581992766564, 2.069751651722, -0.112828845472}, fit string:"2.23-2.58*x+2.07*x^2-0.113*x^3"}

fitrational v : given two arrays of real {x,y} returns the best rational fit y=NUM(x)/DEN(x). NUM and DEN are polynomials and the constant term of DEN is 1.

fitrational list of array of real : a list of two arrays of real {x,y}

numerator integer : the requested degree for NUM(X)

denominator integer : the requested degree for DEN(X)

[number formatting string] : the format string for the formula output. If you don't specify this parameter, no fit string will be provided in the result record.

fitrecord : where fit result if a list of 2 polynomials.

read binary v : read a file of real or small real

read binary file specification : the file

as type : the format of the data file: real (8 bytes), small real (4 bytes), integer (4 bytes), small integer (2 bytes), or byte (1 byte)

[skip integer] : the number of leading bytes to skip

[step integer] : the offset between two consecutive readings

[blocksize integer] : the size of the blocks in the "as" unit. Default 1

[length integer] : the number of blocks to read

[big endian boolean] : is the file encoded as big endian or little endian? Default: system endianess (false on mac intel).

[signed boolean] : Only for integer types. Are they signed or unsigned? Default: true.

array of real

write binary v : write the data into a binary file (encoded as big endian)

write binary file specification : the file

with data array of real

[starting at integer] : offset in bytes, default: append data at the end of the file

[as type] : the format of the data to be saved: real (8 bytes), small real (4 bytes), integer (4 bytes), small integer (2 bytes), or byte (1 byte). Default: real.

[big endian boolean] : is the file encoded as big endian or little endian? Default: system endianess (false on mac intel).

Array and List Utilities

sortlist v : sort a list of numbers (or array of real) or a list of strings (case sensitive) or a list of dates. Can also sort a list of lists: lists are sorted either asynchronously or synchronously if the 'with respect to' parameter is specified. Sortlist is stable. syn sortarray

sortlist list of anything : the list to sort (or a list of lists)

[with respect to integer] : rank of the list used as the sort criterion. Relevant only if the direct parameter is a list of lists: requests a synchronous sort. If this parameter is not specified, each list is sorted separately. This parameter may be a list of integer corresponding to a list of criteria in decreasing priority order

[ascending boolean] : default true. May be a list if "with respect to" is already a list.

[remove duplicates boolean] : if true, remove duplicate values. Default false

[comparison integer] : only relevant for list of string. 1 case insensitive, 2 compare numerically, 1+4 force ordering ('A'<'a'<'B'). Default 0

→ list of anything : the sorted list (or lists)

Example
sortlist (randomarray 10) -- «data Lido4E6F74206120...» (sortlist {2, 5, 1, 3} without ascending) as list of real -- {5.0, 3.0, 2.0, 1.0} sortlist {"abc", "ABC", "xyz", "123"} -- {"123", "ABC", "abc", "xyz"} sortlist {{1, 2, 3, 4}, {"abc", "ABC", "xyz", "123"}, createarray 4, {{a:1}, "b", 3, {1, 2, 3}}} with respect to 2 -- {{4, 2, 1, 3}, {"123", "ABC", "abc", "xyz"}, «data Lido4E6F74206120...», {{1, 2, 3}, "b", {a:1}, 3}} -- compare numerically: sortlist {"a1", "a10", "a2", "1b", "10b", "2b"} -- {"10b", "1b", "2b", "a1", "a10", "a2"} sortlist {"a1", "a10", "a2", "1b", "10b", "2b"} comparison 2 -- {"1b", "2b", "10b", "a1", "a2", "a10"}

masklist v : suppress items out of a list with respect to a mask of 0's and 1's. See also 'suppress item'

masklist list of any : the list to be filtered.

with array of real : the filter: an array of real, or a list of integers, 0's mean that the corresponding items are to be deleted in the direct object(s).

→ list of any : the resulting list

Example
masklist {"abc", {a:1}, "b", 3, {1, 2, 3}} with {1, 0, 1, 1, 0} -- {"abc", "b", 3}

suppress item v : delete a list of items from a list or a record.

suppress item anything : a list of indices or a list of keywords. Use quotes around custom properties, and also around 4-characters codes. (If you don't know what this means, you don't need it).

from list or record

→ list or record : according to the "from" parameter

Example
suppress item 2 from {"abc", {a:1}, "b", 3} -- {"abc", "b", 3} suppress item name from {path name:1, name:"abc"} -- {path name:1} suppress item {2, 3} from {"abc", {a:1}, "b", 3} -- {"abc", 3}

exclude items v : remove strings from a list of strings. A list equivalent of the set difference.

exclude items list of string : the list of strings to remove from the input list

from list of string : the input list

[with respect to integer] : rank of the list (of string) used for the filter process. Other input lists may be lists of anything. Relevant only if the 'from' parameter is a list of lists. Default: 1

[case sensitive boolean] : default true

→ list : the cleaned input list, or a list of cleaned lists if the 'from' parameter is a list of lists.

Example
exclude items {"r", "t", "z"} from {"a", "z", "e", "r", "t", "y"} -- {"a", "e", "y"} exclude items {"r", "t", "z"} from {{"a", "z", "e", "r", "t", "y"}, {1, 2, 3, 4, 5, 6}, {"one", "two", "three", "four", "five", "six"}} -- {{"a", "e", "y"}, {1, 3, 6}, {"one", "three", "six"}}

keep items v : remove strings from a list of strings. A list equivalent of the set intersection.

keep items list of string : the list of the strings to keep

from list of string : (or list of list). The input list

[with respect to integer] : rank of the list (of string) used for the filter process. Other input lists may be lists of anything. Relevant only if the 'from' parameter is a list of lists. Default: 1

[case sensitive boolean] : default true

→ list : the cleaned input list, or a list of cleaned lists if the 'from' parameter is a list of lists.

Example
keep items {"r", "t", "z"} from {"a", "z", "e", "r", "t", "y"} -- {"z", "r", "t"} keep items {"r", "t", "z"} from {{"a", "z", "e", "r", "t", "y"}, {1, 2, 3, 4, 5, 6}, {"one", "two", "three", "four", "five", "six"}} -- {{"z", "r", "t"}, {2, 4, 5}, {"two", "four", "five"}}

special concat v : concatenate {a_ppty:X, …} and {a_ppty:Y, …} into {a_ppty:Z, …}, where Z is X & Y (resp. X + Y) if X,Y are lists (resp. numbers). Also merges tabulated string arrays side to side (in other terms, adds columns).

special concat record : the record

with record : the additional data

→ record

Example
special concat {a:1, b:{1}, c:"A", d:0} with {a:2, b:{2}, c:"B"} -- {a:3.0, b:{1, 2}, c:"A", d:0} special concat ("1" & tab & "2" & return & "A" & tab & "B") with ("3" & return & "C") -- "1 2 3 A B C "