12
\$\begingroup\$

Jolf is a procedural golfing language made by @CᴏɴᴏʀO'Bʀɪᴇɴ.

What tips do you have for golfing in Jolf?

Please post one tip per answer.

These tips should be at least somewhat specific to Jolf, e.g. remove comments is an answer, but not a very good one.

\$\endgroup\$
  • \$\begingroup\$ Welcome to the site, please read the How to Ask page and the tour page for more information. \$\endgroup\$ – Rɪᴋᴇʀ Dec 20 '16 at 16:32
4
\$\begingroup\$

JavaScript fall back

If for some strange reason Jolf isn't golfy enough, or simply cannot cope, it may be of use to use JavaScript eval. This can happen in one of two ways.

1. Designed eval

Anything inside of $...$ is literally carried over to the JS transpilation. For example, +3$~$5 transpiles to add(3, ~5). Equivalently, +3:~5.

2. Array eval

You can use JS arrays in Jolf! Mostly. It's kind of a bug, but I'm not going to fix it. For example:

u[3*5,5/6,(3+4)/5]

Transpiles to:

sum([2 * 3, 5 / 3, (3 + 4) / 5]);
\$\endgroup\$
  • 1
    \$\begingroup\$ If for some strange reason Jolf is golfy enough (...?) \$\endgroup\$ – Erik the Outgolfer Jan 6 '18 at 17:03
  • \$\begingroup\$ @EriktheOutgolfer isn't ** \$\endgroup\$ – Conor O'Brien Jan 6 '18 at 18:30
7
\$\begingroup\$

Know your auto-assigning variables!

Jolf has many ways to "auto assign" variables. The standard one is γ, which takes the value of the next expression. Β is the same thing, but converts the next expression to a number.

Also, ζ (zeta) is a variable initialized to -1/12 (guess why), and can be re-assigned with Ζ (Zeta).

For example, let's say you want to compare I (the input string) to an operation over itself. For now, let's see if I + I = reverse(I + I). This is written as, conventionally:

=+II_+II

But this can be golfed down to:

=γ+II_γ
\$\endgroup\$
  • \$\begingroup\$ Does your -1/12 zeta have to do with string theory? I know of a way to add up every natural number and obtain -1/12 \$\endgroup\$ – DeepDeadpool Apr 25 '16 at 18:45
  • 1
    \$\begingroup\$ @GheyPhistor Which string theory? But yeah, it's that the zeta function over the natural numbers is -1/12. \$\endgroup\$ – Conor O'Brien Apr 25 '16 at 18:48
6
\$\begingroup\$

Use @

@ is a command that takes the next character in the source code and returns that character's code point. (For example, @X returns 88.) This is often very useful since you can express any number between 0 and 255 in two bytes.

\$\endgroup\$
  • \$\begingroup\$ "between 100 and 255" \$\endgroup\$ – Leaky Nun Apr 25 '16 at 14:49
  • \$\begingroup\$ @KennyLau In Jolf, 10 is actually the number 1 and the number 0 not the number 10, so it's more like 10-255. \$\endgroup\$ – a spaghetto Apr 25 '16 at 14:52
  • \$\begingroup\$ I see, thanks.. \$\endgroup\$ – Leaky Nun Apr 25 '16 at 14:53
4
\$\begingroup\$

Read the source

As of right now, there are a lot of undocumented things -- the mysterious m module among them, which has a lot of builtins. However, they do exist in the source, and it's really not hard to read once you get the hang of it, so read the source.

\$\endgroup\$
  • 1
    \$\begingroup\$ The mysterious math module. \$\endgroup\$ – Conor O'Brien Apr 25 '16 at 14:42
  • 1
    \$\begingroup\$ module. (6 more to go...) \$\endgroup\$ – Leaky Nun Apr 25 '16 at 14:48
2
\$\begingroup\$

Increase Function Arity

Every function has an arity. For example, + has an arity of 2. If you want to (say) add 5 elements, you could use 5 +s... or do +θ12345. Specifically:

  • θ incrases the arity of the function by 3.
  • increases the arity of the parent function by 3. (So *+~θ345678 increases the arity of the * by 3)
  • M increases the arity of the function by 2.
  • ~M increases the arity of the parent function by 2.
  • ; increases the arity of the function by 1.
  • ~; increases the arity of the parent function by 1.
  • η decreases the arity of the function by 1.
  • decreases the arity of the parent function by 1.
  • \xad sets the arity of the parent function to the next character's charcode.
\$\endgroup\$
  • \$\begingroup\$ What's the advantage of *+~θ over *θ+? \$\endgroup\$ – user253751 Apr 26 '16 at 22:52
  • \$\begingroup\$ @immibis There isn't in that case, it was merely illustrative. There are some functions in Jolf that pass two functions when parsed. Then, the only way to access the top function's arity is using ~<char>. \$\endgroup\$ – Conor O'Brien Apr 26 '16 at 22:58
2
\$\begingroup\$

Take advantage of implicit input

If a function does not have enough arguments, it will look to the input for the remainder of the arguments. For example:

+uz

Would transpile to:

add(sum(unaryRange(x)), x)

It's equivalent to

+uzxx
\$\endgroup\$
1
\$\begingroup\$

Use o to store values

Similar to how other languages can assign variables for easy/short referencing, Jolf has o.

For example, oThx prints the input plus 1.

This is a useless example, but when the expression is more complicated than hx, it can save some serious byteage.

Also, v"var name"<val> allows for a multi-char variable name, and V"var name" gets a variable from the scope.

Thanks to Conor for explaining this to me, and giving the previous sentence.

\$\endgroup\$
  • \$\begingroup\$ Also note that v"var name"<val> allows for a multi-char variable name, and V"var name" gets a variable from the scope. \$\endgroup\$ – Conor O'Brien Apr 25 '16 at 14:57
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ oh, so that's what they do. Adding to the post. \$\endgroup\$ – Rɪᴋᴇʀ Apr 25 '16 at 14:58
  • 2
    \$\begingroup\$ o Thx for this tip :P \$\endgroup\$ – Downgoat Apr 26 '16 at 2:54
  • \$\begingroup\$ @EᴀsᴛᴇʀʟʏIʀᴋ It was a pun on o being the assignment variable \$\endgroup\$ – Conor O'Brien May 8 '16 at 23:31
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ o, yeah.... \$\endgroup\$ – Rɪᴋᴇʀ May 9 '16 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.