Skip to main content
3 of 3
added 831 characters in body
Laikoni
  • 26.3k
  • 6
  • 52
  • 115

Coconut, 190 bytes, cracked by quartata

main :: RunIO
main = print (list (range (1, 101)))

list :: Fn ((Range, Int) -> (List, Int))
list = xs -> List.fromObj (xs)

range :: Fn ((Pair, Int) -> (Range, Int))
range = (x,y) -> {x..y}

Try it online!

Coconut extents Python by syntactical constructs for functional programming.

main = print (list (range (1, 101))) is the only line that is actually doing something, though a more idiomatic way would be (1,101) |*> range |> list |> print.

The lines with :: should be reminiscent of Haskell's type annotations, but Coconut is actually dynamically typed and :: is its chain operator which works lazily, which is probably the reason why those nonsensical declarations do not throw an error.

I also wanted to create the impression that functions can be used before their definition appears in the code, but actually Coconut is interpreted sequentially and list and range are build-in functions which work fine in the second line, but are redefined to nonsensical functions afterwards.

Calling list after the redefinition produces a NameError: name 'List' is not defined, because there is no function List.fromObj.

Calling the redefined range with two numbers, e.g. range(1,101) returns a singleton set which contains a function object, because the .. operator is used for function composition. This does not cause an error yet, but trying to evaluate this composed function of course throws a TypeError: 'int' object is not callable.

Laikoni
  • 26.3k
  • 6
  • 52
  • 115