Keyword golfing
Many programming languages have the concept of keywords, special syntax items that are not just identifiers reserved by some library, but words reserved by the language itself.
The challenge is to write a minimal program for a language with such keywords, with as few characters as possible (code golf), while at the same time using every single keyword from the language.
The program need not do anything meaningful or perform any particular input/output, but it most compile cleanly with a conforming compiler and execute without run-time errors/crashes. Non-standard extensions and alternative non-standard keywords shall not be used.
Example, all keywords from the C language (as per the current C17 standard):
auto
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
inline
int
long
register
restrict
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
_Alignas
_Alignof
_Atomic
_Bool
_Complex
_Generic
_Imaginary
_Noreturn
_Static_assert
_Thread_local
[Python 3.7], 231 bytes …
3mo ago
Ruby 3.1.0, 274 bytes ```RU …
3mo ago
Scala 3, 553 bytes ```scala …
3mo ago
Lua 5.4.4, 147 bytes ``` l …
22d ago
BQN, 107 bytes ``` A↩C←A⇐¯ …
3mo ago
5 answers
Python 3.7, 231 bytes
class C:pass
def g():
async def f():return;yield;await[3for()in()];nonlocal f
if None:
with lambda:3or 7and 8as q:del x
elif False:raise
else:assert 1is not 5
try:from x import*
except:global a
finally:9
while True:break;continue
1 comment thread
Scala 3, 553 bytes
package a
import E.Z as Z
import E.*
sealed trait T
open class Y{export E.Z as Q}
enum E[+A]derives CanEqual:
case Z
end E
private abstract final class X extends AnyRef with T{protected opaque type T>:0=0
lazy val x:X#T=0
override def toString:String={var e=0
while false do try 0 catch{case e=>throw e}finally{}
0 match{case _@0|1=>if true then(for a<-""yield null)else 0}
return new String(super.toString)}}
given[A[-C]<:[B]=>>B](using 0):0=0
object O
extension(x:0)transparent inline infix def x(y:0)(implicit c:0)=(a:0)=>(b:0)?=>null
@main def m={}
This includes soft keywords. The official list of keywords is here.
0 comment threads
Ruby 3.1.0, 274 bytes
BEGIN{END{
alias undef class
if self and true or false
begin
rescue
retry
ensure
end
elsif defined?
for a in 1 do
module B
super until 1
end
redo
next
end
return
end
def _ =yield a;case __ENCODING__ when __LINE__ then __FILE__ else break while 1 until 2 unless not nil end}}
41 total keywords that you can view here. Hard to make any improvements because of the end
s.
0 comment threads
Lua 5.4.4, 147 bytes
local function f()goto l::l::return end for _ in f do end if true and false then elseif""then else end repeat until""or not nil while""do break end
Check the list of keywords.
Thanks to @orthoplex for more shortening.
0 comment threads