26

I just stumbled on what appears to be a generally-known compsci keyword, "emit". But I can't find any clear definition of it in general computer science terms, nor a specific definition of an "emit()" function or keyword in any specific programming language.

I found it here, reading up on MapReduce:

https://en.wikipedia.org/wiki/MapReduce

The context of my additional searches show it has something to do with signaling and/or events. But it seems like it is just assumed that the reader will know what "emit" is and does. For example, this article on MapReduce patterns:

https://highlyscalable.wordpress.com/2012/02/01/mapreduce-patterns/

There's no mention of what "emit" is actually doing, there are only calls to it. It must be different from other forms of returning data, though, such as "return" or simply "printf" or the equivalent, else the calls to "emit" would be calls to "return".

Further searching, I found a bunch of times that some pseudocode form of "emit" appears in the context of MapReduce. And in Node.js. And in Qt. But that's about it.

Context: I'm a (mostly) self-taught web programmer and system administrator. I'm sure this question is covered in compsci 101 (or 201?) but I didn't take that course.

JDS
  • 1,869
  • 1
  • 15
  • 17
  • 2
    Well it means to *put out/forth* so I would read it in p-code as a metasyntactic saying *"here is the useful data, do something with it"* as opposed to specifying something specific like returning/printing/echoing/storing – Alex K. Jul 07 '15 at 14:09
  • Just a note for the future: there's actually a computer science version of Stack Overflow, http://cs.stackexchange.com/ that would be more appropriate for this question. It's a great site! – whatoncewaslost Jul 07 '15 at 14:18
  • This is a meta question: How do I move that to cs.stackexchange without double posting? – JDS Jul 07 '15 at 14:40
  • @AlexK. i get that, but how does "emit" differ from "return", in your example? – JDS Jul 27 '15 at 21:55

4 Answers4

11

In the context of web and network programming:

When we call a function the function may return a value. When we call a function and the function is supposed to send those results to another function we will not user return anymore. Instead we use emit. We expect the function to emit the results to another function by our call.

A function can return results and emit events.

Arman Fatahi
  • 2,635
  • 3
  • 24
  • 37
9

I've only ever seen emit() used when building a simple compiler in academia.

Upon analyzing the grammar of a program, you tokenize the contents of it and emit (push out) assembly instructions. (The compiler program that was written actually even contained an internal function called emit to mirror that theoretical/logical aspect of it.)

Once the grammar analysis is complete, the assembler will take the assembly instructions and generate the binary code (aka machine code).

So, I don't think there is a general CS definition for emit; however, I do know it is used in the pseudocode (and sometimes, actual code) for writing compiler programs. And that is undergraduate level computer science education in the US.

ryuu9187
  • 1,162
  • 7
  • 15
5

I can think of three contexts in which it's used:

  • Map/Reduce functions, where some input value causes 0 or more output values to go into the Reduce function
  • Tokenizers, where a stream of text is processed, and at various intervals, tokens are emitted
  • Messaging systems

I think the common thread is the "zero or more". A return provides exactly one value back from a function, whereas an "emit" is a function call that could take place zero times or several times.

Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
  • giving this a check mark on the basis of "zero or more" as compared to "return" – JDS Oct 26 '17 at 17:36
0

In the context of the MapReduce programming model, it is said that an operation of a map nature takes an input value and emits a result, which is nothing more than a transformation of the input.

Ricardo Sanchez
  • 704
  • 6
  • 21