Skip to content
dbenn edited this page Sep 26, 2020 · 18 revisions

Introduction

VeLa (VStar expression Language) is a general purpose programming language that, within VStar, can be used to:

  • specify a numeric expression wherever a number can be used as input;
  • create complex observation filter and search expressions;
  • specify model functions;
  • transform observations.

VeLa is a simple functional language with:

  • integer, real, string, boolean, list, function types
  • variables that take on the type of the value to which they are first bound via the <- binding (assignment) operator (e.g. n <- 1)
  • named constants via the is operator (e.g. π is 3.1415926)
  • case insensitive, Unicode keyword, variable, and function names
  • statically typed, recursive, higher order, named or anonymous functions that may be overloaded by parameter type
  • selection (when) and iteration (while)
  • numeric operators: + - * / ^
  • string operators: + in
  • logical operators: not, and, or
  • relational operators: = <> > < >= <= =~
  • list operators: in
  • regular expressions (Java syntax) for use with =~ (approximately equal) operator
  • intrinsic functions (see below)

Grammar

Here is the VeLa grammar specification (PDF).

Examples

Numeric expression

Any text entry box in VStar that accepts a numeric value can instead receive a numeric VeLa expression.

Expressions such as 2457529.5-365.25*5 or today()-365.25*5 could be used as the minimum JD when loading a dataset from AID.

Observation filter expression

(obscode in ["CTIA" "SAH"] and band = "Johnson V" and uncertainty <= 0.01) 
OR 
(band = "Visual" and obscode = "BDJB")

This Boolean expression defines an observation filter in which:

  • the observer code is CTIA or SAH and the band is Johnson V and the uncertainty is less than or equal to 0.01 or
  • the band is Visual and the observer code is BDJB (the lead VStar developer)

Load eta Aquilae with a JD range of 2457529.5-365.25*5 to 2458259.5 and try this filter via VeLa Filter... in the View menu.

A VeLa observation filter has access to the properties of the currently loaded observations, such as time/JD, magnitude, observer code, band, and any properties peculiar to a particular observation source.

Model function

Applying DCDFT with Period Range to the eta Aql filtered observations above with a period range of 1 to 10 and a resolution of 0.01 will yield a period search top hit of 7.18.

This function defines a Fourier model obtained from a fundamental frequency of ~0.1393 (a period of 7.18) and two harmonics:

f(t:real) : real {
  3.8893863
  +0.1148971 * cos(2*PI*0.1392758*(t-2457506))-0.312022 * sin(2*PI*0.1392758*(t-2457506))
  +0.0432131 * cos(2*PI*0.2785515*(t-2457506))-0.1196311 * sin(2*PI*0.2785515*(t-2457506))
  +0.0370884 * cos(2*PI*0.4178273*(t-2457506))-0.0013007 * sin(2*PI*0.4178273*(t-2457506))
}

Running VeLa Code

VeLa code can be entered into a dialog (Tools -> VeLa) to test it before use in one of the contexts outlined above, e.g.

fact(n : integer) : integer {
    when n = 0 -> 1
         true -> n*fact(n-1)
}

map(fact [1 2 3 4 5 6 7 8 9 10])

VeLa dialog

Intrinsic variable bindings

General

π 
pi
e

Intrinsic functions

A range of in-built functions are available in VeLa and categorised below.

General

EVAL (STRING) : LIST
CHR (INTEGER) : STRING
FORMAT (STRING LIST) : STRING
ORD (STRING) : INTEGER
TODAY () : REAL

I/O

PRINT(...)
PRINTLN(...)
NEXTCHAR () : STRING

List

APPEND (LIST ANY) : LIST
CONCAT (LIST LIST) : LIST
FILTER (FUNCTION LIST) : LIST
FOR (FUNCTION LIST) : ANY
HEAD (LIST) : ANY
LENGTH (LIST) : INTEGER
MAP (FUNCTION LIST) : LIST
NTH (LIST INTEGER) : ANY
REDUCE (FUNCTION LIST ANY)  : ANY
TAIL (LIST) : LIST

Math

ABS (INTEGER) : INTEGER
ABS (REAL) : REAL
SIN (REAL) : REAL
COS (REAL) : REAL
TAN (REAL) : REAL
ATAN2 (REAL REAL) : REAL
SQRT (REAL) : REAL
LOG (REAL) : REAL
LOG10 (REAL) : REAL
POW (REAL REAL) : REAL
EXP (REAL) : REAL
MIN (REAL REAL) : REAL
MIN (INTEGER INTEGER) : INTEGER
MAX (REAL REAL) : REAL
MAX (INTEGER INTEGER) : INTEGER
ADDEXACT (INTEGER INTEGER) : INTEGER
DECREMENTEXACT (INTEGER) : INTEGER
INCREMENTEXACT (INTEGER) : INTEGER
MULTIPLYEXACT (INTEGER INTEGER) : INTEGER
NEGATEEXACT (INTEGER) : INTEGER
SUBTRACTEXACT (INTEGER INTEGER) : INTEGER
SCALB (REAL INTEGER) : REAL
COPYSIGN (REAL REAL) : REAL
GETEXPONENT (REAL) : INTEGER
SIGNUM (REAL) : REAL
ASIN (REAL) : REAL
ACOS (REAL) : REAL
ATAN (REAL) : REAL
TORADIANS (REAL) : REAL
TODEGREES (REAL) : REAL
CBRT (REAL) : REAL
IEEEREMAINDER (REAL REAL) : REAL
CEIL (REAL) : REAL
FLOOR (REAL) : REAL
RINT (REAL) : REAL
FLOORDIV (INTEGER INTEGER) : INTEGER
FLOORMOD (INTEGER INTEGER) : INTEGER
ULP (REAL) : REAL
SINH (REAL) : REAL
COSH (REAL) : REAL
TANH (REAL) : REAL
HYPOT (REAL REAL) : REAL
EXPM1 (REAL) : REAL
LOG1P (REAL) : REAL
NEXTAFTER (REAL REAL) : REAL
NEXTUP (REAL) : REAL
NEXTDOWN (REAL) : REAL
POWEROFTWOD (INTEGER) : REAL

String

COMPARETO (STRING STRING) : INTEGER
INDEXOF (STRING STRING INTEGER) : INTEGER
INDEXOF (INTEGER INTEGER STRING INTEGER) : INTEGER
INDEXOF (INTEGER INTEGER INTEGER INTEGER INTEGER) : INTEGER
INDEXOF (STRING INTEGER) : INTEGER
INDEXOF (STRING STRING) : INTEGER
INDEXOF (STRING INTEGER INTEGER) : INTEGER
VALUEOF (BOOLEAN) : STRING
VALUEOF (INTEGER INTEGER) : STRING
VALUEOF (REAL) : STRING
VALUEOF (INTEGER) : STRING
CODEPOINTAT (STRING INTEGER) : INTEGER
CODEPOINTBEFORE (STRING INTEGER) : INTEGER
CODEPOINTCOUNT (STRING INTEGER INTEGER) : INTEGER
OFFSETBYCODEPOINTS (STRING INTEGER INTEGER) : INTEGER
CONTENTEQUALS (STRING STRING) : BOOLEAN
EQUALSIGNORECASE (STRING STRING) : BOOLEAN
COMPARETOIGNORECASE (STRING STRING) : INTEGER
REGIONMATCHES (STRING INTEGER STRING INTEGER INTEGER) : BOOLEAN
REGIONMATCHES (STRING BOOLEAN INTEGER STRING INTEGER INTEGER) : BOOLEAN
STARTSWITH (STRING STRING) : BOOLEAN
STARTSWITH (STRING STRING INTEGER) : BOOLEAN
ENDSWITH (STRING STRING) : BOOLEAN
INDEXOFSUPPLEMENTARY (STRING INTEGER INTEGER) : INTEGER
LASTINDEXOF (STRING INTEGER INTEGER) : INTEGER
LASTINDEXOF (INTEGER INTEGER INTEGER INTEGER INTEGER) : INTEGER
LASTINDEXOF (INTEGER INTEGER STRING INTEGER) : INTEGER
LASTINDEXOF (STRING STRING INTEGER) : INTEGER
LASTINDEXOF (STRING INTEGER) : INTEGER
LASTINDEXOF (STRING STRING) : INTEGER
LASTINDEXOFSUPPLEMENTARY (STRING INTEGER INTEGER) : INTEGER
SUBSTRING (STRING INTEGER) : STRING
SUBSTRING (STRING INTEGER INTEGER) : STRING
SUBSEQUENCE (STRING INTEGER INTEGER) : STRING
CONCAT (STRING STRING) : STRING
REPLACE (STRING STRING STRING) : STRING
MATCHES (STRING STRING) : BOOLEAN
CONTAINS (STRING STRING) : BOOLEAN
REPLACEFIRST (STRING STRING STRING) : STRING
REPLACEALL (STRING STRING STRING) : STRING
COPYVALUEOF (INTEGER INTEGER) : STRING