This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
Idiom #3 Create a procedure
Like a function which doesn't return any value, thus has only side effects (e.g. Print to standard output)
- Ada
- C
- Caml
- Clojure
- C++
- C#
- C#
- D
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Go
- Groovy
- Haskell
- JS
- JS
- JS
- JS
- Java
- Java
- Java
- Java
- Kotlin
- Lisp
- Lua
- Obj-C
- PHP
- PHP
- Pascal
- Perl
- Python
- Python
- Ruby
- Rust
- Scala
- Scheme
- Scheme
- Smalltalk
- VB
(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.
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 { .
const greet = who => console.log(`Hi ${who}!`)
Arrow function syntax. It consists of three parts: arguments, arrow and code block.
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.
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
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
(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