arturo 0.3.3

Simple, modern and powerful interpreted programming language for super-fast scripting


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

<img align="left" width="170" src="logo.png">

<h1>Art:uro</h1>

Simple, modern and powerful
interpreted programming language for super-fast scripting.

License Language

The Language

Arturo is a modern programming language, vaguely inspired by various other ones - including but not limited to Ruby, Haskell, D, SDL, Tcl and Lisp.

It is built on some very simple and straightforward principles:

Everything is a simple statement

There are no "special" language constructs (even `if` is nothing but a simple statement). Everything you see is a statement in the form ID <expression> <expression> <expression> ...

Code is data - and data is code

Arturo can be used both as a data-interchange format and a programming language. Basically all data structures are valid code and all code can be represented as a data structure. Think of it as SDL/Json/YAML/XML combined with the power of Lisp - but without the... sea of opening and closing parentheses.

Each statement returns a value

Whether what you would consider a "function" or any other statement, it will return a value. If it's a block of code (see: function), the last statement's result will be return - unless specified otherwise.

Functions are first-class citizens

Functions - or blocks of statements enclosed in {} - can be anything. Assign them to a symbol/variable, pass them around as arguments to function calls, include them as a dictionary key value, or return them from a function. And of course they can be either named or anonymous/lambda.

Uniform syntax

As already mentioned, everything is a statement of the form ID <expressions>. So, how does this work?

  • Is it the first time you are declaring this symbol? Then, the right-hand value will be assigned.
  • Is it not the first time? Then again, the right-hand value will be assigned.
  • Do you want to call a function you have declared, by name? Just prefix it with an exclamation mark. E.g.: !myFunc "some arg" "another arg"
  • Do you want to use the result of a function call as part of an expression? Just enclose the function call in $(...) E.g.: print $(reverse #(1 2 3))

Simple, isn't it?

Getting Started

Hello World

"Hello World"

or...

print "Hello World"

Declaring some data

num 	10
str 	"this is a string"

arrA 	1 2 3
arrB 	"one" "two" "three"
arrC	#(1 2 3)

dict 	#{
	name 	"john"
	surname "doe"
	age 	33
	address #{
		city	"Granada"
		country	"Spain"
	}
}

Declaring a function

addNumbers {
	@0 + @1
}

or...

addNumbers [x,y]{
	x + y
}

Fibonacci

maxLimit 20 // $(toNumber @0)

fib $(memoize [x]{
	if x<2 { 1 }{
		$(!fib x-1) + $(!fib x-2)
	} 
})

loop $(range 0 maxLimit) {
	print $(!fib @)
}

The Library

FunctionDescriptionSyntax
array:allcheck if all elements of array are true or pass the condition of given function[Array or Array/Function] -> Boolean
array:anycheck if any of the array's elements is true or passes the condition of given function[Array or Array/Function] -> Boolean
array:avgget average value from array[Array] -> Number or Real
array:countcount how many of the array's elements is true or passes the condition of given function[Array or Array/Function] -> Number
array:differenceget difference of two given arrays[Array/Array] -> Array
array:filterget array after filtering each element using given function[Array/Function] -> Array
array:firstget first element from array[Array] -> Any
array:foldfold array using seed value and the given function[Array/Any/Function] -> Any
array:gcdcalculate greatest common divisor of values from array[Array] -> Number
array:intersectionget intersection of two given arrays[Array/Array] -> Array
array:joinget string by joining array elements with given delimiter[Array/String] -> String
array:lastget last element from array[Array] -> Any
array:mapget array after executing given function for each element[Array/Function] -> Array
array:maxget maximum value from array[Array] -> Number or Real
array:medianget median value from array[Array] -> Number or Real
array:minget minimum value from array[Array] -> Number or Real
array:permutationsget all permutations for given array[Array] -> Array
array:productreturn product of elements of given array[Array] -> Number
array:rangeget array from given range (from..to) with optional step[Number/Number or Number/Number/Number] -> Array
array:reversereverse given array[Array] -> Array
array:sampleget random sample from given array[Array or Array/Number] -> Any or Array or Null
array:shuffleshuffle given array[Array] -> Array
array:sortsort given array[Array] -> Array
array:sumreturn sum of elements of given array[Array] -> Number
array:tailget last section of array excluding the first element[Array] -> Array
array:unionget union of two given arrays[Array/Array] -> Array
array:uniqueget array by removing duplicates[Array] -> Array
array:zipreturn array of element pairs using given arrays[Array/Array] -> Array
collection:containscheck if collection contains given element[String/String or Array/Any or Dictionary/Any] -> Boolean
collection:deletedelete collection element by using given value[Array/Any or Dictionary/Any] -> Array or Dictionary
collection:deleteBydelete collection element by using given index/key[Array/Number or Dictionary/String] -> Array or Dictionary
collection:findreturn index of string/element within string/array, or -1 if not found[String/String or Array/Any] -> Number
collection:getget element from collection using given index/key[Array/Number or Dictionary/String] -> Any
collection:isEmptycheck if collection is empty[String or Array or Dictionary] -> Boolean
collection:setset collection element using given index/key[Array/Number/Any or Dictionary/String/Any] -> Array or Dictionary
collection:sizeget size of collection[String or Array or Dictionary] -> Number
collection:sliceget slice of array/string given a starting and/or end point[Array/Number or Array/Number/Number or String/Number or String/Number/Number] -> Array or String
convert:toBinconvert given number to its corresponding binary string value[Number] -> String
convert:toHexconvert given number to its corresponding hexadecimal string value[Number] -> String
convert:toNumberconvert given value to its corresponding number value[Real or String or Boolean] -> Number or Real
convert:toOctconvert given number to its corresponding octal string value[Number] -> String
convert:toStringconvert given number/boolean/array/dictionary to its corresponding string value[Number or Real or Boolean or Array or Dictionary] -> String
core:andbitwise/logical AND[Boolean/Boolean or Number/Number] -> Boolean or Number
core:execexecute given function with optional array of arguments[Function or Function/Any...] -> Any
core:ifif condition is true, execute given function - else optionally execute alternative function[Boolean/Function or Boolean/Function/Function] -> Any
core:importimport external source file from path[String] -> Any
core:inputread line from stdin[] -> String or Any
core:lazyget a lazy-evaluated expression[Any] -> Function
core:loopexecute given function for each element in array or dictionary, or while condition is true[Array/Function or Dictionary/Function or Boolean/Function] -> Any
core:memoizeget a memoized function[Function] -> Function
core:newcopy given object and return a new duplicate. one[String or String/Array] -> Any
core:notbitwise/logical NOT[Boolean or Number] -> Boolean or Number
core:orbitwise/logical OR[Boolean/Boolean or Number/Number] -> Boolean or Number
core:panicexit program printing given error message[String] ->
core:printprint value of given expression to screen, optionally suppressing newlines[Any or Any/Boolean] -> Any
core:returnreturn given value[Any] -> Any
core:shlbitwise left shift[Number/Number] -> Number
core:shrbitwise right shift[Number/Number] -> Number
core:tracetrace executing of given expression[Any] -> Any
core:xorbitwise/logical XOR[Boolean/Boolean or Number/Number] -> Boolean or Number
crypto:hashget hash value for given value[Any] -> String
crypto:md5get MD5 hash of given string data[String] -> String
crypto:sha256get SHA256 hash of given string data[String] -> String
crypto:sha512get SHA512 hash of given string data[String] -> String
csv:parseget object by parsing given CSV string, optionally using headers[String or String/Boolean] -> Array
date:dateNowget current date into string[] -> String
date:datetimeNowget current date and time into string[] -> String
date:dayget day from date string[String] -> String
date:monthget month from date string[String] -> String
date:timeNowget current time into string[] -> String
dictionary:hasKeycheck if dictionary has key[Dictionary/String] -> Boolean
dictionary:keysget array of dictionary keys[Dictionary] -> Array
file:existscheck if file exists at given path[String] -> Boolean
file:readread string from file at given path[String] -> String
file:writewrite string to file at given path[String/String] -> Null
html:markdownToHtmlconvert given markdown string to html[String] -> String
json:generateget JSON string from given object[Any] -> String
json:parseget object by parsing given JSON string[String] -> Any
number:acosget 'acos' for given number[Number or Real] -> Real
number:acoshget 'acosh' for given number[Number or Real] -> Real
number:asinget 'asin' for given number[Number or Real] -> Real
number:asinhget 'asinh' for given number[Number or Real] -> Real
number:atanget 'atan' for given number[Number or Real] -> Real
number:atanhget 'atanh' for given number[Number or Real] -> Real
number:ceilget 'ceil' for given number[Number or Real] -> Real
number:cosget 'cos' for given number[Number or Real] -> Real
number:coshget 'cosh' for given number[Number or Real] -> Real
number:evencheck if given number is even[Number] -> Boolean
number:expget 'exp' for given number[Number or Real] -> Real
number:floorget 'floor' for given number[Number or Real] -> Real
number:lnget 'ln' for given number[Number or Real] -> Real
number:log10get 'log10' for given number[Number or Real] -> Real
number:oddcheck if given number is odd[Number] -> Boolean
number:randomgenerate random number in given range (from..to)[Number/Number] -> Number
number:roundget 'round' for given number[Number or Real] -> Real
number:singet 'sin' for given number[Number or Real] -> Real
number:sinhget 'sinh' for given number[Number or Real] -> Real
number:sqrtget 'sqrt' for given number[Number or Real] -> Real
number:tanget 'tan' for given number[Number or Real] -> Real
number:tanhget 'tanh' for given number[Number or Real] -> Real
path:createDircreate directory at given path[String] -> Boolean
path:currentDirget current directory path[] -> String
path:dirget array of directory contents at given path[ or String] -> Array
path:getDirget directory from given path[String] -> String
path:getExtget extension from given path[String] -> String
path:getFilenameget filename from given path[String] -> String
path:isDirectorycheck if given path is a directory[String] -> Boolean
path:isFilecheck if given path is a file[String] -> Boolean
path:isSymlinkcheck if given path is a symlink[String] -> Boolean
path:normalizePathget normalized path from given path[String] -> String
reflection:objectget object for given symbol name[String] -> Any or Null
reflection:pointerget pointer location for object[Any or String] ->
reflection:symbolExistscheck if given symbol exists[String] -> Boolean
reflection:symsget list of declared symbols[ or String] ->
reflection:typeget type for given object[Any] -> String
string:capitalizecapitalize given string[String] -> String
string:charget ASCII character from given char code[Number] -> String
string:charactersget string characters as an array[String] -> Array
string:endsWithcheck if string ends with given string[String/String] -> Boolean
string:isAlphacheck if all characters in given string are ASCII letters[String] -> Boolean
string:isAlphanumericcheck if all characters in given string are ASCII letters or digits[String] -> Boolean
string:isControlcheck if all characters in given string are control characters[String] -> Boolean
string:isDigitcheck if all characters in given string are digits[String] -> Boolean
string:isLowercasecheck if all characters in given string are lowercase[String] -> Boolean
string:isMatchcheck if string matches given regex[String/String] -> Boolean
string:isUppercasecheck if all characters in given string are uppercase[String] -> Boolean
string:isWhitespacecheck if all characters in given string are whitespace[String] -> Boolean
string:levenshteinget Levenshtein distance between two given strings[String/String] -> Number
string:linesget lines from string as an array[String] -> Array
string:lowercaselowercase given string[String] -> String
string:matchesget array of matches for string using given regex[String/String] -> Array
string:padCentercenter justify string by adding padding[String/Number] -> String
string:padLeftleft justify string by adding padding[String/Number] -> String
string:padRightright justify string by adding padding[String/Number] -> String
string:replaceget string by replacing occurences of string with another string[String/String/String] -> String
string:splitsplit string by given separator or regex[String/String] -> Array
string:startsWithcheck if string starts with given string[String/String] -> Boolean
string:stripstrip spaces from given string[String] -> String
string:uppercaseuppercase given string[String] -> String
string:uuidgenerate random UUID string[] -> String
string:wordsget words from string as an array[String] -> Array
system:envget system environment variables as a dictionary[] -> Dictionary
system:shellexecute given shell command[String] -> String or Boolean
system:spawnspawn process using given string and get process id[String] -> Number
web:downloaddownload string contents from webpage using given URL[String] -> String
web:postperform POST request using given URL and data[String/String] -> String
xml:checkcheck integrity of XML input using given string[String] -> Boolean
yaml:generateget YAML string from given object[Any] -> String
yaml:parseget object by parsing given YAML string[String] -> Any

Build Instructions

Prerequisites:

  • Flex
  • Bison
  • D compiler (preferably DMD) + DUB

Build:

dub build --build=release

Run script:

./arturo <script>

REPL:

./arturo -c

Or... Check it out online!

http://arturo-lang.io

License

MIT License

Copyright (c) 2019 Yanis Zafirópulos (aka Dr.Kameleon)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Authors:
  • drkameleon
Dependencies:
dmarkdown, dyaml
Versions:
0.3.9 2019-Oct-19
0.3.8 2019-Oct-16
0.3.7 2019-Oct-11
0.3.6 2019-Oct-09
0.3.5 2019-Oct-07
Show all 8 versions
Download Stats:
  • 1 downloads today

  • 1 downloads this week

  • 1 downloads this month

  • 25 downloads total

Score:
2.1
Short URL:
arturo.dub.pm