vipsi - the built-in words
Author: kio@little-bat.de
Keywords: vipsi shell script interpreter programming

# vipsi - shell and script language

## the built-in words

### numeric functions

functions which return numeric (incl. boolean) values.

#### mdate

    mdate filename

get modification date of file. yields a numeric value.

#### count

    count text|list

querry number of elements in text or list.

#### index

    index value

get position of item in list.

#### random

    random num_value

get a random number in range [0 … [n (float!)

#### abs

    abs num_value

unsigned, absolute value of numeric value.

#### sign

    sign num_value

sign of numeric value.

#### int

    int num_value

integral part of numeric value.

#### fract

    fract num_value

fractional part of numeric value.

#### round

    round num_value

round to nearest. xx.5 rounds upwards.

#### cos

    num_value = cos num_value

cosinus of angle. full circle = 2*pi.

#### sin

    num_value = sin num_value

sinus of angle. full circle = 2*pi.

#### tan

    num_value = tan num_value

tangens of angle. full circle = 2*pi.

#### acos

    num_value = acos num_value

angle from cosinus. result range: 0 … +pi.

#### asin

    num_value = asin num_value

angle from sinus. result range: -pi/2 … +pi/2.

#### atan

    num_value = atan num_value

angle from tangens. result range: -pi/2 … +pi/2.

#### cosh

    num_value = cosh num_value

cosinus hyperbolicus. example?

#### sinh

    num_value = sinh num_value

sinus hyperbolicus. example?

#### tanh

    num_value = tanh num_value

tangens hyperbolicus. example?

#### logn

    num_value = logn( num_value1, num_value2 )

logarithm of number 2 to base number 1. e.g.: `logn(16,256) = 2.`

#### log2

    num_value = log2 num_value

logarithm of number to base 2. e.g.: `log2(4) = 2.`

#### loge

    num_value = loge num_value

logarithm of number to base e. e.g.: `loge(e*e) = 2.`

#### log10

    num_value = log10 num_value

logarithm of number to base 10. e.g.: `log10(100) = 2.`

#### exp

    num_value = exp( num_value1, num_value2 )

number 1 raised to the power of number 2. e.g. `exp(16,2) = 256.`

#### exp2

    num_value = exp2 num_value

2 raised to the power of number. e.g. `exp2(3) = 8.`

#### expe

    num_value = expe num_value

e raised to the power of number. e.g.: `expe(2) = e*e.`

#### exp10

    num_value = exp10 num_value

10 raised to the power of number. e.g.: `exp10(2) = 100.`

#### square

    num_value = square num_value

number * number. e.g.: `square 5 = 25.`

#### sqrt

    num_value = sqrt num_value

square root of number. e.g.: `sqrt 25 = 5.`

#### charcode

    num_value = charcode text_value

convert first character in text to character code number. e.g.: `charcode "€" = 8364.`

#### now

    num_value=now

get system time. returns local time in seconds incl. a fractional part. time base may vary!

e.g.

        log"current date and time = ",datestr(now),nl;
        var a=0,t0=now; do while ++a<100000; loop; put "time=",now-t0;

#### dateval

    num_value = dateval text_value

convert readable date text to numeric format.

e.g.:

        dateval "2002-04-01 12:00" = 1017658800.
        dateval "2002.04"          = 1017529200.

#### find

    number = find ( text1, text2 [,number3] )

find first occurance of text 2 in text 1, optionally starting search at index number 3. returns index of position found or 0. indexes start at 1. search starts at index number 3 inclusive.

e.g.:

        find ( "hello world", "l" )     = 3
        find ( "hello world", "X" )     = 0
        find ( "hello world", "ll" )    = 3
    	find ( "hello world", "l",  6 ) = 10
    	find ( "hello world", "l",  4 ) = 4
    	find ( "hello world", "ll", 4 ) = 0
    	find ( "hello world", "ll", 3 ) = 3
    	find ( "hello world", "ll", 2 ) = 3

#### rfind

    number = rfind ( text1, text2 [, number3] )

find last occurance of text 2 in text 1, optionally starting search at index number 3. returns index of position found or 0. indexes start at 1. search starts at index number 3 inclusive.

e.g.:

        rfind ( "hello world", "l" )     = 10
        rfind ( "hello world", "X" )     = 0
        rfind ( "hello world", "ll" )    = 3
    	rfind ( "hello world", "l",  6 ) = 4
    	rfind ( "hello world", "l",  4 ) = 4
    	rfind ( "hello world", "ll", 4 ) = 3
    	rfind ( "hello world", "ll", 3 ) = 3
    	rfind ( "hello world", "ll", 2 ) = 0

#### istext

    num_value = istext value

test whether expression is a text value.

e.g.: `istext("foo") = 1; istext({}) = 0.`

#### isnumber

    num_value = isnumber value

test whether expression is a numeric value.

e.g.: `isnumber(1+2) = 1; isnumber({}) = 0.`

#### islist

    num_value = islist value

test whether expression is a list.

e.g.: `islist({1,2}) = 1; islist(12) = 0.`

#### isproc

    num_value = isproc value

test whether expression is a user-defined procedure.

e.g.: `proc foo(){}; isproc(foo) = 1; isproc("foo") = 0.`

#### isfile

    num_value = isfile text_value

test whether path refers to a file.

e.g.: `var a = isfile("~/bin/vipsi");`

#### isdir

    num_value = isdir text_value

test whether path refers to a directory.

e.g.: `isdir("/") = 1; isdir("") = 0.`

#### exists

    num_value = exists variable

test whether variable exists.

e.g.: `var a={1,2,3}; exists a[3] = 1; exists a[5] = 0.`

#### match

    num_value = match( text_value1, text_value2 [,num_value] )

test whether text 1 matches pattern in text 2. returns boolean value: 0 (no) or 1 (yes).

the optional flag consists of 4 bits:

        1 = enable backslash escaping
        2 = directory separators must match directly
        4 = initial dot in each file or directory must match directly
        8 = compare case-insensitive

#### min

    number = min ( number1 [, number2, …] )
    text   = min ( text1 [, text2, …] )
    number = min ( list /*of numbers*/ )
    text   = min ( list /*of texts*/ )

return the smallest of the supplied values. the returned result may be a variable reference. if a list is passed as single argument, then a reference to the smallest list item is returned. compared values must be of the same type. comparing different data types or supplying a list which contains items of different data type will raise an error. if two values are equal, the first is returned.

e.g.:

        a = min(a,99)
        put min( {1,6,3,4} )
        min(a,b,c) = 0
        put name( min(a,b) )
        if min(my_list)!=my_list[1] put "the list seems to be not sorted" then
        put min("Anton", "Berta", "Cicero")

#### max

    number = max ( number1 [, number2, …] )
    text   = max ( text1 [, text2, …] )
    number = max ( list /*of numbers*/ )
    text   = max ( list /*of texts*/ )

return the largest of the supplied values. the returned result may be a variable reference. if a list is passed as single argument, then a reference to the largest list item is returned. compared values must be of the same type. comparing different data types or supplying a list which contains items of different data type will raise an error. if two values are equal, the first is returned.

e.g.:

        put max( {1,6,3,4} )
        max(a,b,c) = 0
        put name( max(a,b) )
        if max(my_list)!=my_list[count my_list] put "the list seems to be not sorted" then
        put max("Anton", "Berta", "Cicero")