Seed7 demo programs
Start a program by clicking on the image. Loading a program for the first time may take some time. It may be necessary to unblock a blocked popup. The button to unblock is often in or near to the browsers address line. Usually there are also settings to allow the browser to open popup windows for this website. While the program runs the browser tab needs to stay active. The program will not work correctly if the browser opens it in a new tab instead of a popup window. Only one program can run at a time. A running program can be terminated with:
Programming quiz
Clicking on the text shows a description of the program. Clicking on an image starts a JavaScript/WebAssembly program in the browser. The programs have been compiled from Seed7 source code. The same source code can be used to create native Linux, Windows or MacOs executables.
Synchronous and asynchronous I/O
Seed7 programs use synchronous I/O and browsers only support asynchronous I/O. The asynchronous I/O of browsers requires that functions finish quickly and never wait for anything. To wait for an input (e.g. a keypress), a function must register a callback function (or promise) and terminate itself. Later when the input is received, the callback function is called. For the next input, another callback must be registered and so on.
With synchronous I/O a (possibly deeply nested) function can issue a read command. The function will wait until the reading is completed. The state of the program (local variables, parameters, etc.) will stay intact. Seed7 provides a driver to map the synchronous I/O of Seed7 to the asynchronous I/O of browsers. After a promise has been created, the whole call stack (local variables, parameters, etc.) is saved and the program is terminated. When the promise is activated, the call stack is restored and the program continues in the function.
With synchronous I/O you can do:write("Start new game [Y/N]? "); case getc(KEYBOARD) of when {'y', 'Y'}: newGame := TRUE; when {'n', 'N'}: noop; otherwise: writeln("Please type Y or N."); end case;
Active and non-active tabs
Browsers distinguish between active and non-active tabs. In a non-active tab every timer request (e.g. setTimeout) waits for at least a second. So all time dependent things like animations will not run smoothly when the tab is not active. When a new window is requested in JavaScript with window.open() the result is either a popup or a new tab. There is a problem if a browser opens a tab instead of a popup: The script runs in the old tab and the new tab gets the focus. Without focus the script is slowed down and therefore time related functionality will not work. The graphics driver for the browser tries to discover if a tab has been opened instead of a popup. It uses heuristics for this purpose. If a tab has been opened the new opened tab is closed and the content of the current tab is used as window. To do that the current tab document is overwritten with a canvas. When the program exits this tab is reloaded and this way it gets the original content.