AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
unroll (Pointer source [, Pointer dest]) reserved
 
Copies elements from source into dest, or a new array if dest is omitted, and returns the destination (i.e., either dest or the new array) to the caller. When an object, like a dictionary, that associates names with values is unrolled into an object, like an array that does not, then unroll includes the name and the value of each element in the destination.

Something special happens when unroll is used as an argument in a function call or one of the comma separated expressions, enclosed in braces, that can be used to initialize arrays and dictionaries. The Yoix interpreter notices that the object was returned by unroll and decides that the individual elements in that object that are also initialized, rather than the object itself, should be the arguments in the function call or the elements in the initializer. Although it is may not be obvious, these really are unroll's most important uses.
 
 Example:   The program,
import yoix.stdio.*;

f(Stream stream, String fmt, ...) {

    if (stream == stdout)
        printf(unroll(&fmt));
    else fprintf(unroll(&stream));
}

f(stdout, "this calls %s\n", "printf");
f(stderr, "this calls %s\n", "fprintf");
prints
this calls printf
on standard output and
this calls fprintf
on standard error. Even though it is a trivial example it illustrates how unroll can be used when you are in a function, often one with a variable argument list, and you want to call another function, once again often one with a variable argument list.

Right now dictionaries, arrays, and strings can be quickly and easily duplicated using simple declarations, so

Dictionary dict[] = VM;
makes a copy of the VM dictionary and
String str[] = VM.Created;
makes a copy the VM.Created string. The square brackets are the key that tell the interpreter we want to make a copy, but unfortunately they currently don't work with objects, like a Point or Rectangle, that associate names with values but are not dictionaries. However unroll does work, so the program
import yoix.*.*;

Point p1 = {
    double x = 123.456;
    double y = 654.321;
};

Point p2 = {unroll(p1)};

printf("p2=%O\n", p2);
prints
p2=Point[2:0]
   >x=123.456
    y=654.321
on standard output.
 
 Return:   Pointer

 

Yoix is a registered trademark of AT&T Inc.