HyperMath

System Operations

System Operations

Previous topic Next topic Expand/collapse all hidden text  

System Operations

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  
hmtoggle_plus1greyassert

Returns an error if the expression is false.

Syntax

assert(T)

assert(T, msg)

Arguments

Name

Description

 

T

A Boolean.

 

msg

A string.  An error returned if T is false.  If it is missing, it defaults to "assertion failed!"

Example

Syntax

 

assert(true)

assert(false)

assert(1 == 1)

assert(1 == 0, 'my error')

Comments

assert(T) returns an error if met is false.

See Also:

pcall

hmtoggle_plus1greycd

Changes the current working folder.  It returns nil upon failure.

folder

A string of the folder name.  Folders must be separated by a forward slash (/) or (\\).

hmtoggle_plus1greyChdir(folder)

Changes the current working folder.  It returns nil upon failure.

folder

A string of the folder name.  Folders must be separated by a forward slash (/) or (\\).

hmtoggle_plus1greycopyfile

Copies a file (or directory) to the destination file (or directory).

Syntax

copyfile(source_file, destination_file)

Argument

Name

Description

 

source_file

A string: a file or a directory name to copy.

 

destination_file

A string: a file or a directory name as the destination.

If the source is a directory, the destination need to be a directory.

Outputs

Name

Description

See Also

Remove

Rename

unix

hmtoggle_plus1greyCpuTime

Returns an approximation of the amount (in seconds) of CPU time used by the application on the Windows operating system. On Linux, the time is the total execution time of the last command or scripts.

hmtoggle_plus1greyDate()

Returns the date and time in a string.

hmtoggle_plus1greyDiffTime(t2, t1)

Returns the number of seconds from time t1 to time t2.  The two time variables are assumed to be in seconds.

hmtoggle_plus1greyDir([folder], [match])

Returns an array of tables containing the directory listing information.  Each table contains three fields: name, date, and bytes, which carry the name, date, and size, respectively.  If no argument is supplied, the current directory listing is returned.  The table is empty if the directory is empty.  If the directory does not exist, the returned value is nil.

folder

A string of the directory name. Directories must be separated by a forward slash, (/).

match        

A matching string to limit the listing information to. It can include the wildcard character ‘*’.

hmtoggle_plus1greyerror

Generates an error in HyperMath and displays an error message.

Syntax

error(str)

Arguments

Name

Description

 

str

A string: the error message to return.

Example

Syntax

 

function foo(n)

  if n < 0 then

   error('a positive value expected.')

  end

  return n * n;

end

 

 foo(-1)

 foo(2)

 

Result

 

// foo(-1)

[string " function foo(n)..."]:3: a positive value expected.

Comments

The error function stops the current script execution and displays an error message.

See Also:

assert

pcall

hmtoggle_plus1greyexit

Closes HyperMath.

Syntax

exit()

Example

Syntax

 

// WARNING : it will close this session

exit()

Comments

exit() ends the current HyperMath session.

hmtoggle_plus1greyfileparts

Returns the folder, filename and extension of a filename.

Syntax

path_f, file_f, ext_f = fileparts(filename)

Argument

Name

Description

 

filename

A string of a file or a directory.

Outputs

Name

Description

 

path_f

A string: the path.

 

file_f

A string: the filename.

 

ext_f

A string: the extension.

Example

Syntax

 

print(fileparts('c:/Windows'))

pathf, namef, extf = fileparts('c:\\dir\\file.ext')

print(pathf, namef, extf)

Comments

path_f, file_f, ext_f = fileparts(filename) splits filename into three parts: path, filename and its extension (including '.').

fileparts only parses the input string and performs no existence checks.

See Also:

isdir

isfile

hmtoggle_plus1greyGetCwd(separator)

Returns a string containing the current working directory.

separator

An optional string used as a directory separator in the output. The default is a forward slash, (/).

hmtoggle_plus1greyGetEnvVar(var)

Gets the system environment variable value.

var

A string of the environment variable name.  Returns nil if variable is not defined.

The following gets the system variable value ALTAIR_HOME.

GetEnvVar("ALTAIR_HOME")

hmtoggle_plus1greygetpid

Get the current process identifier of HyperMath.

Syntax

id = getpid()

Outputs

Name

Description

 

id

A number.

Example

Syntax

 

print(getpid())

See Also:

memory

hmtoggle_plus1greygetuserdir

Returns the user home directory.

Syntax

p = getuserdir()

Outputs

Name

Description

 

p

A string: the path of the user home directory.

Example

Syntax

 

print(getuserdir())

See Also:

cd

hmtoggle_plus1greyisdir

Checks if the string input argument is a directory or not.

Syntax

R = isdir(A)

Argument

Name

Description

 

A

A string.

Outputs

Name

Description

 

R

0 (false) or 1 (true) if the string is an existing path.

Example

Syntax

 

print(isdir('/'))

print(isdir('c:/'))

print(isdir('c:/Windows'))

Comments

R = isdir(A) returns logical 1 (true) if A is a valid folder.

It returns logical 0 (false) otherwise.

See Also:

isfile

hmtoggle_plus1greyisfile

Checks if the input argument is an existing file.

Syntax

R = isfile(A)

Argument

Name

Description

 

A

A string.  A filename.

Outputs

Name

Description

 

R

0 (false) or 1 (true) if the string is an existing filename.

Example

Syntax

 

print(isfile('c:/Windows'))

Comments

R = isfile(A) returns logical 1 (true) if A is an existing filename.

It returns logical 0 (false) if the file does not exist.

See Also:

isdir

hmtoggle_plus1greymemory

Retrieves memory information.

Syntax

total_mem_used, total_mem_available, mem_used_by_hypermath = memory()

Argument

Name

Description

 

total_mem_used

Total physical memory used (kilobytes).

 

total_mem_available

Total physical memory available (kilobytes).

 

mem_used_by_hypermath

Memory used by HyperMath in the current session (kilobytes).

Example

Syntax

 

total_mem_used, total_mem_available, mem_used_by_hypermath_1 = memory();

print('Memory used by Hypermath:', mem_used_by_hypermath_1/1024, ' MB');

M = ones(9000,9000);

total_mem_used, total_mem_available, mem_used_by_hypermath_2 = memory();

print('Memory used by Hypermath:', mem_used_by_hypermath_2/1024, ' MB');

Clear('M');

total_mem_used, total_mem_available, mem_used_by_hypermath_3 = memory();

print('Memory used by Hypermath:', mem_used_by_hypermath_3/1024, ' MB');

print('Physical memory on your system: ', total_mem_available/1024, ' MB');

hmtoggle_plus1greyMkdir(folder)

Creates a new folder. It returns nil upon failure.

folder

A string of the folder name.  Folders must be separated by a forward slash (/) or (\\).

hmtoggle_plus1greypwd

Gets the current directory.

Syntax

p = pwd()

p = pwd(sep)

Argument

Name

Description

 

sep

A string: '/' or '\\'.  An optional string used as a directory separator in the output.

Outputs

Name

Description

 

p

A string: the current path.

Example

Syntax

 

print(pwd())

print(pwd('/'))

print(pwd('\\'))

Comments

p = pwd() returns a string containing the current working directory.

See Also:

Chdir

hmtoggle_plus1greyRemove(item)

Removes a file. It returns nil plus an error message upon failure.

item

A string of the folder name.

Comments

To remove a directory, see Rmdir.

hmtoggle_plus1greyRename(old, new)

Renames a file or folder. It returns nil plus an error message upon failure.

old

A string of the current file or folder name.  Folders must be separated by a forward slash (/) or (\\).

new

A string of the new file or folder name.  Folders must be separated by a forward slash (/) or (\\).

hmtoggle_plus1greyRmdir(folder, s)

Deletes the folder. The folder must be empty.  It returns nil upon failure.

folder

A string of the folder name.  Folders must be separated by a forward slash (/).

s

Removes a folder which contains sub-folders.

hmtoggle_plus1greySetEnvVar(expression)

Sets the system environment variable value.  It returns nil upon failure.

expression

A string of the environment variable setting command.  Spaces should not precede the equal sign.

The following sets the system variable value TEST to This Is A test.

SetEnvVar("TEST= This Is A Test")

hmtoggle_plus1greySystem(command)

Passes a command to be executed by an operating system shell. Returns non-zero upon failure.

command

Any system command as a string. Folders must be separated by a forward or backward slash, (/) or (\\).

The following executes the system command to set the time.

System("time")

hmtoggle_plus1greyTime

Get the current time in seconds since the Epoch.

Syntax

t = Time()

Argument

Name

Description

 

t

A number: current time since the Epoch (seconds).

Example

Syntax

 

t1 = Time();

print(t1);

sleep(10);

t2 = Time();

print(t2)

print('t2 - t1 = ', t2 - t1)

Comments

t = Time() returns the current time in seconds since the Epoch.