GithubHelp home page GithubHelp logo

wirth-algorithms's Introduction

Examples from N. Wirth "Algorithms and Data Structures. Oberon version", 2004, updated 2012.

Book is available for free here.

General remarks

Short-circuit evaluation

Boolean operators in both C and Oberon are short-circuit, while Fortran operators are neither short-circuit nor eager: the language specification allows the compiler to select the method for optimization. Consequently, conditionals and loops relaying on short-circuit evaluation, for instance,

WHILE (A) & (B) & (C) DO
  D
END;

has to be rewritten in Fortran as follows,

do while (A)
    if (.not. B) exit
    if (.not. C) exit
    D
end do

Arrays numbering

C as well as Oberon uses zero-based numbering for arrays, Fortran on the other hand has arrays with user-defined indices and by default subscripts starts with one. Without starting rather useless zero- vs. one-based numbering holy war, for languages which allow the freedom of choice we adopt the zero-based numbering for uniformity.

Dijkstra's Loop

Both C and Fortran lack the so-called Dijkstra's Loop (also referred to as the Dijkstra's Guarded Loop) construct which is used in the book. It was originally defined in the Guarded Command Language (GCL) with the following syntax,

do G0 -> S0
| G1 -> S1
...
| Gn -> Sn
od

and with the semantics that the repetition executes the guarded commands repeatedly until none of the guards are true.

Dijkstra's Loop is directly supported in just a few programming languages (for instance, in Oberon-07), where its syntax is as follows,

WHILE G0 DO
    S0
ELSIF G1 DO
    S1
...
ELSIF Gn DO
    Sn
END

In other languages it can be easily emulated as shown below for the example of C,

while (true) {
    if (G0)
        S0
    else if (G1)
        S1
    ... 
    else if (Gn)
        Sn
    else
        break;
}

wirth-algorithms's People

Contributors

kemiisto avatar

Stargazers

 avatar scvalencia avatar

Watchers

 avatar James Cloos avatar

wirth-algorithms's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.