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

YOLOL Tricks

From Starbase wiki
Revision as of 03:02, 5 August 2021 by DerPfandadler (talk | contribs) (begone pop that never worked)

Jump to navigation Jump to search
Русский Українська

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
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, if the values in the string to test (s) are arranged in alphabetically descending order, s>s-("~"+t+"~") can also be used.
For non-distinct values, (for example searching for "tin" in the string "non-distinct values") the delimiter ("~") can be omitted.
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 any non-negative input value, not 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 all input values, not only 0 and 1. Works on all chips.
Select a+(b-a)*s
a*0^s+b*s
Select one of a or b based on a 0 or 1, s select signal.
Equivalent to if s then result=b else result=a end

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.