MULTIPLE: ONE NAME, SEVERAL TYPES

Every name in satellite has a type. A satellite.variable.number holds a number, and a satellite.variable.string holds text. Now and then you want a name that can hold either. An answer might be typed as the word “twelve” or as the number 12. A setting might be a number or the word “auto”. For that, satellite has satellite.container.multiple.

Saying which types a name takes

You list two or more types between < and >. The name then takes a value of any of those types, and satl checks every value you give it.

answer.satlSATELLITE 004 Download
One name, a string first and a number after
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.container.multiple<satellite.variable.string, satellite.variable.number> answer = "forty-two"
    satellite.console.display(answer)
    satellite.console.display(answer.reverse())
    satellite.console.display(answer + "!")

    answer = 42
    satellite.console.display(answer)
    satellite.console.display(answer * 2)
    satellite.console.display(answer.to_string() + "!")
    satellite.return(satellite)
}
OUTPUT
forty-two
owt-ytrof
forty-two!
42
84
42!

Notice that nothing special happens when you use it. While answer holds text, it reverses and joins like text. Once it holds 42, it multiplies like a number. The value inside is an ordinary string or an ordinary number, and it behaves exactly as it would in a name declared the plain way.

That is why multiple is not really a container, even though its name starts with satellite.container. It holds nothing of its own. It is a promise about a name: “this name takes one of these types”.

In a capsule, and inside a list

A multiple can be a capsule’s parameter, so one capsule can be handed different kinds of value. It can also be the type a list holds, which gives you a list where every item is one of the listed types.

describe.satlSATELLITE 004 Download
A capsule that takes a number or a string, and a list that holds both
satellite.include(satellite)

satellite.capsule describe(satellite.container.multiple<satellite.variable.number, satellite.variable.string> amount)
{
    satellite.return("you asked for " + amount.to_string())
}

satellite.capsule satellite.main()
{
    satellite.console.display(describe(12))
    satellite.console.display(describe("a dozen"))

    satellite.container.list<satellite.container.multiple<satellite.variable.number, satellite.variable.string>> order = {2, "some", 6}
    order.append("plenty")
    satellite.console.display(order)
    satellite.console.display(order.size)

    satellite.container.multiple<satellite.variable.string, satellite.container.list> label = "one"
    label = {"two", "three"}
    satellite.console.display(label)
    satellite.return(satellite)
}
OUTPUT
you asked for 12
you asked for a dozen
{2, "some", 6, "plenty"}
4
{"two", "three"}

Containers can go on the list too, as label shows. A multiple with no <> at all takes every type.

One small detail: if a number is on the list, a binary value is taken as it is and stays a binary. Give b101 to a name declared satellite.container.multiple<satellite.variable.string, satellite.variable.number> and it shows b101. Give it to a plain satellite.variable.number and it becomes 5.

A type that is not on the list

Give the name a value whose type you did not list and satl stops, and says which types the name takes. Here a percentage goes into a name that takes only strings and numbers:

not_on_the_list.satlSATELLITE 004 Download
A percentage is refused by a string-or-number name
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.container.multiple<satellite.variable.string, satellite.variable.number> answer = "not sure"
    answer = 50%
    satellite.return(satellite)
}
OUTPUT
[satellite] satl(run): answer was declared satellite.container.multiple, and it holds a percentage, and this name takes satellite.variable.string or satellite.variable.number (machine_code: 27 types_do_not_meet)

This refusal is one line rather than a full report, but it says the same things: what the value was, which types the name takes, and the machine code, 27, that satl exits with.

A multiple needs at least two types. With only one type it would say nothing that a plain declaration does not say, so satl refuses it before the program runs:

one_type.satlSATELLITE 004 Download
A multiple of one type is refused
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.container.multiple<satellite.variable.string> just_text = "hello"
    satellite.return(satellite)
}
OUTPUT
--------------------------------------------------------------------------------
SATELLITE CRITICAL ERROR REPORT
--------------------------------------------------------------------------------
S110: LINE_NOT_UNDERSTOOD
satl(check): in satellite.main, satellite.container.multiple takes two or more
types between < and >, and was given 1

directory: one_type.satl:5
syntax: satellite.container.multiple<satellite.variable.string> just_text = "hello"
        /\

satellite has no scenario for this line -- it is spelled in a shape the language
does not have a meaning for.
machine code 13 satl_line_not_understood -- satl exits with this.

--------------------------------------------------------------------------------

What is not built yet

satellite 004 has no way yet to ask a multiple which type it holds right now. Write your program so that each line using the name makes sense for every type on its list, as describe does above by turning the amount into text with .to_string().

Where next

The FULL REFERENCE has every container word. Lists are in LISTS, and names that file values under keys are in MAPS.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *