Sb forum speech.png DiscordLink.png FacebookLink.png RedditLink.png SteamLink.png TwitterLink.png YoutubeLink.png

Difference between revisions of "YOLOL Tricks"

From Starbase wiki
Jump to navigation Jump to search
(Negation)
m (Separated Not into its own Number Tricks section)
Line 18: Line 18:
|-
|-
| Contains || '''s="~meh~foo~bar~"<br/>t="foo"<br/>c=s>s-("~"+t+"~")''' || Evaluates to 1 if '''t''' is present in test set '''s''', and 0 if not<br/>Alternatively, '''!=''' can be used instead of '''>''', in which case, this is more flexible with regards to the values in '''s'''<br/>Depending on the values that can occur in '''s''' and '''t''', some or all of the delimiters '''"~"''' can be omitted, or changed into other values, such as numbers.
| Contains || '''s="~meh~foo~bar~"<br/>t="foo"<br/>c=s>s-("~"+t+"~")''' || Evaluates to 1 if '''t''' is present in test set '''s''', and 0 if not<br/>Alternatively, '''!=''' can be used instead of '''>''', in which case, this is more flexible with regards to the values in '''s'''<br/>Depending on the values that can occur in '''s''' and '''t''', some or all of the delimiters '''"~"''' can be omitted, or changed into other values, such as numbers.
|}
== Number tricks ==
{| class="wikitable"
|-
|-
| Not || '''0^b'''<br/>'''1-b'''<br/>'''b==0''' || Used to negate a '''0''' or '''1''' value.<br/>'''0^b''': Does not need parenthesis when used in a multiplication. Works with values other than only '''0''' and '''1'''. Requires an Advanced or Professional chip<br/>'''1-b''': Works '''only''' with '''0''' and '''1'''. Works on all chips.<br/>'''b==0''': Works with values other than only '''0''' and '''1'''. Works on all chips.<br/><br/>For '''0^b''' and '''b==0''', any '''non-0''' input will give '''0''' as the output.
! Nickname !! Code !! Explanation
|-
| Not || '''0^b'''<br/>'''1-b'''<br/>'''b==0''' || Used to negate a '''0''' or '''1''' value.<br/>'''0^b''': Does not need parenthesis when used in a multiplication. Works with values other than only '''0''' and '''1'''. Requires an Advanced or Professional chip<br/>'''1-b''': Works '''only''' with '''0''' and '''1'''. Works on all chips.<br/>'''b==0''': Works with values other than only '''0''' and '''1'''. Works on all chips.<br/><br/>For '''0^b''' and '''b==0''', any '''non-0''' input will give '''0''' as the output
|}
|}



Revision as of 23:26, 15 February 2021

Русский Українська

YOLOL is a rather constrained language. The line and chip length limits and slow execution speed incentivize clever shortcuts. The small math library and limited operation space require building larger operations from smaller building blocks. To those ends, this page serves to catalog a variety of things you can accomplish with YOLOL that might not be obvious from the main [YOLOL] documentation.

String Manipulation

Nickname Code Explanation
Pop string---string Evaluates to the last character in string and removes that character, "abcd" becomes "abc" while evaluating to "d"
If Empty string-(string+otherstring) If otherstring is empty then this evaluates to an empty string, else it evaluates to string
Select a="foo1" b="bar2" c="meh3"
x=2
s=a+b+c-x-a-b-c
s=="bar"
One string from a set can be selected by concatenating them with indices, then removing an index, then removing all the strings which will fail for the un-indexed one. If one index is a substring of another then the order of the strings will matter.
Contains s="~meh~foo~bar~"
t="foo"
c=s>s-("~"+t+"~")
Evaluates to 1 if t is present in test set s, and 0 if not
Alternatively, != can be used instead of >, in which case, this is more flexible with regards to the values in s
Depending on the values that can occur in s and t, some or all of the delimiters "~" can be omitted, or changed into other values, such as numbers.

Number tricks

Nickname Code Explanation
Not 0^b
1-b
b==0
Used to negate a 0 or 1 value.
0^b: Does not need parenthesis when used in a multiplication. Works with values other than only 0 and 1. Requires an Advanced or Professional chip
1-b: Works only with 0 and 1. Works on all chips.
b==0: Works with values other than only 0 and 1. Works on all chips.

For 0^b and b==0, any non-0 input will give 0 as the output

Code Golf

If you want to develop readable code and only shorten it for deployment, consider using yodk or Yololc which can minify your code for you.

Shortening identifiers to one character saves bytes, use f=b rather than foo=bar.

Reassigning fields to identifiers saves bytes if you use them more than a few times. f=:f f f f f f f f f is shorter than :f :f :f :f :f :f :f :f .

Most whitespace is optional. You only actually need a space when code would be ambiguous without it. Spaces can almost always be omitted before :, after if or then or end, between a number or symbol and a letter, and in various other places.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.