# What exactly is the Criteria for a Function? [duplicate]

I got the idea for this question after reading an answer by Martin Ender here. It more-or-less says: Functions in stack-based languages can leave the output on the stack. This question is also similar to What even is a “function” by our standards?.

I use ><> and to me, a function is just when I store my current location on the stack, jump to the function, and then ultimately return to my previous location. This is similar to how I'd do it in nasm with call and ret. So then in some languages, how exactly do we define a function?

I mean, isn't a function just storing your location on the stack, jumping to the function, and then ultimately jumping back? Seems a bit loose considering how big of a role this rule plays for certain esolangs.

Even when considering this answer by Downgoat which says It is a section of code, which can be directly inserted into a program with no modification, and should be able to be assigned/named/referred to in some way., it still leaves it unclear as to what other golfers really would be happy with. In my opinion, many esolangs blur the line between program and function by this definition (I can copy almost any of my ><> programs directly into another ><> program, and jump to it with just .).

><> and asm would be my two biggest examples of languages with ambiguous functions, but I'm sure there are a lot more.

So I ask, what exactly is the criteria for a function? Preferably providing at least one clear example of what is and isn't a function in at least two languages which do not officially define what a function is.

• @nimi, I think might be right, though I still find the answers ambiguous for 2D languages. For example if a function is just a piece of code that can be run independently ignoring surrounding code, and refferred to in some way, then would  "Hi"; (6 bytes, ><>) be considered a function as it can be refferred to by 00. and ignores surrounding code if the fish is moving right? But what about left, does that count? Must I include a jump to the exit if I only have one function (I wouldn't bother jumping in nasm)? So perhaps I should change my question to "What is the criteria for a function?". – redstarcoder Nov 26 '16 at 14:06
• Please let me know if the new way the question is presented is unique enough. I toughened the criteria for an answer and changed the wording to be more specific. The real goal is to clear up any ambiguities, and I'm not convinced the other question does that sadly. If it does though, I'll try to form an answer there to promote discussion instead of pursuing this. Cheers, guys! – redstarcoder Nov 26 '16 at 14:23
• I don't know ><> enough to give a definite answer, but I think you can still apply Mego's answer from the other question, i.e "Hi"(even without ; is a function (no input - output "Hi" on the stack), so is + (input: two numbers from the stack - output one number on the stack). Movement commands (change direction, mirror) alone make no function. Yes, answering the other question to address things that aren't covered by the other answers is a good idea. Then we have a single place which defines a function in our sense. – nimi Nov 26 '16 at 14:42
• That's actually a pretty good answer. I agree, and I feel much more clear on the situation. I'll attempt to write an answer for the other question, and this one should be closed :). – redstarcoder Nov 26 '16 at 14:59