Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Keyword golfing

+6
−0

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 must 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

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

Can a keyword be a single character? (5 comments)
Is it OK to output something and wait for a input? (2 comments)

6 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+1
−0

BQN, 107 bytes

A↩C←A⇐¯π{_𝕣_:@;/⊏𝕩.y?𝕗‿∊𝕊⟨𝕤,⍷⟩𝕏𝕎𝔽𝕨𝔾𝕘}∞˙⌜˘¨´˝`(•Js⎉⊔⎊⌽⌾⍉⚇«∘»·∧○∨⍋⍒↑↓≍∾˜⥊⋈↕⊢⍟⊣¬!|≡≢/≥⟜≠=⊸≥⊐⊘⊒◶⊑><⌊⌈√⁼⋆+-×÷)⋄#

BQN doesn't have keywords but primitive symbols are reserved. It's quite funny how this manages to compile.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+5
−0

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

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

2 comment threads

In Python 3.8 this will print a `SyntaxWarning: "is not" with a literal. Did you mean "!="?`. (1 comment)
10+ years of python and i somehow have never seen nonlocal before... TIL! (1 comment)
+2
−0

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={}

Try it in Scastie!

This includes soft keywords. The official list of keywords is here.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+2
−0

Ruby 3.1.0, 274 259 249 bytes

-10 bytes thanks to Paradox in the Ruby discord

BEGIN{END{alias module class
begin rescue
retry ensure end
if self
elsif defined?
for$.in true do
super while false until 0unless not __ENCODING__ and __LINE__ or nil
undef redo
next end
return def break =yield end
case when __FILE__ then else end}}

Attempt This Online!

41 total keywords that you can view here.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

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

Try it online!

Check the list of keywords.

Thanks to @orthoplex for more shortening.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

You can shorten your for-loop and save a few spaces on the numerical constants. Also, I don't think t... (8 comments)
+0
−0

C (gcc), 358 bytes

static inline _Noreturn float f(union u);extern _Thread_local _Complex long double*restrict B;main(void){_Atomic register enum {A};typedef _Alignas(unsigned char)struct S;_Static_assert(_Alignof(_Bool),"_Imaginary");do goto a;while(sizeof B);if(1)for(auto volatile const signed short int i;;)continue;else switch(_Generic(0,default:0))case 0:a:break;return;}

Try it online!

Since nobody dared to take on C since this was posted, here's my attempt. It fulfills the "doesn't crash" criteria (though returns an unspecified value from the program).

Disclaimer: I couldn't get _Imaginary to work in gcc and clang doesn't even support complex numbers. Therefore I included the keyword inside a string literal, so that I won't get any unfair advantage against someone who can manage to get it working on some compiler.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »