Logo

Programming-Idioms

  • PHP
  • Python
  • Scheme
  • Pascal
  • JS

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)

let dog = 'Poodle';
const dogAlert = () => alert(dog);
const greet = who => console.log(`Hi ${who}!`)

Arrow function syntax. It consists of three parts: arguments, arrow and code block.
var bli = function() { 
	console.log('Hello World!!!');
}
function bli() { 
	console.log('Hello World!!!');
}
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.
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()
(define (finish name)
    (display "My job here is done. Goodbye ")
    (display name)
    (newline))

This is a short syntax for a lambda definition.
(define finish
    (lambda (name)
        (display "My job here is done. Goodbye ")
        (display name)
        (newline)))
Procedure finish(name: String);
Begin
  WriteLn('My job here is done. Goodbye ', name);
End;
procedure Finish (Name : String) is
begin
   Put_Line ("My job here is done. Goodbye " & Name);
end Finish;

New implementation...
< >
programming-idioms.org