What does "emit" mean in general computer science terms?
Asked Answered
D

4

27

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.

Duodenitis answered 7/7, 2015 at 13:57 Comment(4)
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/storingPich
Just a note for the future: there's actually a computer science version of Stack Overflow, cs.stackexchange.com that would be more appropriate for this question. It's a great site!Inconvenience
This is a meta question: How do I move that to cs.stackexchange without double posting?Duodenitis
@AlexK. i get that, but how does "emit" differ from "return", in your example?Duodenitis
H
6

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.

Hauser answered 8/12, 2016 at 10:8 Comment(1)
giving this a check mark on the basis of "zero or more" as compared to "return"Duodenitis
D
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.

Diaster answered 22/4, 2018 at 5:23 Comment(0)
Y
10

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.

Yee answered 30/9, 2015 at 17:33 Comment(0)
H
6

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.

Hauser answered 8/12, 2016 at 10:8 Comment(1)
giving this a check mark on the basis of "zero or more" as compared to "return"Duodenitis
C
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.

Capsaicin answered 28/8, 2020 at 3:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.