Page 1 of 1

Sum of two vector elements cannot be used as number paramter

Posted: Sat Jun 09, 2018 9:00 am
by flembobs
Not sure if this is a bug or working as intended.

I cannot sum two elements from a vector and use them as a number parameter.

Example:

startshape START ( (1,2) )[]

shape START (vector2 v)
{
VECTORSUM ( ( v[0] + v[1] ) )[]
}

shape VECTORSUM (number n)
{
SQUARE[]
}

Results in:

Error - This expression does not satisfy the number parameter requirement


Am I trying to sum the elements properly or is there another way to do this?

Re: Sum of two vector elements cannot be used as number paramter

Posted: Sat Jun 09, 2018 9:48 am
by MtnViewJohn
This is expected. Once you manipulate the vector2 parameter of shape START (by adding elements together), you cannot pass the result as a number parameter to another shape. If Context Free had a type that was vectors of naturals then you could use that.

You will just have to add CF::Impure=1 to your code, even though your code is pure. Or you could break the vector2 into a pair of naturals. I guess it would be a good idea to add a vector-of-naturals type as a convenience for passing a collection of naturals.

Re: Sum of two vector elements cannot be used as number paramter

Posted: Sun Jun 10, 2018 5:23 am
by flembobs
Thanks for your reply. That clears it up for me.

I think it would be cool to have unordered sets and ordered sequences of naturals as data types - with arbitrary lengths.

Operations could create new instances of the sets so that it would allow branching recursion.

I suppose it would be a difficult addition to the code but I love the idea of making Turing machine shapes.