F.E.L.T.

Functionally Equivalent Language Translation

CVAR

    (cvar var-name)                   ; public class variable is the default
    (cvar+ var-name)                  ; public class variable
    (cvar# var-name)                  ; protected class variable
    (cvar- (var-name default-value))  ; private class variable
    
    (cvar var-name-1                  ; multiple CVAR-s will all have the
          var-name-2                  ; same level of access control
          (var-name-3 "default"))

See also DEFCLASS CLASS MVAR

You should only use CVAR within a current CLASS declaration as it makes no sense to use it anywhere else. You can define a single variable with or without a default value or you can define many variables at once, again with or without a default value.


Alternative Forms

FELT supports the notion of class variables that can be "public", "private" or "protected" and in order to express those intentions you can choose from the following:

Instruction Visibility
CVAR public
CVAR+ public
CVAR- private
CVAR# protected


Define a class variable

For full details on how to compose a "class", read the CLASS page as that goes into some detail on how to declares classes in general. This page is more concerned with the actual means of declaring class variables.

Sometimes referred to as "static" variables as well in some quarters, these variables allow for a single instance of something to be maintained regardless of how many instances of the class are minted at run-time... why is that useful, in a word, a single word in fact: Singletons!

Despite the current trend of "singleton pattern considered harmful" it will be a long long time before this very useful pattern goes away and FELT therefore supports it and any other uses you may want for class / static variables.

One at a time

To define a class variable you just name the variable within the CVAR instruction like so:

(class Foo (cvar bar))

With default values

If you want to supply a default value then you use the same syntax as for when you write a function signature with DEFUN/FUNCTION, by placing the variable name and the default value inside parentheses like so:

(class Foo (cvar (bar 100)))

Multiple definitions

Instead of having to laboriously type CVAR for every single class variable, you can in fact supply multiple of them at once like this:

and the FELT process will