1+/Snippets

From Esolang
Jump to navigation Jump to search
Back to 1+

This is horrible and I'm very sorry. -- A random PPCG user

This page provides common code snippets for easy 1+ programming (and golfing).

Any unused function name represents, uh, any unused valid function name. Some snippets involves control flow and is wrapped in a function definition to create a seperate line of execution, and prevent affecting the rest of the program.

Easy

Very short and trivial snippets.

Push 0

11+1<

Negate

1+1<

Truthify

Yeah, you can negate it twice, but this is much shorter:

1^<

Pop

Only works when there's more than one element on the stack.

"<*

Universal Pop

Works anywhere.

(Any unused function name|"<##)

Comparison

Less than: (This saves 1 byte compared to ^<1+1<.)

^1+^<

More than: (This saves 1 byte compared to <1+1<.)

1+^<

Medium

Longer and harder to understand snippets. They involve stack manipulation.

Equality

"/^"\</<\*

Ternary

That is, returns a for a b 0 on the stack (stack top is on the right), and b for a b 1 on the stack.

"1+1</*^\*+

Hard

Involves control flow. Some of these takes an afternoon to make.

Operations

Decrement

(Any unused function name|"1<11+1<^#1+^"/^"\^1+<#)

Subtraction

(Any unused function name|11+1<11+##1+^1+^11+#/"/^"/^\\<11+*1+\^#)

Square root

If the square root is not an integer, rounds to the nearest *larger* integer.

(Any unused function name|"1<11+1<^#1+^"/^"\^"*<#)

Control Flow

Do-while loop

Let's say your pseudo-code is:

do { code } while (!x)

Assuming x is already a boolean and not an integer. (Otherwise you need to convert it to boolean with 1^<.)

(Any unused function name|1##
    [code]
[push x]1+#)

While loop

Pseudo-code:

while (!x) { code }

Compiles to:

(Any unused function name|[push x]#
    [code]
[push x]#)

This was originally very, very bulky when it was first created.

If block

Pseudo-code:

if (!x) { code }

Compiles to this 1+ code:

(Any unused function name|[push x]#
    [code]
1#)

If-else block

Pseudo-code: (Please note code2 comes before code1.)

if (x) { code2 } else { code1 }

Compiles to this 1+ code:

(Any unused function name|[push x]#
    [code1]
11+#
    [code2]
11+#)

Sometimes this works, depending on your operation in code1 and code2:

(Any unused function name|11+[push x]#
    [code1]
#
    [code2]
#)

Insane

Obviously Medium-Graded

Legendary

Snippets about Lyxal (User:JonoCode9374)

COME BACK LYXAL!!!

(|111+")(_|""+*"*+)+";1111++"( |"+"*+"++;)()1+( )()+"""**++;()"""+"**";^"(_);()"+*"*+;\;()++"""++*;;""1+"+"*+"+";1111++"""*"*+++"1+;;()"+*"*+;;()"+"**+"";;;