Pluvo Basic Functions

This is a guide to the basic program functions, operators, and variables of Pluvo. These are all accessible as variables without the "@" namespace sigil. For an introduction to Pluvo, try the Guide to Pluvo instead. Feel free to ask questions about this document on the Pluvo mailing list.

add table item
Append item to table, initialising table if it doesn't already exist. Examples:
>> add people "Alice"
>> add people "Bob"
def *args
An alias for = (q.v.).
else block
If the most recent status is "Condition Failed", i.e. if an "if" command has failed, then else will execute its block. Example:
>> if {return false} { say "FAIL" }
>> else { say "pass" }
pass
example block
Does nothing, but the block argument can then be used by the check function. Format of block is commands to run, with output lines indicated by commands starting with the "=>" function. Example:
>> hello = (name)
>>    example
>>       hello "Alice"
>>       => Hello, Alice!
>> 
>>    say "Hello, $name!"
for table block
for name table block
for name in table block
For each item in the Table (or iterator) table, pass the item to block as the variable named name. If name isn't present, default to "arg". If name is a Table of names and the items returned from table are of the same length, assign the sub items to the sub names. Examples:
>> for ("Alice" "Bob")
>>    say "Hello $arg"
Hello Alice
Hello Bob

>> for name ("Alice" "Bob")
>>    say "Hi $name"
Hi Alice
Hi Bob

>> for language in ("Perl" "PHP" "Python")
>>    say "$language is a language"
Perl is a language
PHP is a language
Python is a language

>> for (p q) in (("p" "q") ("r" "s") (7 8))
>>    say "$p -> $q"
p -> q
r -> s
7 -> 8
help
If there was a previous usage block, print out the documentation derived therefrom and exit with the status 0. Example:
>> usage
>>    "033-test.pvo [options]"
>>    -h/--help "Display a help message"
>>    -t/--test "Perform builtin code tests"
>> help
033-test.pvo [options]
-h/--help  Display a help message
-t/--test  Perform builtin code tests
if condition block
If condition, which must be a block as it will be evaluated, passes then run block. Otherwise return a status of "Condition Failed". Example:
>> if {return true} { say "pass" }
join string table
Join each of the items in the Table instance table, converted to strings, with the String instance string. Examples:
>> join " " ("Hello" "there")
Hello there
>> "..." join (1 2 3)
1...2...3
method var = argspec block
Create a new method, named var, with the argspec argspec and content block. This is to be used in a closure which can later be instantiated as a prototype. Example:
>> Person = (name homepage)
>>    method details = ()
>>       say "Name: $name"
>>       say "Homepage: $homepage"
>> jc = Person("Cody Woodard" "http://d8uv.org/")
>> jc.details
Name: Cody Woodard
Homepage: http://d8uv.org/
not arg
Return the inverse of the boolean status of arg. If arg is a strong function, it'll be called. Example:
>> if {not true} { say "FAIL" }
>> if {not false} { say "pass" }
pass
or arg+
At the moment, acts like elif. So if the current status is "Condition Failed", the args in arg+ will be run as a command. Example:
>> if {/123/ "pqr"} { say "FAIL" }
>> or if {/pqr/ "pqr"} { say "pass" }
pass
out arg+
Write each argument in arg+ to stdout, joined with a single space. Examples:
>> out "Hello, world!\n"
Hello, world!
>> out "p" "q" "r\n"
p q r
quit [status]
Quit the program immediately, with optional status, which defaults to 0. Examples:
>> say "pass"
>> quit
pass

>> say "FAIL"
>> quit 1
FAIL
range start finish [step]
Return a Table of numbers from start to finish, incrementing by the optional step where step defaults to 1. Note that step may be negative, and finish may be smaller than start. Examples:
>> for i in { range 1 3 }
>>    say i
1
2
3

>> for i in { range 5 1 -2 }
>>   say "...$i"
...5
...3
return value
Return value from the current function, ignoring any commands that follow. Example:
>> test = ()
>>    return "pass"
>>    say "FAIL"
>> say { test }
pass
run block
If block is runnable, run it and return the value. Otherwise, just return block as is (i.e., this is a soft and forgiving function). Examples:
>> run { say "Testing" }
Testing
>> say { run "Hello, world!" }
Hello, world!
say arg+
For each argument in arg+, if the argument is a block evaluate it, then convert it to a string. Write all of the arguments, joined by a space, to stdout, followed by a newline, "\n". Examples:
>> say "Hello, world!"
Hello, world!
>> say 1 2 3
1 2 3
>> say { 3 + 5 }
8
script function
If the script has not been imported, i.e. it's actually running as a script, then call function with argv as an argument. Note that at the moment it doesn't work for imports, but since imports doesn't work this is rather moot. Example:
>> main = (argv)
>>    say "Hello, world!"
>> script main
Hello, world!
split sep string
Return a Table containing parts of string that were formerly delimited with sep. The inverse of join. Examples:
>> split " " "Hello there"
("Hello" "there")
>> "..." split "1...2...3"
("1" "2" "3")
usage block
By itself does nothing, but its content can later be used by the help function. Example:
>> usage
>>    "033-test.pvo [options]"
>>    -h/--help "Display a help message"
>>    -t/--test "Perform builtin code tests"
>> help
033-test.pvo [options]
-h/--help  Display a help message
-t/--test  Perform builtin code tests

Operators

table : item
The ":" function gets an item from a Table. Example:
>> {block} = { 5 + 3 }
>> say {{{ quote block }:0}:0}
5
name = value
{name} = block
name = argspec block
name = proto args
Assign to name. If the second argument is a value, simply assign name to that object. Example:
>> hello = "Hello, world!"
>> say hello
Hello, world!
If name appears within braces and the second argment is a block, assign the block to name without evaluating it. Example:
>> {block} = { 5 + 3 }
>> say {{{ quote block }:0}:0}
5
If there are two arguments, and the second argument is a Table, argspec, the the third argument a block, create a new function from block using the second argument as the argument specification. Example:
>> test = (name)
>>    say "Hello $name!"
>> test "Alice"
Hello Alice!
Otherwise, if the second argument is a prototype, proto, and the third a Table of arguments, args, create a new copy of the prototype passing it the arguments. Example:
>> Dog = (name)
>> method speak = (bark)
>>    say "$name says: "
>>    say "$bark! $bark! I am a dog."
>> rover = Dog("Rover")
>> rover.speak "WOOF"
Rover says: 
WOOF! WOOF! I am a dog.
p == q
Compare p for equality with q. Return a boolean. Example:
>> if {"something" == "something else"} { say "FAIL" }
>> or if {"test" == "test"} { say "pass" }
pass
p + q
+ arg+
Each of the args to + are evaluated if they are blocks. Then, if the arguments are strings, they will be concatenated and the sum will be returned. Whereas if the argments are numbers, they will be summed and then returned. Examples:
>> say { "p" + "q" }
pq
>> say { + "p " "q " "r" }
p q r
>> say { 5 + 3 }
8
p - q
Return the value of the Number p minus the Number q. Example:
>> say { 8 - 3 }
5

@@ More.

Variables

args
The arguments passed to the program on the command line, ignoring the executable, i.e. argv from its second argument onwards. Example:
$ pluvo test.pvo first second
>> say { args:1 }
first
>> say { args:2 }
second
prog
The name of the current program, from the command line. In other words, the first or second element of argv, depending on the interpreter. Example:
$ pluvo test.pvo
>> say "$prog"
test.pvo

These functions and variables are just the variables that are available without using the program variables namespace sigil, "@". When using it, many more functions are available. There is some scant library documentation, but for more information on the library functions the best reference at the moment is the source itself.

Sean B. Palmer, inamidst.com