10.10.8  Ref Types

Almost all Mythryl values are immutable once created; in the jargon of functional programming, they are pure. In more mainstream nomenclature, they are read-only.

The two exceptions are:

The latter are a concession to the needs of matrix algorithms; they are not often used in vanilla Mythryl coding.

For most practical purposes, the only Mythryl values which can be modified are references, which work much like C pointers:

    linux$ cat my-script

    int_ptr = REF 0;

    printf "int_ptr = %d\n"  *int_ptr;

    int_ptr := 1;

    printf "int_ptr = %d\n"  *int_ptr;

    int_ptr := 2;

    printf "int_ptr = %d\n"  *int_ptr;

    linux$ ./my-script
    int_ptr = 0
    int_ptr = 1
    int_ptr = 2

Here we are seeing true side-effects at work:

The type of a reference cell depends on the type of its contents, and is declared using the Ref type constructor:

    Int_Ref        = Ref(Int);
    Float_Ref      = Ref(Float);
    String_Ref     = Ref(String);

    Stringlist_Ref = Ref(List(String));
    Record_Ref     = Ref(My_Complex_Record_Type);

Comments and suggestions to: