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

Comments on Keyword golfing

Parent

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)
Post
+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)
You can shorten your for-loop and save a few spaces on the numerical constants. Also, I don't think t...
orthoplex‭ wrote over 2 years ago

You can shorten your for-loop and save a few spaces on the numerical constants. Also, I don't think the rules require you to call your function in the end.

local function f()if true then for v=0,0 do while false do break end repeat until""and""or not nil end elseif""then else end goto l::l::return end
Zakk‭ wrote over 2 years ago · edited over 2 years ago

You can shorten your for-loop

No, I can't. Shortening it the way you did results in omitting the in keyword. This obviously goes against the rule of including all language keywords.

and save a few spaces on the numerical constants

Yes, that's true. I will edit my answer. Thanks (again) for pointing this out!

Also, I don't think the rules require you to call your function in the end.

Maybe you are right. But, again, the rules require the program to compile (i.e. no syntax errors) and to run without runtime errors or crashes. In Lua, you can define a syntactically-correct and at the same time buggy function without calling it and the interpreter won't complain.

orthoplex‭ wrote over 2 years ago

Oh oops, you're right, I completely overlooked in. Still, the for-loop could be shortened to something sneaky like

for x in print do end
Moshi‭ wrote over 2 years ago

If your function never runs, then clearly it won't have a runtime error :)

Zakk‭ wrote over 2 years ago

orthoplex‭ You are right! It can be shortened (and it prints nil nil). Strange how I missed this one out. Anyways, thanks (once more) for pointing this out!

Zakk‭ wrote over 2 years ago

If your function never runs, then clearly it won't have a runtime error :)

Moshi‭ So calling f() is not necessary... If so, I will remove it.

orthoplex‭ wrote over 2 years ago

How about we use our own function to shorten the for-loop even more? This should also relieve your discomfort with not calling f.

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
Zakk‭ wrote over 2 years ago

Clever solution! Thanks!