Tips for golfing in Jolf

12

5

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.

Rɪᴋᴇʀ

Posted 2016-04-25T14:28:00.790

Reputation: 7 410

Welcome to the site, please read the [ask] page and the [tour] page for more information. – Rɪᴋᴇʀ – 2016-12-20T16:32:01.730

Answers

4

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]);

Conor O'Brien

Posted 2016-04-25T14:28:00.790

Reputation: 36 228

1If for some strange reason Jolf is golfy enough (...?) – Erik the Outgolfer – 2018-01-06T17:03:27.600

@EriktheOutgolfer isn't ** – Conor O'Brien – 2018-01-06T18:30:22.990

7

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_γ

Conor O'Brien

Posted 2016-04-25T14:28:00.790

Reputation: 36 228

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 – DeepDeadpool – 2016-04-25T18:45:49.797

1@GheyPhistor Which string theory? But yeah, it's that the zeta function over the natural numbers is -1/12. – Conor O'Brien – 2016-04-25T18:48:56.583

6

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.

a spaghetto

Posted 2016-04-25T14:28:00.790

Reputation: 10 647

"between 100 and 255" – Leaky Nun – 2016-04-25T14:49:05.143

@KennyLau In Jolf, 10 is actually the number 1 and the number 0 not the number 10, so it's more like 10-255. – a spaghetto – 2016-04-25T14:52:58.123

I see, thanks.. – Leaky Nun – 2016-04-25T14:53:54.530

4

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.

Fund Monica's Lawsuit

Posted 2016-04-25T14:28:00.790

Reputation: 564

1The mysterious math module. – Conor O'Brien – 2016-04-25T14:42:25.083

1module. (6 more to go...) – Leaky Nun – 2016-04-25T14:48:31.360

2

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.

Conor O'Brien

Posted 2016-04-25T14:28:00.790

Reputation: 36 228

What's the advantage of *+~θ over *θ+? – user253751 – 2016-04-26T22:52:10.237

@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>. – Conor O'Brien – 2016-04-26T22:58:58.707

2

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

Conor O'Brien

Posted 2016-04-25T14:28:00.790

Reputation: 36 228

1

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.

Rɪᴋᴇʀ

Posted 2016-04-25T14:28:00.790

Reputation: 7 410

Also note that v"var name"<val> allows for a multi-char variable name, and V"var name" gets a variable from the scope. – Conor O'Brien – 2016-04-25T14:57:57.653

@CᴏɴᴏʀO'Bʀɪᴇɴ oh, so that's what they do. Adding to the post. – Rɪᴋᴇʀ – 2016-04-25T14:58:27.893

2o Thx for this tip :P – Downgoat – 2016-04-26T02:54:48.613

@EᴀsᴛᴇʀʟʏIʀᴋ It was a pun on o being the assignment variable – Conor O'Brien – 2016-05-08T23:31:34.977

@CᴏɴᴏʀO'Bʀɪᴇɴ o, yeah.... – Rɪᴋᴇʀ – 2016-05-09T01:11:59.237