Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
ALGOL 68
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Code sample=== This sample program implements the [[Sieve of Eratosthenes]] to find all the [[prime number]]s that are less than 100. '''NIL''' is the ALGOL 68 analogue of the ''null pointer'' in other languages. The notation ''x'' '''OF''' ''y'' accesses a member ''x'' of a '''STRUCT''' ''y''. '''BEGIN''' # Algol-68 prime number sieve, functional style # '''PROC''' error = ('''STRING''' s) '''VOID''': (print(( newline, " error: ", s, newline)); '''GOTO''' stop); '''PROC''' one to = ('''INT''' n) '''LIST''': ('''PROC''' f = ('''INT''' m,n) '''LIST''': (m>n | '''NIL''' | cons(m, f(m+1,n))); f(1,n)); '''MODE''' '''LIST''' = '''REF''' '''NODE'''; '''MODE''' '''NODE''' = '''STRUCT''' ('''INT''' h, '''LIST''' t); '''PROC''' cons = ('''INT''' n, '''LIST''' l) '''LIST''': '''HEAP''' '''NODE''' := (n,l); '''PROC''' hd = ('''LIST''' l) '''INT''': ( l '''IS''' '''NIL''' | error("hd '''NIL'''"); '''SKIP''' | h '''OF''' l ); '''PROC''' tl = ('''LIST''' l) '''LIST''': ( l '''IS''' '''NIL''' | error("tl '''NIL'''"); '''SKIP''' | t '''OF''' l ); '''PROC''' show = ('''LIST''' l) '''VOID''': ( l '''ISNT''' '''NIL''' | print((" ",whole(hd(l),0))); show(tl(l))); '''PROC''' filter = ('''PROC''' ('''INT''') '''BOOL''' p, '''LIST''' l) '''LIST''': '''IF''' l '''IS''' '''NIL''' '''THEN''' '''NIL''' '''ELIF''' p(hd(l)) '''THEN''' cons(hd(l), filter(p,tl(l))) '''ELSE''' filter(p, tl(l)) '''FI'''; '''PROC''' sieve = ('''LIST''' l) '''LIST''': '''IF''' l '''IS''' '''NIL''' '''THEN''' '''NIL''' '''ELSE''' '''PROC''' not multiple = ('''INT''' n) '''BOOL''': n '''MOD''' hd(l) ~= 0; cons(hd(l), sieve( filter( not multiple, tl(l) ))) '''FI'''; '''PROC''' primes = ('''INT''' n) '''LIST''': sieve( tl( one to(n) )); show( primes(100) ) '''END'''
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)