Check out Grant Acedrex, our featured variant for April, 2024.


[ Help | Earliest Comments | Latest Comments ]
[ List All Subjects of Discussion | Create New Subject of Discussion ]
[ List Earliest Comments Only For Pages | Games | Rated Pages | Rated Games | Subjects of Discussion ]

Single Comment

Game Courier History. History of the Chess Variants Game Courier PBM system.[All Comments] [Add Comment or Rating]
🕸💡📝Fergus Duniho wrote on Wed, Jul 29, 2020 01:34 AM UTC:

I have made a few changes to GAME Code today:

  1. Functions will now evaluate variables when they are called, not when they are defined. In this example, the function x2 returns a different value each time:
def x2 * 2 #x;
set x 12;
print fn x2;
set x 23;
print fn x2;
  1. Functions now allow you to set named my scope variables. To do this, prepend a variable name with the = sign, and follow it with the value you want to copy to the variable. In the following example, the function copies "Chess Variant" to the variable v, and it doubles it. Both before and after calling the function, #v returns the value of "cartoon violence". This is because the function raised the scope, and the my scoped variables it created were destroyed when the function ended.
set v "cartoon violence";
def s2 list #v #v =v "Chess Variant";
print #v;
print fn s2;
print #v;

If more than one argument follows a variable assignment, they will be converted into an array, leaving nothing to the right of the assignment.

  1. Functions now accept named parameters. This works the same way as assigning a value to a variable except that no value follows the assignment. When no value follows the assignment, it pops off a value from the arguments passed to the function. In the example below, the output is 30, 110, and #x, because x has not been defined outside of the function:
def sqrplus + * #x #x #x =x;
print fn sqrplus 5;
print fn sqrplus 10;
print #x;

Numbered parameters will still work, since it would break way too much code if they stopped working. But numbered parameters will not work with named parameters. With numbered parameters, the exact number of arguments to expect is calculated. If too few arguments are given, there is an error message. If too many are given, only the ones that are needed get read and used. This allows code like this to make sense:

def mns - #0 #1;
def multdiff * fn mns #0 #1 #2;
print fn multdiff 5 11 10;

In the multdiff function, the call to mns has three arguments after it. It uses only the first two, leaving the third to be used as an argument for the * operator.

When you use named parameters, you will get an error message if there are not enough arguments. But if there are more than enough arguments, only the last arguments in the list will be used. In the code below, the first function call prints my name, but the second prints my uncle's.

def name list #first #last =first =last;
print fn name Fergus Duniho;
print fn name Fergus Patrick Duniho;

In general, you should avoid extra arguments when using named parameters, but this behavior may prove useful for creating functions that can take a variable number of arguments. To enable this, I have added the args operator, which returns an array of the remaining arguments. Named parameters will shrink the array of arguments by popping them off. So, if you pop them all off, args will be empty. But if you don't, you can do something like this:

def revwords list reverse args;
print fn revwords Fergus Duniho;
print fn revwords Fergus Patrick Duniho;

The revwords function can take a variable number of arguments. It reverses the order of the arguments and makes a string out of them. So, the two calls to the function output "Duniho Fergus" and "Duniho Patrick Fergus".