Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- C
- Java
- Java
- Java
- Java
- Ada
- Caml
- Clojure
- C++
- C#
- C#
- D
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Go
- Groovy
- Haskell
- JS
- JS
- JS
- JS
- Kotlin
- Lisp
- Lua
- Obj-C
- PHP
- PHP
- Pascal
- Perl
- Python
- Python
- Ruby
- Rust
- Scala
- Scheme
- Scheme
- Smalltalk
- VB
void finish(void) {
printf("My job here is done.\n");
}
interface F { void set(); }
F f = () -> out.println("abc");
f.set();
void f() { out.println("abc"); }
private void methodName() {
System.out.println("Hello, World!");
}
void finish(String name){
System.out.println("My job here is done. Goodbye " + name);
}
void means "no return value".
procedure Finish (Name : String) is
begin
Put_Line ("My job here is done. Goodbye " & Name);
end Finish;
let do_something arg1 arg2: unit =
print_endline "foo"
(defn main- [& args]
(println "I got all this arguments " args " and now I'm returning nil. Peace out!"))
The syntax "& args" in the arguments vector means this function can take any number of arguments.
void finish(String name) {
print("My job here is done. Goodbye $name.");
}
def finish(name) do
IO.puts "My job here is done. Goodbye #{name}"
end
-spec procedure() -> _.
procedure() -> io:format("#YOLO!~n").
There is no way to avoid returning a value here. This function returns ok. But you can add -spec to say that you should not care about the result.
module foo
implicit none
contains
subroutine bar
print *,"Hello"
end subroutine bar
end module foo
Modern Fortran should use modules and implicit none, so I added both.
finish := func(name string) {
fmt.Println("My job here is done. Good bye " + name)
}
This is a closure.
finish is a variable of type func(string).
finish is a variable of type func(string).
func finish(name string) {
fmt.Println("My job here is done. Good bye " + name)
}
There is no return type in the signature, before the { .
void finish(String name){
println "My job here is done. Goodbye $name"
}
f = print "whatever"
actually a side effecting action as reusable value
function bli() {
console.log('Hello World!!!');
}
var bli = function() {
console.log('Hello World!!!');
}
const greet = who => console.log(`Hi ${who}!`)
Arrow function syntax. It consists of three parts: arguments, arrow and code block.
let dog = 'Poodle';
const dogAlert = () => alert(dog);
(defun show (message)
(format t "Hello: ~a" message)
(values))
function finish(name)
print('My job here is done. Goodbye, '..name..'.')
end
void foo(void) {
NSLog(@"My job here is done. Goodbye\n");
}
function finish($name)
{
echo "My job here is done. Goodbye $name";
}
function()
{
echo "Hello World";
}
This is an unnamed function, it can be bound to a variable or else immediately executed - the demo has both usages in it.
Procedure finish(name: String);
Begin
WriteLn('My job here is done. Goodbye ', name);
End;
sub some_procedure {
print 'some side effect';
return;
}
Due to context sensitivity and automatic value conversions on assignment, it is de facto not possible to not return a value. Even a naked `return;` will result in `undef` or empty list at the caller. A naive attempt to fix the problem by omitting the return statement does not help: then the return value of the last statement before exiting the subroutine will be used instead; in the example, that would be the return value of `print`.
def finish(name):
print(f'My job here is done. Goodbye {name}')
Variable name inside curly braces will be replaced by its value. This is called "f-strings" introduced in Python version 3.6
f = lambda: print('abc')
f()
def finish( name )
puts "My job here is done. Goodbye #{name}"
end
Ruby methods always return something; in this case nil, the return value of puts
def doSomething(name: String): Unit = {
println(s"My job here is done. Goodbye ${name}")
}
(define finish
(lambda (name)
(display "My job here is done. Goodbye ")
(display name)
(newline)))
(define (finish name)
(display "My job here is done. Goodbye ")
(display name)
(newline))
This is a short syntax for a lambda definition.
methodWithoutReturn
self doSomething.
[Transcript showln: 'something'] value.
Note that this is how it typically looks in a Smalltalk code browser and belongs a class of some sort.
Moreover, line 4, `[Transcript showln: 'something'] value.` creates an anonymous procedure and invokes it directly via value
Moreover, line 4, `[Transcript showln: 'something'] value.` creates an anonymous procedure and invokes it directly via value