Glava

From Esolang
Jump to navigation Jump to search

Glava is an esoteric programming language, built on top of a Java base, that is designed to be effective in code golf competitions. It was designed and implemented by ZekNikZ in 2017.

Glava is not designed to be a separate language from Java, it is purely designed as a shorter, more feature-rich version. This includes a custom code page which allows all characters to be a single byte.

Features

Shorthands

Shorthands are single- or double-character shortcuts that are replaced by longer strings. Shorthands are what give Glava much of its power.

Type Shorthands

Type Keywords

  • βboolean
  • χchar
  • δdouble
  • φfloat
  • ιint

Type Classes

  • ΠBoolean
  • ΣCharacter
  • ΔDouble
  • ΦFloat
  • ΓInteger
  • σString

Type Classes w/ new Keyword

  • ηΠnew Boolean( *
  • ηΣnew Character( *
  • ηΔnew Double( *
  • ηΦnew Float( *
  • ηΓnew Integer( *
  • ησnew String( *

Casting

  • ζΠ(boolean)
  • ζΣ(char)
  • ζΔ(double)
  • ζΦ(float)
  • ζΓ(int)
  • ζσ(String)

Loop Shorthands

  • εwhile( closing character adds ){ *
  • Ξwhile(true){ (infinite while loop) *
  • ωfor( closing character adds ){ *
  • Ωfor(int i=0;i< (pre-built for loop) closing character adds ;i++){ *

Command-line Arguments

String Arguments

  • args[0]
  • args[1]
  • args[2]
  • args[3]
  • args[4]
  • args[5]
  • args[6]
  • args[7]
  • args[8]
  • args[9]

Converted Arguments

The shorthands ①②③④⑤⑥⑦⑧⑨⑩ are replaced with their corresponding command-line arguments, after attempting to convert them to another native type. For example, if the first argument is 12.34, will be replaced with 12.34 in the code.

Converted Arguments Arrays

All of these arrays contain only the command-line arguments of that type.

  • glava_args_boolean[ *
  • glava_args_char[ *
  • glava_args_double[ *
  • glava_args_float[ *
  • glava_args_int[ *
  • glava_args_String[ *

Output

  • πSystem.out.print( *
  • λSystem.out.println( *
  • κSystem.out.printf( *

Misc

  • υ.length()
  • ύ.length
  • ϋ.size()
  • ηnull
  • ώ}; (also a group closer)

* This shorthand opens a group.

Automatic Code-Completion

Glava has the great feature of being able to auto-complete many parts of your code.

Automatic Group Closing

If, throughout your code, you open any groups ((, {, [, etc.) but never close them, Glava will close them automatically when compiling. Note that this does not work the other way around.

Example: λ"Hello, World! will be closed by λ"Hello, World!", and then by System.out.println("Hello, World!).

Automatic main Method and class Wrapping

Glava also has the ability to wrap your entire code in a main method, assuming it does not have one. And then, if it does not have a surrounding class, it will wrap the code in public class Main { ... }.

Additionally, if Glava wraps the code in a class, several other features are added as well. All of the following are added into/around the Main class as well:

Default Imports

  • java.util.*
  • static java.lang.Math.*
  • java.io.*
  • java.awt.*
  • javax.swing.*
  • java.text.*
  • java.util.regex.*

Default Class (Static) Variables

  • int m = 0
  • int n = 1
  • double d = 0d
  • float f = 0f
  • String s = ""
  • String t = "\n"
  • String u = "abcdefghijklmnopqrstuvwxyz"
  • String U = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  • char c = 'A'
  • boolean T = true
  • boolean F = false

Command-line Converted Argument Arrays

Note: only the applicable arrays are created when the program is run. Also, note that all of these arrays also have shorthands.

  • int[] glava_args_int
  • double[] glava_args_double
  • float[] glava_args_int
  • char[] glava_args_char
  • boolean[] glava_args_boolean

Miscellaneous Features

On this wiki page you can find a list of all of the miscellaneous features of Glava that do not fit in another category.

Multi-line Strings

Instead of using \n for linefeed characters in strings, in Glava, you can use literal linefeeds.

Shorter char Literals

Not as important, but all char literals in Glava no longer use and ending single quote ('c is a char literal in Glava but 'c' is not).

Custom Code Page

To be able to use more characters in programs, Glava has a custom code page which can be found here.

Examples

Hello, World!

λ"Hello, World!

FizzBuzz

λ(①%3<1?"Fizz":s)+(①%5<1?"Buzz":①%3<1?s:①

99 Bottles of Beer

n=99;A=new String[]{" bottles of beer on the wall"," bottles of beer.
Take one down, pass it around, ","Better go to the store and buy some more."ώwhile(n>0){λn+A[0]+", "+n+A[1]+(--n)+A[0]+".
");}λA[2]

External Resources