We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

KBAT

From Esolang
Jump to navigation Jump to search

KBAT (Killed By A Train)

KBAT is an esolang that is based on APL's trains. This language only has trains and recursion.

Syntax

{...} is a dyadic train and [...] is a monadic train.
'f means f is recursive. $ is the recursion operator inside f.
f?g:h is the conditional operator. If f(args) is truthy, then g is called. Otherwise, h is called.
Any literals are monadic constant functions. To make dyadic constant functions, place a dot before the literal.

Data types

  • Integer. Only natural numbers are supported. 0 is falsy and any other number is truthy.
  • String. Sequence of characters. Empty string is falsy and any non-empty string is truthy.
  • List. Sequence of values. Empty list is falsy and any non-empty list is truthy.
  • Undefined. Just like in JavaScript. Always falsy.

Types are implicitly converted:

Implicit conversions
Data\Target Int Str List
Int / chr(n) range(n)
Str len(s) / [ord(c) for c in s]
List len(l) "".join([str(i) for i in l]) /
Undef 0 "" []

Seq is str or list.

Built-in operators

Dyadic operators

Polymorphic operators work by converting the left argument to the right argument's type.

  • +: Addition / Concatenation.
  • <: Always returns the left argument.
  • >: Always returns the right argument.
  • /: Nth element of a list/string. Left: Seq, Right: Int.
  • -: Subtraction / Set difference.
  • =: Equality. Returns 0 or 1.
  • *: Multiplication / Repetition.
  • %: Remainder.

Monadic operators

  • ;: Identity.
  • #: Length.
  • l: Wrap in a list.
  • s: Repr.
  • h: Int -> Successor, Seq -> car.
  • t: Int -> Predecessor, Seq -> cdr.
  • p: ParseInt. Returns undefined otherwise.

Examples

Prime sieve, accepts an integer from stdin (as string as its left argument):

[p+1+()tt'[;?[hl+{<'{<?{{h%}?{hl<+{t$}}:{t$}}:.()}$}h]:()]]