Default implementation values and functions.

Note:

Argument surrounded in "[" and "]" is not required.

Example:
(func arg1 arg2 [arg3])
arg1 and arg2 are required, you must specify them. arg3 is not required, you can omit it.

return to clCalc

Constance value

version

Syntax
version
Description

This value is string of current version. String is expressed by date of release current version.

This symbol defined different value every version of application.

Sample
version => "2012-12-24"

e

Syntax
e
Description
This value is number of Napier's constant.
Sample
e => 2.718281828459045

pi

Syntax
pi
Description
This value is π.
Sample
pi => 3.141592653589793

t

Syntax
t
Description
Value means "true", this value used by result of expression usually.
Sample
t => T
't => T
(= (- 3 2) 1) => T

nil

Syntax
nil
Description

Value means "false" or "no value", this value used by result of expression usually.

Empty list is evaluated to equals to nil.

Sample
nil => NIL
'nil => NIL
(= (+ 1 2) 1) => NIL
'() => NIL
(car '()) => NIL
(cdr '(5)) => NIL
to Top return to clCalc

Basic operator

+ - * /

Syntax
(+ NUMBER [NUMBER] ...)
(- NUMBER [NUMBER] ...)
(* NUMBER [NUMBER] ...)
(/ NUMBER [non_zero_NUMBER] ...)
Description
Basic operators that Add, Sub, Mul, and Div. This functions require more 1 arguments. Division operator must not specify 0 than second paramter.
Sample
(+ 1 2 3) => 6
(- 5 2) => 3
(* 2 2 2 2) => 16
(/ 8 2) => 4
(+ (* 3 3) (* 4 4)) => 25

%

Syntax
(% NUMBER NUMBER)
Description
This function returns surplus that 1st argument divided by 2nd argument. 2nd argument must not set 0.
Sample
(% 5 3) => 2
(% 4 7) => 4

if

Syntax
(if EXPRESSION TRUE-CASE [FALSE-CASE])
Description

This function evaluate EXPRESSION. If evaluated result is not NIL, returns result of evaluate TRUE-CASE.

If result is NIL and specify FALSE-CASE, returns evaluated result of FALSE-CASE. If result is NIL and not specify FALSE-CASE, returns NIL.

Sample
(if (= 3 3) "TRUE" "FALSE") => "TRUE"
(if (< (+ 3 2) 4) -1 1) => 1
(if (= (+ 1 2 3) 10) 100) => NIL

not

Syntax
(not EXPRESSION)
Description
This function invert logical expression. If EXPRESSION is NIL, returns T. is not NIL, returns NIL.
Sample
(not T) => NIL
(not NIL) => T
(not 0) => NIL
(not "") => NIL
(not '()) => T

=

Syntax
(= EXPRESSION1 EXPRESSION2)
or
(eq EXPRESSION1 EXPRESSION2)
Description
Compare 2 expression and returns T if results is equal. IF not equal, returns NIL.
Sample
(= 1 1) => T
(= 1 2) => NIL
(= (+ 1 2 3) 6) => T
(= "1" 1) => NIL

/=

Syntax
(/= EXPRESSION1 EXPRESSION2)
Description
Compare 2 expression and returns T if results is not equal. IF equal, returns NIL.
Sample
(/= 1 1) => NIL
(/= 1 2) => T
(/= (+ 1 2) (+ 2 3)) => T
(/= "1" 1) => T

<

Syntax
(< EXPRESSION1 EXPRESSION2)
Description
Compare 2 expression and returns T if EXPRESSION1 is smaller than EXPRESSION2. Expressions must number or string, and must same type.
Sample
(< 1 3) => T
(< 2 2) => NIL
(< 4 2) => NIL
(< "A" "C") => T
(< "D" "C") => NIL
(< "A" "a") => T
(< "a" "C") => NIL

>

Syntax
(> EXPRESSION1 EXPRESSION2)
Description
Compare 2 expression and returns T if EXPRESSION1 is larger than EXPRESSION2. Expressions must number or string, and must same type.
Sample
(> 1 3) => NIL
(> 2 2) => NIL
(> 4 2) => T
(> "A" "C") => NIL
(> "D" "C") => T
(> "A" "a") => NIL
(> "a" "C") => T

<=

Syntax
(<= EXPRESSION1 EXPRESSION2)
Description
Compare 2 expression and returns T if EXPRESSION1 is same value or smaller than EXPRESSION2. Expressions must number or string, and must same type.
Sample
(<= 1 3) => T
(<= 2 2) => T
(<= 4 2) => NIL
(<= "A" "C") => T
(<= "D" "C") => NIL
(<= "A" "a") => T
(<= "a" "C") => NIL

>=

Syntax
(>= EXPRESSION1 EXPRESSION2)
Description
Compare 2 expression and returns T if EXPRESSION1 is same value or larger than EXPRESSION2. Expressions must number or string, and must same type.
Sample
(>= 1 3) => NIL
(>= 2 2) => T
(>= 4 2) => T
(>= "A" "C") => NIL
(>= "D" "C") => T
(>= "A" "a") => NIL
(>= "a" "C") => T

atom

Syntax
(atom VALUE)
Description
If VALUE is not list, returns T. Returns NIL if list. If VALUE is empty list, returns T because clCalc evaluate empty list equally NIL.
Sample
(atom 3.1415) => T
(atom '(1 2 3)) => NIL
(atom PI) => T
# PI evaluate to value 3.1415...
(atom '()) => NIL
to Top return to clCalc

List manipulate functions

car

Syntax
(car LIST)
Description
Returns the first element of LIST. if LIST is empty, returns NIL.
Sample
(car '(1 2 3)) => 1
(car '((1 2 3) (4 5 6))) => (1 2 3)
(car nil) => NIL

cdr

Syntax
(cdr LIST)
Description
Returns LIST that removed first element. if LIST is empty, of LIST has only one element, returns NIL.
Sample
(cdr '(1 2 3)) => (2 3)
(cdr (cdr '(1 2 3 4 5))) => (3 4 5)
(cdr '((1 2 3) (4 5 6))) => ((4 5 6))
(cdr '(1)) => NIL
(cdr nil) => NIL

cons

Syntax
(cons VALUE1 VALUE2)
Description
Create list join two values or a value and list. This implements is different to LISP, this function returns pure-list (VALUE1 (VALUE2 ... (VALUEn nil))) only. Not supported create dotted list.
Note
If you want to join list and atom, you may use append function.
Sample
(cons 1 2) => (1 2)
(cons 1 '(2 3)) => (1 2 3)
(cons '(1 2) '(3 4)) => ((1 2) 3 4)

append

Syntax
(append LIST ATOM)
Description
Add element to tail of LIST.
Sample
(append '(1 2) 3) => (1 2 3)
(append '(1 2) '(3 4)) => (1 2 (3 4))

reverse

Syntax
(reverse LIST)
or
(reserve STRING)
Description
If specify argument to list, returns list that has elements sorted reverse-order from argument. If specify string, returns string reversed from argument.
Sample
(append '(1 2 3)) => (3 2 1)
(append '(1 '(2 3) 4 5)) => (5 4 (2 3) 1)
(append "abcde") => "edcba"
(append "") => ""

length

Syntax
(length LIST)
or
(length STRING)
Description
Returns count of elements in list or length of string.
Sample
(length '(1 2 3 4 5)) => 5
(length "this is test") => 12
(length '((1 2 3) 4 (5 6 7 8) (9 10))) => 4
(length "") => 0
(length nil) => 0

concatinate

Syntax
(concatinate LIST1 [LIST2 ... LISTn])
or
(concatinate STRING1 [STRING2 ... STRINGn])
Description
Concatinate strings or elements of list. All elements must same type, and type is string or list.
Sample
(concatinate "123" "abc" "XYZ") => "123abcXYZ"
(concatinate '(1) '(2 3) '(4 5 6) '(7 8 9 10)) => (1 2 3 4 5 6 7 8 9 10)
(concatinate '(1) '(2 (4 5 6)) '(7 8) '((9))) => (1 2 (4 5 6) 7 8 (9))
to Top return to clCalc

String manipulate functions

substring

Syntax
(substring STRING START-INDEX [END-INDEX])
Description
Returns substring of STRING. This function take characters from STRING from START-INDEX to (END-INDEX - 1). The index of head character is 0. if you ommit END-INDEX, take to end.
Sample
(substring "ABCDEFG" 2 5) => "CDE"
(substring "12345" 3 4)) => "4"
(substring "12345" 4 4) => ""

string-substitute

Syntax
(string-substitute STRING REPLACE-SOURCE REPLACE-DEST)
Description
Returns substituted string REPLACE-SOURCE to REPLACE-DEST in STRING.
Sample
(string-substitute "ABCDEFG" "B" "x") => "AxCDEFG"
(string-substitute "government of the people, by the people, for the people" "people" "PEOPLE") => "government of the PEOPLE, by the PEOPLE, for the PEOPLE"
(string-substitute "This is a pen" "is" "WAS") => "ThWAS WAS a pen"

string-substitute-regex

Syntax
(string-substitute-regex STRING PATTERN REPLACE-DEST)
Description
Returns substituted string matched pattern of PATTERN to REPLACE-DEST in STRING. Can use pattern of regex depends on java.
Sample
(string-substitute-regex "ABCDEFG" "B.*E" "x") => "AxFG"
(string-substitute "government of the people, by the people, for the people" "^.*people," "PEOPLE") => "PEOPLE for the people"

string-trim

Syntax
(string-trim [TRIMMED-STRING] STRING)
Description
Returns string that cut TRIMMED-STRING from head and tail of STRING. If ommit TRIMMED-STRING, cur white-space from STRING.
Sample
(string-trim " abcde  ") => "abcde"
(string-trim "   XYZ") => "XYZ"
(string-trim "123 ") => "123"
(string-trim "ABC" "ABCDE123456ABABABC") => "DE123456ABAB"

string-upcase

Syntax
(string-upcase STRING)
Description
Replace characters in STRING from lower-case character to upper-case character.
Sample
(string-upcase "The Sample of STRING") => "THE SAMPLE OF STRING"

string-downcase

Syntax
(string-downcase STRING)
Description
Replace characters in STRING from upper-case character to lower-case character.
Sample
(string-downcase "The Sample of STRING") => "the sample of string"

string-split

Syntax
(string-split STRING DELIMITER)
Description
Returns list in strings that is split STRING by DELIMITER.
Sample
(string-split "/etc/httpd/conf/httpd.conf" "/") => ("" "etc" "httpd" "conf" "httpd.conf")
(string-split "home/username//public_html/" "/") => ("home" "username" "" "public_html" "")
(string-split "~myname/tmp/cache" "m") => ("~" "yna" "e/t" "p/cache")
(string-split "government of the people, by the people, for the people" "people") => ("government of the " ", by the " ", for the " "")

string-split-regex

Syntax
(string-split-regex STRING DELIMITER-PETTERN)
Description
Returns list in strings that is split STRING by DELIMITER-PETTERN. DELIMITER-PETTERN is string of regex pattern.
Sample
(string-split-regex "This is  the string." "\s+") => ("This" "is" "the" "string.")
(string-split-regex "abc123def5fghij6k7890lmn" "[0-9]+") => ("abc" "def" "fghij" "k" "lmn")
to Top

Math functions

sqrt

Syntax
(sqrt EXPR)
Description
Returns square-rooted number. EXPR must larger than 0.
Sample
(sqrt 2) => 1.4142135623730951

sin

Syntax
(sin RADIAN)
Description
Returns sine of argument. RADIAN must between 0 and (2 * π).
Sample
(sin 0) => 0
(sin 1) => 0.8414709848078965
(sin 3.14) => 0.0015926529164868282
(sin 6.28) => -0.0031853017931379904

cos

Syntax
(cos RADIAN)
Description
Returns co-sine of argument. RADIAN must between 0 and (2 * π).
Sample
(cos 0) => 1
(cos 1) => 0.5403023058681398
(cos 3.14) => -0.9999987317275395
(cos 6.28) => 0.9999949269133752

tan

Syntax
(tan RADIAN)
Description
Returns tangent of argument. RADIAN must between 0 and (2 * π) but must not set (π / 2) and (π * 3 / 2).
Sample
(tan 0) => 1
(tan 1) => 1.5574077246549023
(tan 3.14) => -0.001592654936407223
(tan 6.28) => -0.003185317952531891
to Top return to clCalc

Date and Time functions

time-get

Syntax
(time-get)
Description
Returns current time by milliseconds from EPOCH. This function returns value by java.util.Calendar#getTimeInMillis() method.
Sample
(time-get) => 2147483647
(at 24th, Dec. 2013, 18:30:45.123)

time-decode

Syntax
(time-decode SEQ)
Description
Decode SEQ that sequencial time from EPOCH to list. SEQ is get by time-get function. List has 7 elements. elements are:
  1. year
  2. month (0 to 11)
  3. day
  4. hour (0 to 23)
  5. minute
  6. second
  7. millisecond
Sample
(time-decode (time-get)) => (2013 11 1 18 30 45 256)
(at 1st, Dec. 2013, 18:30:45.256)

time-encode

Syntax
(time-encode TIME-LIST)
Description
Encode TIME-LIST that is time in list to EPOCH. List must have 3, 4, or 7 elements. These format is.
format 1 (specify date, time specify 00:00:00):
(YEAR MONTH DAY)
format 2 (specify time, date specify today.):
(HOUR MINUTE SECOND MILLISECOND)
format 3 (specify date and time):
(YEAR MONTH DAY HOUR MINUTE SECOND MILLISECOND)
NOTE:
MONTH is start from 0. example, April is 3, Decenber is 11.
Sample
(time-encode '(2013 11 24 18 30 45 123)) => 2147483647

time-format

Syntax
(time-format SEQ STRING)
Description
Returns formatted string from SEQ that is EPOCH time by STRING. STRING shold valid to java.text.SimpleDateFormat.
Sample
(time-format (time-get) "yyyyMMdd hh:mm:ss.SSS") => "20131224 08:30:59.333"
(at 24th, Dec. 2013, 20:30:59.333)
to Top return to clCalc

Macro functions

quote

Syntax
(quote EXPR)
'EXPR
Description
Returns EXPR (number, string, symbol, or list) without evaluate. This function can write short by single quote.
Sample
(quote (1 2 3)) => (1 2 3)
(quote (+ 1 2 3)) => (+ 1 2 3)
(quote PI) => PI
(cdr (quote (car 1 2 3))) => (1 2 3)

eval

Syntax
(eval 'EXPR)
Description
Evaluate QUOTED element.
Sample
(eval '(+ 1 2)) => 3
(eval (cdr '(+ * 4 8))) => 32

setq

Syntax
(setq NAME VALUE)
Description
This function defines new variable.
Sample
(setq P 3.1415) => 3.1415
P => 3.1415
(setq P (+ P 5)) => 8.1415
P => 8.1415

cond

Syntax
(cond (CASE1 EXPR1) [(CASE2 EXPR2) ... (CASEn EXPRn)])
Description

This function has any arguments. Arguments must list and this has at least 2 elements in list.

This function is macro. when called cond function. Function returns expression replace from
(cond (CASE1 EXPR2) (CASE2 EXPR2) ... (CASEn EXPRn))
to
(if CASE1 EXPR2 (if CASE2 EXPR2 (if ... (if CASEn EXPRn nil))))

This function is incompatible with LISP. A CASE can have only one EXPR.

Sample
(cond ((= 1 2) "1") ((= 2 2) "2") ((= 3 2) "3")) => "2"
(cond ((< 3 2) "TRUE")) => NIL

lambda

Syntax
(lambda (ARGS1 [ARGS2 ... ARGSn]) EXPR)
Description

This function define and returns new macro. First argument is list of arguments. Arguments list must have element at least one.

Second argument if expression of macro. Expression may use variable that define in argument list.

Sample
(lambda (A) (+ A 1)) => <function(UserExpression)>
((lambda (A) (+ A 1)) 3) => 4
((lambda (A B C) (+ (* A A) (* B B) (* C C))) 2 3 5) => 38
to Top return to clCalc