Micro

From Esolang
Jump to navigation Jump to search

This language was created by user:Raddish0 as an attempt to make a code golfing language that is easier to understand than Golfscript.

It is currently under development, so expect some changes.

keywords

These are not allowed as variable, or function names. Remember: This language is case-sensitive

  • I
  • s
  • r
  • R
  • c
  • C
  • l
  • m
  • if
  • SB
  • BS
  • NS
  • SN
  • AS
  • SA

Types

  • string (basically an array that is treated differently on the iostream)
  • number (arbitrary precision - depends on the implementation)
  • array (list of numbers)
  • block (code block)

Built-in functions

note that a Micro has implicit evaluation, so program will always pop the value at the top of the stack, and evaluate it at the end of execution

IMPROTAND: Micro's implicit evaluation is weird, because the evaluated variable may generate new items on the stack, in which case the program's execution will continue as if it hadn't ended. This means that implicit evaluation can occur many times in just one execution of the program. This makes the example quine possible

; comment
{a} push a code block with the content 'a'
" toggle StringMode (when string mode is turned on, everything typed will be pushed to the stack as one string)
[1 2 3] push an array with the content 1,2,3 (note that ([5][5]) will create a 2-dimensional, 5x5 array)(negative addresses on lists are allowed, blank positions will be filled with a space when AS is applyed)
:A pop an item from the stack, and assign it to A (if a code block is assigned, calling the var runs the block) (note that when the stack is empty, this will just return zeros)
A push A
~ swap the top 2 items on the stack
| duplicate top element of stack

(A,B,C)... are the elements of the stack, with rightmost on top.

< (without popping the args) push the result of A<B true-1 false-0
> (without popping the args) push the result of A>B true-1 false-0
= (without popping the args) push the result of A=B true-1 false-0 (when comparing different sized strings, this changes so that instead, it looks to see if the smaller is present in the larger.)
| (without popping the args) logical or
& (without popping the args) logical and
! (without popping the args) logical not
, input, and push a number
. pop and run a function, or pop and display a variable
_ push the last thing popped from the stack (at the start of the program, before anything has been popped, this will not do anything)
# clear stack
+ (a,b) -> (a+b) [a b c][e f] -> [a b c e f] 'a' 'bc' -> 'abc' {abc}{de} -> {abcde} 2 3 -> 5
- (a,b) -> (a-b) please note: when this operator is directly to the left of a number, it will negate it, and not operate as a minus
* (a,b) -> (a*b) (this also works for strings, e.g: "hi" 5 * returns "hihihihihi"
/ (a,b) -> (a/b)
% (a,b) -> int(a/b)
s (a,b) -> (list made of string a, split every b characters) splits a string , or block. (If b is a character, than a will be split at every occurance of b)
c (without popping args) push the ascii equivalent of the number on top of the stack)
C (without popping args) push the ascii number for a 1 char string on top of the stack, otherwise for multi-char strings, it pushes a list of numbers representing the ascii chars
l (DELETES args) pushes the length of the previous token (array, or string)
L 'letter'- pushes one character from iostream. this also deletes the character from the iostream que
m (a,b) -> (the item at position b of a ) (where a is a string of an array) (another way to access an array is (a[5]), that will return the 5th element of a)
r (a,b,c) -> () replace value at position c in array a with b, pops all 3 values (also works with strings)
R (a,b) (without popping args) call a b times.
I (without popping args) push the integer part of a number on top of the stack
\ push entire iostream, while clearing it (so \:a inputs a string to a)
SB convert the string at the top of the stack to a Block
BS convert the block at the top of the stack to a String
NS convert the number at the top of the stack to a String
SN convert the string at the top of the stack to a Number
if(a,b) pops an element from the stack, if it's >0 push a, and execute it as a function; else push b, and execute it as a function. (so a, or b can be blocks, or functions) note that either a, or b can be omitted, but not both.
SA convert the string at the top of the stack to an Array
AS convert the array at the top of the stack to a string

Some example programs

Hello world program:

"Hello, World!"

Quine:

{_BS}

(Very) Simple Calculator:

{\\\~++SB:C C:\c}:c c

A BF interpreter, proving this language to be turing-complete:

{bval 1 -}:jumpbackl {bval 1 +}:jumpbackr 1:tapepos 1:i [0]:tape 29999:tapelen {i 1 - prg i m :jmpchar jmpchar "[" = if(jmpbackl,) p p "]" = if(jmpbackr,) bval 0 = if(,jumpback)}:jumpback {tape [0] + :tape tapelen 1 - if(tapesetup,)}:tapesetup {}:null {char "+" = if(plus,) p p "-" = if(minus,) p p "<" = if(left,) p p ">" = if(right,) p p "." = if(print,) p p "," = if(in,) p p "[" = if(leftb,) p p "]" = if(rightb,)}:command {prg i m :char prg l :len command i>len i 1 + if(null,main)}:main "BF interpreter":\ \:prg tapesetup main {tapepos 1 -}:left {tapepos 1 +}:right {tape tapepos m 1 + (tape,tapepos)}:plus {tape tapepos m 1 - (tape,tapepos)}:minus {tape tapepos m :\}:print {\: (tape,tapepos)}:in {}:leftb {1:bval tape tapepos m 0 > if(jumpback,)}:rightb

ROT13 (warning, this is a bit golfed):

:i\:n{i1+:i n i m C13+ 64 26+ > if(:26-,) c n ~ i r:n}.n.


Truth machine:

{1:/o}:o {0:/}:z
/: SN 0= if(z,o)


see http://txt.do/d0tyb for a RPN-based 4-function calculator (better than the 'simple calculator')

There is extensive commenting, so please take a look ↑