Check out Symmetric Chess, our featured variant for March, 2024.

Enter Your Reply

The Comment You're Replying To
🕸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".


Edit Form

Comment on the page Game Courier History

Quick Markdown Guide

By default, new comments may be entered as Markdown, simple markup syntax designed to be readable and not look like markup. Comments stored as Markdown will be converted to HTML by Parsedown before displaying them. This follows the Github Flavored Markdown Spec with support for Markdown Extra. For a good overview of Markdown in general, check out the Markdown Guide. Here is a quick comparison of some commonly used Markdown with the rendered result:

Top level header: <H1>

Block quote

Second paragraph in block quote

First Paragraph of response. Italics, bold, and bold italics.

Second Paragraph after blank line. Here is some HTML code mixed in with the Markdown, and here is the same <U>HTML code</U> enclosed by backticks.

Secondary Header: <H2>

  • Unordered list item
  • Second unordered list item
  • New unordered list
    • Nested list item

Third Level header <H3>

  1. An ordered list item.
  2. A second ordered list item with the same number.
  3. A third ordered list item.
Here is some preformatted text.
  This line begins with some indentation.
    This begins with even more indentation.
And this line has no indentation.

Alt text for a graphic image

A definition list
A list of terms, each with one or more definitions following it.
An HTML construct using the tags <DL>, <DT> and <DD>.
A term
Its definition after a colon.
A second definition.
A third definition.
Another term following a blank line
The definition of that term.