Vectors and global variables

Let the developers know what you think of the software and what can be done to either improve the CFDG language or the Context Free program.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
Posts: 29
Joined: Tue Aug 28, 2007 4:21 am
Location: Italy

Vectors and global variables

Post by mycelium »

I'm trying write a "library" (a file to include) with predefined functions and shapes and I'm feeling well with the actual version of CF.
I post a things that could help me making a better code:

1. I'm using a lot of vectors in the code and everything seems ok to me, but I miss bigger size vectors.
In particular I'd need a 15 size vector. I wish it was possible to have a more generalistic syntax for declaring vector type or bigger vector sizes.

2. Global variables are working properly?
I thought I could use global variables to store setup parameters of the library but it doesn't work.
Global variables have a behaviour I didn't expect.

Code: Select all

GV=1 // Global variable
startshape AAA[b 1 sat 1]

shape AAA {
    GV=2  // this (to me) should give a violation error (context free impurity)
    CIRCLE[h (120*GV)]
    BBB[x GV]
shape BBB {
     // GV value -now, to me- shoud be 2 but it is 1
     CIRCLE[h (120*GV)]
     CCC[x GV]
shape CCC {   
  CIRCLE[h (120*GV)]   
3. Code that crashes CF on my PC (win vista): (a totally empty path declaration)

Code: Select all

startshape AA

shape AA
{ AAA()[]  }

path AAA()
{  }
This is not a big problem. But you should remember to save often when writing paths.

Merry Christmas everybody

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

Re: Vectors and global variables

Post by MtnViewJohn »

1. I limited vectors to 9 because there are a few places where temporary results are stored in the stack. I will find these places and see if I can use the new variable size array feature in C++11.

2. The GV=2 declaration in shape AAA creates a new variable named GV that supersedes the global GV variable within shape AAA, but then goes out of scope and vanishes. This leaves the global GV variable as the only one in scope for shape BBB. Context Free does not have mutable state, even when impurity is turned on.

There is one outstanding bug with global variables. If you have a global variable that is not constant (i.e., it's random or depends on frame()/ftime()) and you use it in a configuration declaration then it will evaluate to zero or garbage. The variable will work fine inside of shapes/paths, but not in configs.

3. If there are no parameters then there should not be empty parentheses. I debated whether to allow empty parens as an option but decided to be strict. I will find out why it crashes and have CF issue an error instead.

Post Reply