FlogScript

From Esolang
Jump to navigation Jump to search

FlogScript is a programming language by User:Zzo38, similar to GolfScript but it is different. No documentation yet, read the examples and source code to try to figure it out.

Flogscript is similar to golfscript in some ways. It shares the philosophy of having heavily overloaded single-character operators, which help enable compact code. They are both stack-based languages.

In flogscript, there are only 3 basic data types.

  • numbers. Example numbers are 1 5 7 etc
  • strings. Example strings are {this is a string} {hello world.} lowercaseonly'
  • arrays. Example arrays are [ 1 2 3 ] [ 4 5 6 ]

Unlike golfscript, there is no such thing as a native "block" type. Operators in golfscript which are overloaded differently for (array + string) and (array + block), have fewer meanings in flogscript.

Uppercase and lowercase appear to have different meanings. All builtin functions which are not single characters, consist of one or two uppercase letters, followed by a lowercase letter or punctuation symbol. It's probably necessary for all user variables to begin with a lowercase letter.

Variables are defined by ending them with :

 0 idx:

There are no comments. At least, # does not start comments. An equivalent to comments, is to just push a string and immediately pop it off the stack with ; So, {This is equivalent to a comment.};

The "standard library" of builtin functions, is huge compared to golfscript, and this feels like the primary reason it typically enables shorter code than golfscript.

Syntax and operators.

  • { begin a new string (no distinction between literals and code)
  • } end a string (no distinction between literals and code)
  • [ begin defining an array (more precisely "mark")
  • ] end defining an array

Examples

Factorial example:

{
 ,{)}%A*
}fac:

5 fac~ P.

Check if a sentence is a palindrome:

{Evade me Dave!}
Su{/[^A-Z]/}{;{}}S~.Ar=P.

Convert roman numbers to decimal:

0.:Il1/Ar{[1{.5*.2*}3*~]\{IVXLCDM}1/?=._-Ms){_1*}?.Ma:-}/P.

Underload:

Ia:
{
 [
  {\}
  {.}
  {;}
  {+}
  {_{)()}S0\:}
  {{(}\+{)}+}
  {_+:}
  {P.}
  {}
 ]
 _(\:
 {~:!*(a^S}1/?=~
 _,0=!F[
}~

"Strange Numbers" from perl golf challenge:

Il~.2/^M2P,

Beer program:

99{
 .P. { bottles of beer on the wall}P,
 .P. { bottles of beer}P,
 {Take one down and pass it around}P,
 ( .!F]
 .P. { bottles of beer on the wall}P,P_
 F<
}~{No more bottles of beer on the wall}P,

ROT13:

#{A:Za:z}Sx{N:ZA:M}Sx.Sl+St

Display printable characters ASCII table:

32"{[?>!+]}Sb;16/A_100/P.

Reverse order of lines in input:

)Ar

Reverse order of characters on each line in input:

"Ar

BrainFuck interpreter (use ! at end of program) (the one on anarchy golf is completely wrong even if it says FIXED):

[]{!}I0{+<>,.[]-}S5Sb

Count how many of each letters:

IaSua SxS5${/(.)\1*/}S?{0=){  <}P.P.{> }P.,)P.{ TIM}P,}/

Set-theoretic definition of natural numbers:

~f{.`{, }\++}y(*~`

Examples from anarchy golf

Occasionaly the FlogScript code is longer than GolfScript codes (but some might just pass the examples given in anarchy golf without being correct), but the FlogScript code is often shorter.

100 (GolfScript 269, FlogScript 195)

{zero}P,{one.two.three.four.five.six.seven.eight.nine}d/.A_P,{ten}P,{eleven}P,{twelve}P,.(;{twen}\0
A={thir}\1 A={fif}\3 A={eigh}\6 A=.(;{{teen}+P,}/{for}\2 A=\e\+\At{Ar{ty }A,P,}/{one hundred}P,

257 (GolfScript 30, FlogScript 19)

35,{2+257\10@MbSuP,

capital and small letters (GolfScript ?, FlogScript 25)

[IlSl.Su1/\1/]AzAt{A.P,}/

Card Sharp (GolfScript 105, FlogScript 93)

)a S5:[[{Ace}9,i%i%~{Jack}{Queen}{King}]{Spades.Hearts.Diamonds.Clubs}d/At{{ of }A,._ Sc!Z^}%

cut string (GolfScript ?, FlogScript 7)

)Ar~~/(

delete duplicate lines (GolfScript 6, FlogScript 3)

).|

delete last line (GolfScript 6, FlogScript 5)

)););

double back lines (GolfScript 14, FlogScript 7)

".Ar(;+

Drop first line (GolfScript 4, FlogScript 3)

)(;

duplicate lines (GolfScript 8, FlogScript 4)

".P,

GCD of 1 to n (GolfScript 5, FlogScript 2)

"1

happy number (GolfScript 28, FlogScript 24) (very slow)

2000,{{`1/sq%A+}F91=}^Pa

invert case (GolfScript 6, FlogScript 13)

#a.SlAr+.ArSt

judge Janken (GolfScript 32, FlogScript 28) (AKA Rock Paper Scissors)

"s/{"0=17%10%)2/}/-2*)3%60+"

N Queens (GolfScript ?, FlogScript 39)

~~,}o%At{A?F|.}:{._#y,X+_#y,"X+_#;A#}%$

Numeral system (GolfScript 31, FlogScript 7)

"s/~\Md

Quine (GolfScript 1, FlogScript 8)

{)S|]}Fy

Palindromic Quine (GolfScript 19, FlogScript 13)

{)P.}FyF}.P){

Phone Key Pad (GolfScript ?, FlogScript 44)

#Su{+A:Z-}Sx{122233344455566070778889990*}St

reverse lines (GolfScript 7, FlogScript 2)

)"

rotate lines (GolfScript 7, FlogScript 5)

));(+

rotate lines reversely (GolfScript 9, FlogScript 6)

));)P,

Summation (GolfScript 12, FlogScript 11)

"0+.!F]),A+

sum of square numbers (GolfScript 14, FlogScript 13)

"~..)*\2*)*6/

Underload interpreter (GolfScript 20(cheat), FlogScript 64(genuine))

Ia:{{\ . ; + _{)()}S0\: j\+i+ _+: ]}s/_(\:{~:!*(a^S}1/?=~_,0=!F[

zero lines (GolfScript 10, FlogScript 7)

",0`\*]

Operators and builtin functions (very incomplete list)

Numeric.

  • + add
7 5 + -> 12
  • * multiply
7 5 * -> 35
  • ) increment
1 ) -> 2

Foreach-like.

  • / loop
[ 1 2 3 ] { 2 * P, } / -> prints 2\n4\n6\n
[ 1 2 3 ] { 2 * } / -> stack is now 2 4 6
  • % loop
[ 1 2 3 ] { 2 * P, } % -> prints 2\n4\n6\n    
[ 1 2 3 ] { 2 * } % -> stack is now [ 2 4 6 ]
  • * fold
[ 1 2 3 ] { + } * P, -> prints 6\n

String.

  • / split. By length or on a character.
{asdf} 1 / -> [{a} {s} {d} {f}]
{asdf} {s} / -> [{a} {df}]
  • Sx Escape.
{Hello World\n} Sx -> {Hello World\n} (with a real newline instead of \n)
{Unbalance \C} Sx -> {Unbalance {} 
  • " ascii codepoint to chr
32" -> { }
72" P. 105" P. 32" P. 116" P. 104" P. 101" P. 114" P. 101" P. 46" P.  
-> prints "Hi there"

Also reverses. String to list of codepoints.

{Hi there}" -> [72 105 32 116 104 101 114 101 46]
  • n Predefined to mean "\n"
  • S] trim trailing whitespace
{Hello   } S] -> {Hello}
  • S[ trim leading whitespace
{  Hello} S[ -> {Hello}
  • S| trim leading and trailing whitespace
{  hi there   } S| -> {hi there}

Array.

  • / chunk. By length
[ 1 2 3 4 5 6] 2 / -> [ [1 2] [3 4] [5 6] ]
[ 1 2 3 4 5 6] 3 / -> [ [1 2 3] [4 5 6] ]
  • A. join
[ {a} {s} {d} {f} ] A. -> {asdf}
  • + concat
[ 1 2 3 ] [ 4 5 6 ] + -> [1 2 3 4 5 6]
  • * multiply
[ 7 ] 3 * -> [ 7 7 7 ]
  • < slice, range 0..idx
[ 7 9 12 15 19 ] 2 < -> [7 9]
  • > slice, range idx..end
[ 7 9 12 15 19 ] 2 > -> [12 15 19]
  • A= edit
35 [ 7 9 12 15 19 ] 2 A= -> [7 9 35 15 19]

Note that the new value is still on the top of the stack. It doesn't edit the original variable. So

[ 7 9 12 15 19 ] array:
35 array 2 A= ;
array Pa
-> prints 7 9 12 15 19

The name needs to be resaved after each edit. So

[ 7 9 12 15 19 ] array:
35 array 2 A= array:
array Pa
-> prints 7 9 35 15 19
  • ( shift or uncons start of list
[ 1 2 3 ] ( -> [2 3] 1
  • ) shift or uncons end of list
[ 1 2 3 ] ) -> [1 2] 3

Stack manipulation.

  • ; pop top of stack
  • . dup top of stack

Input.

  • Ia Read all of stdin, and push it to the top of the stack.

Output.

  • P. pop and print top of stack, without a newline
  • P, pop and print top of stack, with a newline
  • Pa pop and print array, newline between each element

External resources