gecho

From Esolang
Jump to navigation Jump to search

The gecho programming language is often referred to without a capital 'g', and was created by Max Bernstein (User:Tekknolagi) in summer of 2011.

Inspiration

This language was inspired by Forth. It is stack-based.

Naming

This language was named after a typo by the author. He "meant to type 'echo' but wrote a 'g' in front by accident."

Commands

NOTE: gecho does not by default display the result of the operation! One must use `.`

  1. +
    Pops two elements from the stack, adds them together, and pushes the result.
  2. ++
    Pops all the elements from the stack and adds them together; pushes result.
  3. .
    Prints the top element in the stack.
  4. *
    Pops two elements from the stack, multiplies them, and pushes the result.
  5. dels
    Pops all elements from the stack.
  6. show
    Pretty prints the stack.
  7. dup
    Pushes a copy of the top element of the stack.
  8. swap
    Pops two elements from the stack, and pushes back in each other's places.
  9. -
    Pops two elements from the stack, subtracts the upper from the lower, and pushes the result.
  10. jump
    Pops an element from the stack (a) and prints stack[a]
  11. range
    Pops two elements from the stack (a, b) and prints range(b, a); starts at b, increments by one until a, pushes the array onto the stack.
  12. [num]
    Pushes `num` to the stack.
  13. **
    Pops all the elements from the stack and multiplies them; pushes result.
  14. ![tapeindex]
    Pop element from stack; set variables[tapeindex] to popped value.
  15. &[tapeindex]
    Push variables[tapeindex] to the stack.
  16. wover
    a = pop(); b = pop(); push(b); push(a); push(b); ( a1 a2 -- a1 a2 a1)
  17. drop
    Pop top element from stack, show value.
  18. pop
    see `drop`
  19. top
    Push the index of the top of the stack to the stack.
  20. outascii
    Pop top element of stack and print ASCII character that corresponds to decimal.
  21. print
    Pop all elements of stack and prints ASCII characters that correspond to decimal.
  22. /
    Pop top two elements from stack; divide lower element by upper element.
  23. @[mode]
    Toggles mode specified.
  24. mode
    Prints a list of all enabled modes.
  25. modes
    Prints all modes, complete with 'enabled' flag.
  26. tot
    For use with @tracker. Prints number of commands so far. Does not count as a command.
  27. reset
    Resets the command count. For use with @tracker. Does not count as a command.
  28. tan
    Pops one element from the stack (degrees!) computes tan(x)
  29. sin
    Pops one element from the stack and computes sin(x)
  30. cos
    Pops one element from the stack and computes cos(x)
  31. pow
    a = pop(); b = pop(); push(b^a);
  32. mod
    a = pop(); b = pop(); push(b%a);
  33. read
    Reads user input. Only really useful with file reading/compiling. Pops one element from the stack and reads that number of numbers, and pushes them to the stack.
  34. <
    b = pop(); a = pop(); push(a < b);
  35. >
    a > b
  36. >=
    a >= b
  37. <=
    a <= b
  38. =
    a == b
  39. '[word]
    Push each character of <word> onto the stack.
  40. <>
    Push ' ' to the stack.
  41. and
    Push a && b to the stack.
  42. or
    Push a || b to the stack.
  43. nil
    Does absolutely nothing.
  44. next
    Cycles through the stacks. If on stack 1, will move to stack 2.
  45. back
    Does the opposite of `next`.
  46. mv
    Moves the top element from the current stack to the next stack. To COPY, use `dup mv`.

Turing completeness

It is not yet Turing complete.

Examples

Hello World

'Hello, <> 'world! print

Limited Fibonacci

0 1 dup wover + dup wover + dup wover + dup wover +

Factorial

5 1 range **

Pushes the numbers 1 through 5 onto the stack, and then multiplies them all.

Multiple Stacks

1 2 + show next 3 4 + show

Computes 1+2, shows it, moves to the next stack, computes 3+4, and shows it.

See `mv` on how to exchange information between stacks.

Future Syntax

Loops

5 0 [ i ]

This pushes 5 and 0 to the stack, and then iterates from 0 to 5. `i` pushes the counter to the data stack each iteration. Fibonacci in a loop:

0 1 10 0 [ dup wover + ]

Iterates from 1 to ten, calculating 10 fibonacci numbers.

If Statements

if { 2 3 < ; 1 + ; 1 - }

If `2<3`, it adds one to the top of the stack. Otherwise, it subtracts one.

Function definitions

@sayhi { 'hello <> 'world print }

Stores the body into the function `sayhi` and whenever `*sayhi` is seen, it calls `sayhi`. Uses the stack for arguments.

@add { + }

Takes two arguments from the stack, adds them, and pushes the result.

Implementations

Downloadable

Its original implementation (and current implementation) can be found here.

Online Interpreter

One can experiment with gecho in an online interpreter here.