Satisfying number parameter requirements

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

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
User avatar
pakin
Posts: 43
Joined: Sat Apr 21, 2007 8:59 pm
Location: United States
Contact:

Satisfying number parameter requirements

Post by pakin »

I'm a bit puzzled by CF3's number parameter requirements. Why is the following forbidden

Code: Select all

startshape begin

shape circular (number radius) {
  CIRCLE [ s radius ]
}

shape forbidden (number minrad, number maxrad) {
  circular(rand(minrad, maxrad)) [ ]
}

shape begin {
  forbidden(10, 20) [ ]
}

Code: Select all

Error in restrict.cfdg at line 8 - This expression does not satisfy the number parameter requirement
while the following is allowed?

Code: Select all

startshape begin

shape circular (number radius) {
  CIRCLE [ s radius ]
}

shape allowed (number minrad, number maxrad) {
  circular(rand(maxrad)) [ ]
}

shape begin {
  allowed(10, 20) [ ]
}
I'd have thought that either both would be verboten (because rand is considered to modify its arguments) or both would be acceptable (because rand is considered not to modify its arguments). What gives?

— Scott

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

Re: Satisfying number parameter requirements

Post by MtnViewJohn »

The second one should not be allowed. Rand is considered to modify its arguments. Otherwise you could use rand to wash away violations of the numeric parameter rules. Context Free has a bug where it is ignoring issues with the first argument in a function.

It is allowing this:

Code: Select all

startshape begin

shape circular (number radius) {
  CIRCLE [ s radius ]
}

shape allowed (number minrad, number maxrad) {
  circular(rand(maxrad, 40)) [ ]
}

shape begin {
  allowed(10, 20) [ ]
}
But forbidding this:

Code: Select all

startshape begin

shape circular (number radius) {
  CIRCLE [ s radius ]
}

shape allowed (number minrad, number maxrad) {
  circular(rand(0, maxrad)) [ ]
}

shape begin {
  allowed(10, 20) [ ]
}
I will put out a release to patch this bug (I'll probably wait for other bugs to be discovered though).

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

Re: Satisfying number parameter requirements

Post by MtnViewJohn »

I have pushed a fix to code.google.com.

User avatar
pakin
Posts: 43
Joined: Sat Apr 21, 2007 8:59 pm
Location: United States
Contact:

Re: Satisfying number parameter requirements

Post by pakin »

MtnViewJohn wrote:I have pushed a fix to code.google.com.
Thanks. My beautiful artwork now correctly fails to compile. :|

— Scott

Post Reply