12
\$\begingroup\$

Cheddar

Cheddar is a high-level, functional + object-oriented programming language created by our user Downgoat designed to make programming easier, faster, and more intuitive.

What general tips do you have for golfing in Cheddar? I'm looking for ideas which can be applied to problems and which are also at least somewhat specific to Cheddar (e.g. "Remove unnecessary whitespace." is not an answer).

\$\endgroup\$
3
\$\begingroup\$

Use Functionized Properties

If you ever use just a property in a function:

A->A.long.property(n).foo.bar

You can use functionized properties to save some bytes:

@.long.property(n).foo.bar

You can reference the variable in the functionized property with $0.

\$\endgroup\$
2
\$\begingroup\$

Use the String Operator for string sequences

I'm talking about the @" operator which does different things, all of which deal with strings. This has quite a bit of uses but this is one of my favorite uses:

Take a look at this:

@" [103, 111, 97, 116, 115] === "goats"

not that useful but the opposite is:

@"'goats' === [103, 111, 97, 116, 115]
'goats'.bytes // compare the above too

This is especially useful to generate the alphabet:

65@"90    // Uppercase Alphabet
97@"122   // Lowercase Alphabet
65@"90+97@"122 // Both cases
String.letters // Compare 97@"122 to this
\$\endgroup\$
1
\$\begingroup\$

Curry

No not red curry (what other curry would you be thinking about ¬_¬). I mean this type of curry:

a->b->

If you have a function taking two arguments. It's shorter to curry than to not:

(a,b)->
a->b->

Note: This is only shorter when you have exactly two arguments.

\$\endgroup\$
1
\$\begingroup\$

Use default arguments

Declaring Cheddar variables can be quite the byte-waster:

->{var a=b+1}

luckily, you can (ab)use function default values for creating variables:

b=a+1->b

Here are some examples of uses:

let f= (a,b=a+1)->b
f(5) // 6

let f= a=Math.rand()->a
f() // 0.8757450950797647
\$\endgroup\$
1
\$\begingroup\$

Use Functionized Operators and Bonding

This is a simple one. If you have anything like:

i->1+i

or any similar operation. You can shorten using functionized operators + bonding:

1&(+)
\$\endgroup\$
1
\$\begingroup\$

Use the mapping operator

The => maps LHS to RHS, due to it's precedence, this also means you can use it with ranges and use it multiple times:

a=>f
(a).map(f)

Additionally:

a=>f=>g           // This is equivilant to...
(a).map(f).map(g) // this
\$\endgroup\$

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.