222
\$\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\$
46
  • \$\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
    Commented Oct 18, 2015 at 12:30
  • 26
    \$\begingroup\$ This could have made a really great cops and robbers challenge I think. \$\endgroup\$
    – DankMemes
    Commented Oct 18, 2015 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\$
    – user45941
    Commented Oct 18, 2015 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\$ Commented Oct 19, 2015 at 12:28
  • 6
    \$\begingroup\$ Are we allowed to use a language that's already unusable to begin with? (JavaScript for example) \$\endgroup\$
    – 12Me21
    Commented Oct 17, 2017 at 14:23

92 Answers 92

3
\$\begingroup\$

[min]mod

[].UNWRAP.SET[].IF.SET[].SET.SET

Try it step by step!

Set all the built-in instructions to empty stacks (noops), making all instructions based on those instructions noops as well, since they only execute noops in different orders :)

\$\endgroup\$
2
\$\begingroup\$

Enema

:OQ::!Q:

Code can come any place after this.

This language is similar to Emmental in that it is capable of redefining itself. Essentially, what we're doing here is redefining O (which normally is for output) to do nothing (thus making the language no longer have a transformational model) and then redefine ! (which can be used to reset a word to its default behavior) to do nothing as well.

\$\endgroup\$
2
\$\begingroup\$

O

N:+:-:/:*:@:\:[:]:1:2:3:4:5:6:7:8:9:0:{:}:<:>:=:#:%:^:?:d:w:o:p::;

This reassigns mostly everything to a null codeblock, making any code that contains these characters do nothing.

You could add every ASCII character to make sure they can't do anything, but this kills all arithmetic, stack manipulation, codeblock creation, array creation, pushing numbers to the stack, comparing numbers, control flow, outputting, and assigning variables.

\$\endgroup\$
2
\$\begingroup\$

Mouse-2002

$ ~your code here

In Mouse, $ denotes the end of the program, thus, anything after it will be evaluated and "run" but won't actually do anything. No online interpreter available, unfortunately, but here is a fixed-so-it-compiles-in-gcc version of the interpreter written in C.

\$\endgroup\$
3
  • \$\begingroup\$ Too bad it ain't ): \$\endgroup\$
    – cat
    Commented Dec 9, 2015 at 1:22
  • \$\begingroup\$ Invalid because the code after it wasn't actually executed. \$\endgroup\$ Commented Feb 22, 2016 at 21:19
  • \$\begingroup\$ @ppperry did you read past the first clause of the first sentence? \$\endgroup\$
    – cat
    Commented Feb 22, 2016 at 21:22
2
\$\begingroup\$

J, online interpreter

f =: f
f 3

This calls f with f with f with... etc. Here's what the page looks like:

crash 1

Successive attempts at entering things in yields, well, nothing:

this

Tested on Firefox.

\$\endgroup\$
2
  • \$\begingroup\$ Hmm this only seem to break for me on the online interpreter using Firefox. The interpreter seems to be usable afterwards in Chrome, and jconsole handles the error completely differently locally. Might be worth noting. \$\endgroup\$
    – Sp3000
    Commented May 23, 2016 at 8:05
  • \$\begingroup\$ @Sp3000 Huh, interesting. Consider it noted. \$\endgroup\$ Commented May 23, 2016 at 15:51
2
\$\begingroup\$

Lua

local write = io.write
local type = type
local pairs = pairs
local setmetatable = setmetatable
local function destroy(g,t)
    t = t or {}
    setmetatable(g, {__index = function() return write end,__newindex = function() return false end})
    for k,v in pairs(g) do
        if(type(v)=="table")then
            local has = false
            for k2, v2 in pairs(t) do
                if v2 == v then
                    has = true
                    break
                end
            end
            if not has then
                t[#t+1]=v
                destroy(v,t)
            end
        elseif(type(v)=="function")then
            g[k] = write
        end
    end
end
destroy(_G)
type = write
pairs = write
setmetatable = nil

A fun one, makes all functions, including string and table constructors, into the io.write function. It doesn't necessarily prevent the language from doing things it was already doing, but it does cripple it from this point onwards. I chose io.write because I thought it interesting to see if I could make trying to run literally anything print. It didn't work so well.

\$\endgroup\$
2
\$\begingroup\$

Bash

exec &> /dev/null

Any code that comes after can execute whatever it wants, but its output is cast into the void of /dev/null.

\$\endgroup\$
7
  • \$\begingroup\$ File I/O still works though. \$\endgroup\$
    – eush77
    Commented May 14, 2017 at 18:02
  • \$\begingroup\$ @eush77 True! However, the challenge stated that we could cover only a subset of the allowed output methods. \$\endgroup\$
    – Chris
    Commented May 15, 2017 at 8:51
  • \$\begingroup\$ Right, I missed that. \$\endgroup\$
    – eush77
    Commented May 15, 2017 at 9:16
  • 2
    \$\begingroup\$ Too bad exec &> /dev/tty easily reverses that :) \$\endgroup\$
    – eush77
    Commented May 15, 2017 at 9:23
  • 1
    \$\begingroup\$ What if I rm -rf /dev/ right after? \$\endgroup\$ Commented Jul 13, 2020 at 3:43
2
\$\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\$
2
\$\begingroup\$

S.I.L.O.S, 1 byte

0

Try it online!

Yes, in SILOS, your code can be made completely useless by editing the first line. With this, you can not store any variavbles (or take any input). Essentially it allocates 0 bytes of memory for the first line.

\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

Staq

{ '}{{}}

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

\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

Crystal, 44 bytes

fun main(a : Int32,b : UInt8**) : Int32 0end

Try it online!

Works by overwriting the main function, so that rather than actually running code, it simply returns. Code can be inserted at any point after that, and it will simply be ignored.

\$\endgroup\$
2
\$\begingroup\$

JavaScript (Node.js), 23 bytes

for(y in this)this[y]=0

Try it online!

This script works almost universally unlike other JS examples here. I think I could probably shorten this using regex matching.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Doesn't really work with V8 in browsers unfortunately \$\endgroup\$
    – rydwolf
    Commented Dec 1, 2020 at 20:01
2
\$\begingroup\$

Spice

A couple of ways:

1. ALS

;@
ALS LOD OUT;
ALS ADD SWI;
ALS SUB BRK;
ALS MUL NUL;

New code goes at the end.

Explanation

The first character of a spice program defines the delimiter, in this case ; which is usually followed by all variable definitions before @ denotes the beginning of operations on those variables.

ALS allows aliasing operations to other names, so here we overwrite some builtin operations with other. Because OUT, SWI, BRK and NUL are the only operations that don't require a variable as at least one argument, by aliasing them to pre-existing operations we make it impossible to invoke them, as aliases are resolved first.

2. Poorly defined delimiter

 @

(Note leading space)

Explanation

We define the delimiter as a space, making invoking any operation cause a runtime exception in the interpreter: this is the equivalent of writing code similar to:

;var1;@
ADD;1;2;var

which is nonsensical in Spice.

\$\endgroup\$
2
\$\begingroup\$

JavaScript (browser)

It's hard to test this since it breaks everything. Not sure if this is complete but it's easy to keep adding clear(somebuiltin) to remove more properties

const clear = (obj) => {
  for (const prop in obj) obj[prop] = undefined
}
window.addEventListener("error", () => {})
clear(window);
clear(document);
clear(console);

// code here
console.log(Number(prompt("a")) + Number(prompt("b")))
\$\endgroup\$
2
  • \$\begingroup\$ Only clear(window) should be enough, document and console are both properties of window \$\endgroup\$ Commented Dec 28, 2022 at 18:57
  • \$\begingroup\$ Yeah that seems like it would be like that intuitively @mousetail. I remember finding some workaround while I was testing but I'm going to double check \$\endgroup\$ Commented Dec 28, 2022 at 22:43
2
\$\begingroup\$

tinylisp, 20 bytes

((q((c q load) [your code here] ))0()0

Try it online!

This executes the given code in an environment where the builtins c, q and load are redefined to 0 and/or null. q allows creating a literal list/string and c allows prepending an item to a list, so without these it's impossible to construct lists. load is also blocked to disallow loading the stdlib via (load library), which has a few things that could evade this.

Without these, although it's possible to define arbitrary global variables and perform arithmetic, (assuming the given code is syntactically valid and doesn't used unmatched parentheses to escape) it's impossible to have any form of iteration or recursion due to not being able to define functions or lists. It is possible to use d to get a name and then chars to construct a list of numbers, but this is still useless.

One other thing I thought of is that, since tinylisp function arguments are only accessible directly within their caller scope and nothing deeper, you could escape into a new function which has those variables unshadowed... but to do that you'd have to declare a function.

\$\endgroup\$
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\$
1
  • \$\begingroup\$ No need to count the bytes, this is popularity contest, not code-golf. \$\endgroup\$
    – user75200
    Commented Oct 29, 2017 at 16:50
1
\$\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\$
1
  • \$\begingroup\$ @mbomb007 It works, but only in a REPL. tio.run/nexus/… \$\endgroup\$
    – Dennis
    Commented May 5, 2017 at 16:43
1
\$\begingroup\$

Japt

$Japt=undefined$

Test it online!

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

ForceLang

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

Your code goes after.

\$\endgroup\$
1
  • 2
    \$\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\$ Commented Apr 2, 2019 at 1:25
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\$
2
  • 1
    \$\begingroup\$ alert is a valid output method for PPCG challenges by default. \$\endgroup\$
    – hyperneutrino
    Commented Oct 21, 2017 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
    Commented Oct 29, 2017 at 16:51
1
\$\begingroup\$

C (gcc), 136 bytes

#include <stdlib.h>
#include <signal.h>
__attribute__((constructor))
void enable_io()
{
    // Make it clear that we are ready for IO
    raise(SIGPOLL);
}

Try it online!

Place it after any C file using libc (or LD_PRELOAD it for dynamically linked programs 😉)

#include <stdio.h>
int main()
{
    puts("hello");
}

(note that the program did not output this, it is the shell):

$ ./a.out
I/O possible

The __attribute__((constructor)) is a feature that allows GCC to inject functions before main() runs, and we exit the program before main() by raising a signal saying that I/O is possible, making I/O impossible.

exit(0) works as well, but this is funnier.

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

BrainChild

macro (/[^0]+/) {0}; discard _;

Defines a macro that helpfully replaces all lengths of code that aren't 0s with the number constant 0. The final discard is needed as if the macro is followed by an assembly block, it actually evaluates it.

Try It Online!

\$\endgroup\$
0
\$\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\$
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\$
2
  • \$\begingroup\$ only works in IE>10. \$\endgroup\$
    – user75200
    Commented Oct 29, 2017 at 16:48
  • \$\begingroup\$ eval=0 doesn't seem to work. \$\endgroup\$
    – emanresu A
    Commented Apr 5, 2021 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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