Sum of two vector elements cannot be used as number paramter

If you're having trouble using Context Free or don't understand the language, ask for help here.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
flembobs
Posts: 47
Joined: Tue Oct 09, 2012 3:00 pm

Sum of two vector elements cannot be used as number paramter

Post 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?

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

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

Post 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.

flembobs
Posts: 47
Joined: Tue Oct 09, 2012 3:00 pm

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

Post 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.

Post Reply