191
\$\begingroup\$

Try to write some code in your language and make it not satisfying our criteria of being a programming language any more.

A language satisfies our criteria (simplified version for this challenge) of being a programming language if:

  • It can read user input representing tuples of positive integers in some way.
  • It can output at least two different possible results depending on the input.
  • It can take two positive integers and add them (and the result can affect the output).
  • It can take a positive integer and decide whether it is a prime (and the result can affect the output).
  • For the purpose of this challenge, any kind of output that isn't an allowed output method for a normal challenge is ignored. So it doesn't matter whether the program can also play a piece of music, or posting via HTTP, etc.
  • Update: You can also choose one or some of the allowed output methods, and ignore all the others. But you must use the same definition everywhere in the following criteria. And if your program can disable more than one output methods — that worths more upvotes.

Examples like making it not able to output, or disabling all the loop constructs so it won't be able to do primality test and making sure the user cannot re-enable them.

You should leave a place for inserting new code. By default, it is at the end of your code. If we consider putting the source code in that place in your answer and running the full code as a complete program the interpreter of a new language, that language should not satisfy the criteria.

But the inserted code must be executed in such a way like a language satisfying the criteria:

  • The inserted code must be grammatically the same as something (say it's a code block in the following criteria) that generally do satisfy the criteria, from the perspective of whoever wants to write a syntax highlighter. So it cannot be in a string, comment, etc.
  • The inserted code must be actually executed, in a way it is supposed to satisfy the criteria. So it cannot be in an unused function or sizeof in C, you cannot just execute only a non-functional part in the code, and you cannot put it after an infinite loop, etc.
  • You can't limit the number of possible grammatically correct programs generated this way. If there is already something like a length limit in the language you are using, it shouldn't satisfy the criteria even if this limit is removed.
  • You can't modify or "use up" the content of input / output, but you can prevent them from being accessed.
  • These criteria usually only applies to languages without explicit I/O:
    • Your code should redirect the user input (that contains informations of arbitrary length) to the inserted code, if a code block isn't usually able to get the user input directly / explicitly in the language you are using.
    • Your code should print the returned value of the inserted code, if a code block isn't usually able to output things directly / explicitly in the language you are using.
    • In case you print the returned value, and it is typed in the language you are using, the returned type should be able to have 2 different practically possible values. For example, you cannot use the type struct {} or struct {private:int x;} in C++.

This is popularity-contest. The highest voted valid answer (so nobody spotted an error or all errors are fixed) wins.

Clarifications

  • You shouldn't modify the code in the text form, but can change the syntax before the code is interpreted or compiled.
  • You can do other things while the code is running. But the reason that it doesn't satisfy the criteria should be within the inserted code itself. It can error because of the interference of another thread, but not just be killed by another thread.
  • All the specs basically means it should be grammatically likely satisfying the criteria if all the built-ins were not changed but not actually do. It's fine if you find any non-grammatical workarounds, such as passing the parameters to the code block correctly, but make them not able to be used in some way.
  • Again, the inserted code must be actually executed. Code after an infinite loop or crashing is considered "not actually executed", thus not valid. Those answers might be interesting, but there are already some other infinite loop or crashing questions on this site, and you may find a more appropriate one to answer. If not, consider asking a new question. Examples of those questions are:

Leaderboard

var QUESTION_ID=61115/*,OVERRIDE_USER=8478*/;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,/*getComments()*/(more_answers?getAnswers():process())}})}/*function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}*/function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),score:s.score,language:a[1],lang:jQuery('<div>').html(a[1]).text(),link:s.share_link})}),e.sort(function(e,s){var r=e.score,a=s.score;return a-r});var s={},r=1,a=null,n=1;e.forEach(function(e){e.score!=a&&(n=r),a=e.score,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",e.n=n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.score).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text())/*,s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}*/});var t=e/*[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o])*/;t.sort(function(e,s){return (e.lang.toUpperCase()>s.lang.toUpperCase())-(e.lang.toUpperCase()<s.lang.toUpperCase())||(e.lang>s.lang)-(e.lang<s.lang)});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{PLACE}}",o.n).replace("{{LANGUAGE}}",o.language).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.score).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<(?:h\d|(?!.*<h\d>)p)>\s*((?:[^,;(\s]| +[^-,;(\s])+)(?=(?: *(?:[,;(]| -).*?)?\s*<\/(h\d|p)>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;float:left}table{width:250px}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Score</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Sorted by Language</h2> <table class="language-list"> <thead> <tr><td></td><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{PLACE}}</td><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
  • \$\begingroup\$ Am I allowed to change the code before executing it? Also, can I run other code whilst I am running the code given? \$\endgroup\$ – Blue Oct 18 '15 at 12:30
  • 21
    \$\begingroup\$ This could have made a really great cops and robbers challenge I think. \$\endgroup\$ – DankMemes Oct 18 '15 at 23:07
  • 6
    \$\begingroup\$ @DankMemes Agreed. As it stands, it's much too vague, and most answers would be invalidated by finding a workaround. CnR with this premise would be delightful. \$\endgroup\$ – Mego Oct 18 '15 at 23:54
  • 3
    \$\begingroup\$ So then it seems to be saying that in languages with explicit IO it's permissible to do completely boring things like reading and discarding the contents of stdin. It sets up a completely unfair playing field where some languages require you to carefully handle the IO for the inserted code, and other languages allow you to trash it and deny IO to the inserted code. \$\endgroup\$ – Peter Taylor Oct 19 '15 at 12:28
  • 1
    \$\begingroup\$ Are we allowed to use a language that's already unusable to begin with? (JavaScript for example) \$\endgroup\$ – 12Me21 Oct 17 '17 at 14:23

78 Answers 78

1
\$\begingroup\$

Befunge 98

 v
v>"PAMI"4("zqzCzOz=z.z,z)zozszM"akMn
>

Redefines the , and . instructions to NOPS to prevent out the standard way, then redifines the = instruction to prevent execution oif an arbirtrary program, then redefines the o instruction to prevent file output and the q instruction to prevent output by exit code, then redefines the C,O,M,and ) instructions to prevent you from undoing its definitions. Insert your code after the > on the third line.

\$\endgroup\$
1
\$\begingroup\$

Factor

Factor is a concatenative stack-based language, where all operators are words which are defined with :. Here, we kill the builtin print functions by defining them as nothing, and then redfine the macro redefiniton operator.

: stream-write ( -- ) ;
: write ( -- ) ;
: print ( -- ) ;
: . ( -- ) ;
: : ( -- ) ;

! your code here
\$\endgroup\$
1
\$\begingroup\$

DUP

[]⇒.[]⇒;[]⇒"[]⇒,[]⇒`[]⇒'[]⇒⇒ { your code here }

Redefine the print operators, the string allocation operators, and the input operators all to noop, and then define the definition operator as a noop.

\$\endgroup\$
1
\$\begingroup\$

Staq, 20 bytes

{` }{' }{: }{; }{{}}

Redefines all I/0 instructions as NOPs

Standard Staq instructions:

: output the topmost stack value to the console as a number
; output the topmost stack value to the console as a character
' push entered number on stack
` push value of entered character on stack
{ begin function definition
} end function definition

{` }                   define ` as NOP 
    {' }               define ' as NOP
        {: }           define : as NOP
            {; }       define ; as NOP
                {{}}   define { as }

This way, no more functions can be defined, which would be necessary to reset the instructions to their original state. In Staq, all predefined instructions can be reset to their original state by putting them between curly braces without a space. For example, : could be reset by writing {:}. But that’s not possible anymore because the opening { is defined as }, which would result in a useless set of instructions: }:}, which in turn (due to the redefinition of :) means } }.

So, anything that gets executed after this block runs as normal, but is useless because there is neither input nor output possible anymore, and no way to define functions to restore that ability.

\$\endgroup\$
  • \$\begingroup\$ No need to count the bytes, this is popularity contest, not code-golf. \$\endgroup\$ – user75200 Oct 29 '17 at 16:50
1
\$\begingroup\$

Forth (gforth), 8 bytes

0 >ORDER

Everything you type in after that except an empty line will result in Invalid memory address.

I stumbled upon this by accident just now, I don't know precisely how it works but I guess >ORDER adds a new dictionary to search in for words or something. And it can't read from address 0, the address we told it to search for first, so it throws an error.

Forth (RCOS), 10 bytes

0 LATEST !

Tells the Forth that no words have been defined (latest word is the null pointer). Thus, you can only input numbers, everything else results in an Unknown token error.

Forth (RCOS), 18 bytes

219 ' INTERPRET C!

Writes byte 0xDB (65C02's STP instruction which halts the processor) to the start of the INTERPRET word. Now, everytime that word is called, the processor is halted. What INTERPRET normally does, it takes an area of memory (most likely the line buffer) and executes the words in there in order. It gets called when you press enter to execute the current line. So, with our new behavior, everytime you press enter (aka call INTERPRET) it halts the computer.

Looks like there's many ways to break my RCOS, but what do you expect, it's written in assembly

\$\endgroup\$
1
\$\begingroup\$

JS, 11B

delete this

works with IE>8 and Edge (non-strict mode), with only workaround is exiting then reentering console to redefine them.

\$\endgroup\$
1
\$\begingroup\$

Japt

$Japt=undefined$

Test it online!

\$\endgroup\$
  • \$\begingroup\$ Can you replace it with $Japt=0 for savings? \$\endgroup\$ – CalculatorFeline Jul 10 '17 at 21:41
  • \$\begingroup\$ Won't the embedded JavaScript still be run? \$\endgroup\$ – Esolanging Fruit Aug 22 '17 at 20:08
  • \$\begingroup\$ @Oliver Yes, but there's no closing $, meaning that I can continue to add Javascript after the assignment. \$\endgroup\$ – Esolanging Fruit Aug 23 '17 at 4:58
  • \$\begingroup\$ [][1] instead of undefined? :P \$\endgroup\$ – ASCII-only Apr 1 at 10:40
1
\$\begingroup\$

JS (updated, compatible with IE11)

console.error=eval=0

Defines console.error to be eval which is redefined to be 0, which is no function but a number.

Output isn't directly possible.

\$\endgroup\$
  • 1
    \$\begingroup\$ alert is a valid output method for PPCG challenges by default. \$\endgroup\$ – HyperNeutrino Oct 21 '17 at 17:12
  • \$\begingroup\$ But IE evals thus you can't alert your string. If you delete eval then try deleting console.error, you get The tab contains a modified eval function. It's possible the command program diagnostic windows won't work correctly, which is done by console.error. \$\endgroup\$ – user75200 Oct 29 '17 at 16:51
1
\$\begingroup\$

Staq

{ '}{{}}

which redefines the noop to push entered number to stack. Then { to }.

\$\endgroup\$
1
\$\begingroup\$

Staq, elaborated more

{: }{; }{' }{" }{` }{{}}
{: }                    redefine : to NOP
    {; }                redefine ; to NOP
        {' }            redefine ' to NOP
            {" }        redefine " to NOP
                {` }    redefine ` to NOP
                    {{}}redefine { to }

If we didn't use {{}}, {:} can be used for restoring predefined characters.

\$\endgroup\$
1
\$\begingroup\$

Bash, 60 bytes

shopt -s extdebug;f(){ return 1;};declare -rf f;trap f DEBUG

Your code goes afterwards. I abused this answer which uses a debugging feature. The return code of the function determines what to do with the original command.

I had to add the declare -rf f; bit to make the function read-only. This addresses @Gilles workaround.

I think this complies with the rules since code is still being taken in by the interpreter as the next command without infinite loops, crashing, etc.

Let me know if there is another workaround.

\$\endgroup\$
0
\$\begingroup\$

Python 3 REPL

def f():
    import gc
    obs = gc.get_objects()
    for ob in obs:
       if isinstance(ob, dict) and ob is not locals() and ob is not __builtins__.__dict__ and ob is not globals():
           ob.clear()
f()
#What can you do now!
\$\endgroup\$
  • \$\begingroup\$ @mbomb007 It works, but only in a REPL. tio.run/nexus/… \$\endgroup\$ – Dennis May 5 '17 at 16:43
0
\$\begingroup\$

Groovy

java.lang.Class.metaClass = Integer.metaClass
Integer.metaClass.plus = { Integer n ->     return 'a' }
Integer.metaClass.minus = { Integer n ->     return 's' }
Integer.metaClass.multiply = { Integer n ->     return 'd' }
Integer.metaClass.div = { Integer n ->     return 'f' }

I tried (without success) to overwrite the print commands, so I redefined the Object instead :) ​

\$\endgroup\$
0
\$\begingroup\$

Javascript

for(let q in this)delete this[q];

which deletes each property of this.

Or,

eval=0;

assigning 0 to eval, thus any input raises this:

The tab contains a modified eval function. It's possible, the command program diagnostic windows don't work correctly.

thus being irreversible by even restarting developer tools!

\$\endgroup\$
  • \$\begingroup\$ only works in IE>10. \$\endgroup\$ – user75200 Oct 29 '17 at 16:48
0
\$\begingroup\$

ForceLang

undef def
undef gui
undef io
undef if
undef goto
undef gotoex
undef require
undef undef

Your code goes after.

\$\endgroup\$
  • 1
    \$\begingroup\$ I'm pretty sure this doesn't actually do anything, since all undef does is remove a definition created using the def command and doesn't actually change the value of any variables (or in this case constants.) \$\endgroup\$ – SuperJedi224 Apr 2 at 1:25
0
\$\begingroup\$

Funky

for v in values({math, string, table, io, _G})
    for k in keys(v)
        v[k] = nil

This nukes the math functions, then the string, table, and IO functions, and finally, cleans out the _G table.

The math functions are actually what's called when operators are used, so without them, most functionality is gone. But you can do math with table functions, if you get smart, so they're nuked too.

When the _G table is cleared, all forms of IO are finally also gone, and the getMetaFunc function is also nuked, which causes errors if most things happen.

After this, the language is entirely unusable.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Lua (5.1.5), 9 bytes

print=nil

Not sure if this counts. (Because it can still, for example, add 2 numbers, you just can't see the result (not even in the REPL) because print() doesn't work.)

\$\endgroup\$
  • \$\begingroup\$ Actually with io.write(2+3) you can see the result. Though in REPL you will also get the error after the output. \$\endgroup\$ – manatwork Sep 10 at 17:55
  • \$\begingroup\$ In the latest version of Lua, io.write works without error. Also, Lua's I/O functionality is still there, so you could still write to a file the results of doing useful stuff. \$\endgroup\$ – ouflak Oct 10 at 8:27
-1
\$\begingroup\$

Java

Building upon https://codegolf.stackexchange.com/a/61124/40787's input I saw that there is just too much boilerplate and reflection.

You can insert the code after the comment.

Edit

Saw this wasn't a strict code-golf, so prettied it a bit

import static java.lang.Thread.*;

import java.io.*;
import java.lang.reflect.Proxy;

import sun.misc.*;

public class Jail {

    public static void main(String[] a) {
        //user code here :D
        //Remember, do not do anything funky!
    }

    static {
        // From the original Java submission
        System.setOut(new PrintStream(new ByteArrayOutputStream()));
        System.setErr(new PrintStream(new ByteArrayOutputStream()));
        System.setIn(new ByteArrayInputStream(new byte[0]));

        // Block all access
        SharedSecrets.setJavaIOAccess(b(JavaIOAccess.class));
        SharedSecrets.setJavaLangAccess(b(JavaLangAccess.class));
        SharedSecrets.setJavaSecurityAccess(b(JavaSecurityAccess.class));

        //prevent throw new Error(output to show)
        setDefaultUncaughtExceptionHandler(b(UncaughtExceptionHandler.class));

        // Seal the deal
        System.setSecurityManager(new SecurityManager());
    }

    static <T> T b(Class<T> t) {
        return (T) Proxy.newProxyInstance(null, new Class[]{t}, (p, m, a) -> null);
    }
}

Original

import static java.lang.Thread.*;
import java.io.*;
import java.lang.reflect.*;
import sun.misc.*;

class X {

    static SharedSecrets s;

    public static void main(String[] a) throws IOException {
        // From the original Java submission
        a=null;
        System.setOut(new PrintStream(new ByteArrayOutputStream()));
        System.setErr(new PrintStream(new ByteArrayOutputStream()));
        System.setIn(new ByteArrayInputStream(new byte[0]));

        // Block all access
        s.setJavaIOAccess(b(JavaIOAccess.class));
        s.setJavaLangAccess(b(JavaLangAccess.class));
        s.setJavaSecurityAccess(b(JavaSecurityAccess.class));

        //prevent throw new Error(output to show)
        setDefaultUncaughtExceptionHandler(b(UncaughtExceptionHandler.class));

        // Seal the deal
        System.setSecurityManager(new SecurityManager());

        //user code here :D
        //Remember, do not do anything funky!

    }

    static <T> T b(Class t) {
        return (T) Proxy.newProxyInstance(null, new Class[]{t}, (p, m, a) -> {
            throw null;
        });
    }
}

If you write normal language syntax, it still works (mostly). Also, opening files or trying to reset the streams is frowned upon. Just wanted to get some lower number Java submissions.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.