Welcome to the Dictionary of Programming Languages, a compendium
of computer coding methods assembled to provide information and
aid your appreciation for computer science history.
Browse the dictionary by clicking on a section:
A
B
C
D
E
F
G
H
I
JK
L
M
N
O
P
QR
S
T
UV
WXYZ+
Get a full dump of the dictionary:
List of Names
Short Form
Full Form
HOW TO RETURN index doc: PUT {} IN where FOR line.no IN keys doc: TREAT LINE RETURN where TREAT LINE: FOR word IN split doc[line.no]: IF word not.in keys where: PUT {} IN where[word] INSERT line.no IN where[word]
PROGRAM ONE WHEEL " Simple model of a dynamical system " written in ACSL 1, circa 1982. INITIAL CINTERVAL CINT = 0.05 ALGORITHM IALG = 4 $ "RK3" CONSTANT X1IO = 0.0, X2IO=0.0, X1DIC=0.0, X2DIC = 0.0 CONSTANT M1 = 25.0, M2=2.0, DF=100.0, K2=5000 CONSTANT TDONE = 15.0 K1 = 1000.0 END $ "OF INITIALIZATION" DYNAMIC DERIVATIVE X3= STEP(0.0) X1D = INTEG((-DF/M1)*(X1D-X2D) - (K1/M1)*(X1-X2), X1DIC) X2D = INTEG((-DF/M1)*(X1D-X2D) - (K1/M1)*(X1-X2), ... (K2/M2)*(X2-X3*5.0), X2DIC) X1 = INTEG(X1D,X1IO) X2 = INTEG(X2D,X2IO) END "OF DERIVATIVE SECTION" TERMT(T .GE. TDONE) END "OF DYNAMIC SECTION" END "OF PROGRAM"
-- simple programming with floating-point #s with Ada.Float_Text_IO; use Ada.Float_Text_IO; procedure Think is A, B : Float := 0.0; -- A and B initially zero; note the period. I, J : Integer := 1; begin A := B * 7.0; I := J * 3; B := Float(I) / A; Put(B); end Think;
/* An Alef program to parse numbers out of * the string returned from /dev/time, and * print them from a separate proc. This is * a rather lame conglomeration of several * examples from Bob Flandrea's Alef * User's Guide */ tuple(int, uint, byte*) strtoui(byte* str, int base) { int val; while(*str != 0 && whitespace(*str)) str ; if(str == nil || *str == 0) return(0, 0, str); while(*str && !whitespace(*str)) { if(!validdigit(*str, base)) return (-1, val, str 1); /* extract digit into val */ str ; } return(1, val, str); } void receive(chan(uint) c) { int s; s = <-c; print("%d\n", s); if (s == 0) terminate(nil); } void main(void) { chan(uint) c; alloc c; proc receive(c); int ret; uint val; int fd; byte *p, buf[128], *newp; fd = open("/dev/time", OREAD|OCEXEC); if (fd >= 0) { read(fd, buf, sizeof(buf)); for(p = buf; *p; p = newp) { (ret, val, newp) = strtoui(p, 10); if(ret >= 0) c <-= val; if(ret == 0) break; } } }
// the main program, calculate the mean of // some numbers begin integer N; Read Int(N); begin real array Data[1:N]; real sum, avg; integer i; sum:=0; for i:=1 step 1 until N do begin real val; Read Real(val); Data[i]:=if val<0 then -val else val end; for i:=1 step 1 until N do sum:=sum Data[i]; avg:=sum/N; Print Real(avg) end end
Here is a better example, written in the
Algol60 publication language, from
Jean Sammet courtesy of
Glyn Webster.
procedure problem (a, b); value a, b; integer a, b; begin integer k; real e; for k := 2 × (a ÷ 2) 1 step 2 until b do begin e := if prime(k) then sqrt(3 × k sin(k)) else sqrt(4 × k cos(k)); if prime(k) then putlist(k, e, 'prime') else putlist(k, e, 'nonprime') end end problem;
-- Use the Finder to close all applications -- (by Joshua D. Baer) property specialApps : {"Finder"} tell application "Finder" set allApps to name of processes end tell repeat with someParticularApp in allApps if specialApps does not contain someParticularApp then tell application someParticularApp activate quit end tell end if end repeat
;; Very simple example of interactive extension ;; for AutoCAD (Defun c:SF2ACRE () (setq SF (getreal "Enter area in square feet: ")) (setq AGREAGE (/ SF 43560.0)) (alert (strcat "\nThe area in acres is " (rtos ARGEAGE 2 2))) )
BEGIN { if ("'$#argv'"==1) Col="'$1'"; else Col=1 } {Total = $Col; }; END { printf "Total for column %d with %d items: %d\n", Col,NR,Total }
class ACCOUNT feature balance: INTEGER; owner: PERSON; minimum_balance: INTEGER is 1000 open (who: PERSON) is -- Assign the account to owner who. do owner := who end deposit (sum: INTEGER) is -- Deposit sum into the account. do add (sum) end withdraw (sum: INTEGER) is -- Withdraw sum from the account. do add (-sum) end may_withdraw (sum: INTEGER): BOOLEAN is -- Is there enough money to withdraw sum? do Result := (balance >= sum + minimum_balance) end feature {NONE} add (sum: INTEGER) is -- Add sum to the balance. do balance := balance + sum end end -- class ACCOUNT
;; Simple Elisp example (defconst date-pattern-1 "\\(1?[0-9]\\)/\\([123]?[0-9]\\)/\\([0-9][0-9]\\)" "Regexp for one style of data string") (defun replace-all-dates () "Replace 1/27/93 dates with 27-1-93 dates" (interactive) (let ((mcount 0)) (while (re-search-forward date-pattern-1 nil t) (replace-match "\\2-\\1-\\3" nil nil) (setq mcount (+ 1 mcount))) (message (format "Replaced %d dates" mcount))) )
-module(sort). -export([sort/1]). sort([]) -> []; sort([Pivot|Rest]) -> {Smaller, Bigger} = split(Pivot, Rest), lists:append(sort(Smaller), [Pivot|sort(Bigger)]). split(Pivot, L) -> split(Pivot, L, [], []). split(Pivot, [], Smaller, Bigger) -> {Smaller, Bigger}; split(Pivot, [Hd|Tl], Smaller, Bigger) when Hd < Pivot -> split(Pivot, Tl, [Hd|Smaller], Bigger); split(Pivot, [Hd|Tl], Smaller, Bigger) when Hd >= Pivot -> split(Pivot, T, Smaller, [Hd|Bigger]).
Alternative version using Erlang 4.4 features:
-module(sort). -export([sort/1]). sort([Pivot|T]) -> sort([ X || X <- T, X < Pivot]) ++ [Pivot] ++ sort([ X || X <- T, X >= Pivot]); sort([]) -> [].
MODULE Lambda. CONSTRUCT Person/0. FUNCTION Jane, Mary, John: One -> Person. FUNCTION Mother : Person * Person -> Boolean. Mother(x,y) => x=Jane & y=Mary. FUNCTION Wife : Person * Person -> Boolean. Wife(x,y) => x=John & y=Jane. FUNCTION PrimitiveRel : (Person * Person -> Boolean) -> Boolean. PrimitiveRel(r) => r=Mother \/ r=Wife. FUNCTION Rel : (Person * Person -> Boolean) -> Boolean. Rel(r) => PrimitiveRel(r) \/ (SOME [r1,r2] (r = LAMBDA [u] (SOME [z] (r1(Fst(u),z) & r2(z,Snd(u)))) & PrimitiveRel(r1) & PrimitiveRel(r2))).
module AVERAGE: input INCREMENT_AVERAGE(integer); output AVERAGE_VALUE(integer); var TOTAL := 0, NUMBER := 0, : integer in every immediate INCREMENT_AVERAGE do TOTAL := TOTAL + ? INCREMENT_AVERAGE; NUMBER := NUMBER + 1; emit AVERAGE_VALUE (TOTAL / NUMBER) end end.
-- Prime sieve benchmark, adapted from Euphoria 2.0beta demos constant ON = 1, OFF = 0, SIZE = 5000, BATCH = 20 function sieve() sequence flags integer prime, start, count, still_prime count = 0 flags = repeat(ON, SIZE) for i = 1 to SIZE do still_prime = flags[i] if still_prime then prime = 2 * i prime = prime + 1 start = prime + i for k = start to SIZE by prime do flags[k] = OFF end for count = count + 1 end if end for return count end function atom t, cycles, p cycles = 0 t = time() while time() < t + 30 do -- test for 30 seconds for iter = 1 to BATCH do p = sieve() end for cycles = cycles + BATCH end while t = time() - t printf(1, "%6.1f sieves per second\n", cycles / t)
func cmplxplot(z, u) /* DOCUMENT cmplxplot, z, u * plots a scalar complex function of a complex variable. */ { resx=100; resy=100; s=[[sqrt(2./3.),0,1/sqrt(3)],[-1/sqrt(2*3.0),1/sqrt(2.),1/sqrt(3)], [-1/sqrt(2*3.0),-1/sqrt(2.),1/sqrt(3)]]; phi=span(-pi,pi,256); vec=array(double,3,256); vec(1,)=cos(phi); vec(2,)=sin(phi); vec(3,)=1/sqrt(2)(-); f=s(+,)*vec(+,); palette,bytscl(f(2,),top=255),bytscl(f(1,),top=255),bytscl(f(3,),top=255); xmin=min(u.re); xmax=max(u.re); ymin=min(u.im); ymax=max(u.im); zi=array(complex,resx,resy); zi.re=interp2(span(ymin,ymax,resy)(-:1:resx,),span(xmin,xmax,resx)(,-:1:resy), z.re,u.im,u.re); zi.im=interp2(span(ymin,ymax,resy)(-:1:resx,),span(xmin,xmax,resx)(,-:1:resy), z.im,u.im,u.re); // Caution: on some platforms atan(0,0) crashes ! arr=bytscl(atan(zi.im,zi.re+1e-200),cmin=-pi,cmax=pi); pli,arr, xmin,ymin,xmax,ymax; plc,abs(z),u.im,u.re,marks=0; }
class ACCOUNT feature balance: INTEGER; owner: PERSON; minimum_balance: INTEGER is 1000 open (who: PERSON) is -- Assign the account to owner who. do owner := who end deposit (sum: INTEGER) is -- Deposit sum into the account. do add (sum) end withdraw (sum: INTEGER) is -- Withdraw sum from the account. do add (-sum) end may_withdraw (sum: INTEGER): BOOLEAN is -- Is there enough money to withdraw sum? do Result := (balance >= sum + minimum_balance) end feature {NONE} add (sum: INTEGER) is -- Add sum to the balance. do balance := balance + sum end end -- class ACCOUNT
;; Simple Elisp example (defconst date-pattern-1 "\\(1?[0-9]\\)/\\([123]?[0-9]\\)/\\([0-9][0-9]\\)" "Regexp for one style of data string") (defun replace-all-dates () "Replace 1/27/93 dates with 27-1-93 dates" (interactive) (let ((mcount 0)) (while (re-search-forward date-pattern-1 nil t) (replace-match "\\2-\\1-\\3" nil nil) (setq mcount (+ 1 mcount))) (message (format "Replaced %d dates" mcount))) )
-module(sort). -export([sort/1]). sort([]) -> []; sort([Pivot|Rest]) -> {Smaller, Bigger} = split(Pivot, Rest), lists:append(sort(Smaller), [Pivot|sort(Bigger)]). split(Pivot, L) -> split(Pivot, L, [], []). split(Pivot, [], Smaller, Bigger) -> {Smaller, Bigger}; split(Pivot, [Hd|Tl], Smaller, Bigger) when Hd < Pivot -> split(Pivot, Tl, [Hd|Smaller], Bigger); split(Pivot, [Hd|Tl], Smaller, Bigger) when Hd >= Pivot -> split(Pivot, T, Smaller, [Hd|Bigger]).
Alternative version using Erlang 4.4 features:
-module(sort). -export([sort/1]). sort([Pivot|T]) -> sort([ X || X <- T, X < Pivot]) ++ [Pivot] ++ sort([ X || X <- T, X >= Pivot]); sort([]) -> [].
MODULE Lambda. CONSTRUCT Person/0. FUNCTION Jane, Mary, John: One -> Person. FUNCTION Mother : Person * Person -> Boolean. Mother(x,y) => x=Jane & y=Mary. FUNCTION Wife : Person * Person -> Boolean. Wife(x,y) => x=John & y=Jane. FUNCTION PrimitiveRel : (Person * Person -> Boolean) -> Boolean. PrimitiveRel(r) => r=Mother \/ r=Wife. FUNCTION Rel : (Person * Person -> Boolean) -> Boolean. Rel(r) => PrimitiveRel(r) \/ (SOME [r1,r2] (r = LAMBDA [u] (SOME [z] (r1(Fst(u),z) & r2(z,Snd(u)))) & PrimitiveRel(r1) & PrimitiveRel(r2))).
module AVERAGE: input INCREMENT_AVERAGE(integer); output AVERAGE_VALUE(integer); var TOTAL := 0, NUMBER := 0, : integer in every immediate INCREMENT_AVERAGE do TOTAL := TOTAL + ? INCREMENT_AVERAGE; NUMBER := NUMBER + 1; emit AVERAGE_VALUE (TOTAL / NUMBER) end end.
-- Prime sieve benchmark, adapted from Euphoria 2.0beta demos constant ON = 1, OFF = 0, SIZE = 5000, BATCH = 20 function sieve() sequence flags integer prime, start, count, still_prime count = 0 flags = repeat(ON, SIZE) for i = 1 to SIZE do still_prime = flags[i] if still_prime then prime = 2 * i prime = prime + 1 start = prime + i for k = start to SIZE by prime do flags[k] = OFF end for count = count + 1 end if end for return count end function atom t, cycles, p cycles = 0 t = time() while time() < t + 30 do -- test for 30 seconds for iter = 1 to BATCH do p = sieve() end for cycles = cycles + BATCH end while t = time() - t printf(1, "%6.1f sieves per second\n", cycles / t)
REBOL [ Title: "99 Bottles of Beer on the Wall in REBOL" Author: Neal Ziring Email: ziring@home.com Date: 17-Oct-1998 File: %99beer.r Version: #REBOL-1-0-1 Purpose: "Print the famous iterative beer song" Comment: { This is an example of a program in REBOL that prints the famous 99 bottles of beer on the wall song. For more information on REBOL go to the web site www.rebol.com. This program is deliberately over-complicated to hot-dog some fancy features of REBOL. } ] song: [ Verse [ [if num > 0 [num] else ["No more"] ] " " [if num == 1 ["bottle"] else ["bottles"] ] " of beer on the wall," 1 [if num > 0 [num] else ["No more"] ] " " [if num == 1 ["bottle"] else ["bottles"] ] " of beer!" 1 "Take one down, pass it around!" 1 [if num - 1 > 0 [num - 1] else ["No more"] ] " " [if num - 1 == 1 ["bottle"] else ["bottles"] ] " of beer on the wall." 2 ] Finale [ "Time to buy more beer!" 1 ] ] processItem: func [item num] [ if integer? item [loop item [prin newline] ] if string? item [prin item] if block? item [ftmp: func [num] item prin ftmp num ] exit ] dosong: func [start] [ bottlesleft: start until [ foreach item song/Verse [processItem item bottlesleft] bottlesleft: bottlesleft - 1 (bottlesleft == 0) ] foreach item song/Finale [processItem item 0] return none ] dosong 99
PROCEDURE EUCLID(A,B,X); BEGIN SCALAR R,Q,AA,BB,SA,SB,SR,D; CLEAR FIRST,SECOND; AA := A; BB := B; SA := FIRST; SB := SECOND; WHILE (R := POLYREM(AA,BB,X)) NEQ 0 DO <<ON GCD; Q := (AA - R) / BB; OFF GCD; SR := SA - Q * SB; D := DEN Q; SA := SB * D; SB := SR * D; AA := BB * D; BB := R * D>>; RETURN SB END;
/* Subroutine example from Ian Collier's tutorial, */ /* stand-in until I get a more extensive example. */ /* Calculate factorial x, that is, 1*2*3* ... *x */ parse pull x . say x"!="factorial(x) exit factorial: /* calculate the factorial of the argument */ procedure parse arg p if p<3 then return p else return factorial(p-1) * p
* A simple RPG subprocedure to determine * an amount to pay a worker. From IBM * book SC09-2074-01 "RPG/400 Programmer's Guide" P CalcPay B D CalcPay PI 8P 2 D Rate 5P 2 VALUE D Hours 10U 0 VALUE D Bonus 5P 2 VALUE D Overtime S 5P 2 INZ(0) * Determine any overtime hours to be paid. C IF Hours > 40 C EVAL Overtime = (Hours - 40) * Rate * 1.5 C EVAL Hours = 40 C ENDIF * Calculate the total pay and return it to the caller C RETURN Rate * Hours Bonus Overtime P CalcPay E
# sieve of Eratosthenes max = Integer(ARGV.shift || 100) sieve = [] for i in 2 .. max sieve[i] = i end for i in 2 .. Math.sqrt(max) next unless sieve[i] (i*i).step(max, i) do |j| sieve[j] = nil end end puts sieve.compact.join ", "
{ Table data structure, adapted from an example in "Multiparadigm Data Structures in Leda" by Tim Budd, 1993 Assumes the list data structure is already defined. } class Association [X, Y : equality] of equality[Association]; var key : X; value : Y; function equals(argValue : Association[X, Y])->boolean; begin return key = argValue.key; end; end; class Table [X, Y : equality] { of equality[Association] }; var data : List[Association[X, Y]]; function add (newKey : X, newValue : Y); begin if ~ defined(data) then data := List[Association[X, Y]](); data.add(Association[X, Y](newKey, newValue)); end; function onEach (theFun : function(X, Y)); begin if defined(data) then data.onEach(function (item : Association[X, Y]); begin theFun(item.key, item.value); end); end; function items (byRef key : X, byRef value : Y)->relation; var element : Association[X, Y]; begin return defined(data) & data.items(element) & unify[X](key, element.key) & unify[Y](value, element.value); end; function includesKey (key : X)->boolean; var value : Y; begin if items(key, value) then return true; return false; end; function at (key : X)->Y; var value : Y; begin if items(key, value) then return value; return NIL; end; function atPut (key : X, value : Y); var element : Association[X, Y]; begin if defined(data) & data.items(element) & element.key = key then element.value := value else add(key, value); end; end;
global(sieve)? global(limit)? main :- write("N=?"), read_token(limit & int), next_prime(2), nl. remove_multiples(P,M) :- cond(M < limit, (sieve.M <-multiple_of(P),remove_multiples(P,M+P)) ). next_prime(P) :- P < limit, !, SP=sieve.P, ( SP=prime(P), !, write(P,' '), remove_multiples(P,2*P) ; succeed ), next_prime(P+1). next_prime(P).
# A simple program to sum up some numbers # presented on the command line, from # Bob Pike's forthcoming book on Limbo. implement Sum; include "sys.m"; sys: Sys; include "draw.m"; Sum: module { init: fn(context: ref Draw->Context, argl: list of string); }; init(context: ref Draw->Context, argl: list of string) { sys = load Sys Sys->PATH; argl = tl argl; # ignore command name if(len argl == 0){ sys->print("usage: sum numbers....\n"); return; } sum := 0.0; while(argl != nil){ arg := hd argl; sys->print("%s", arg); sum += real arg; argl = tl argl; if(argl != nil) sys->print(" + "); } sys->print(" = %g\n", sum); }
;; Simple factorial routine ;; (until I get a better example written) (defun fact1 (num) (cond ((not (integerp num)) nil) ((<= num 1) 1) (t (* num (fact1 (- num 1))))) )
; Recursive procedure to line, fractalized to DrawFractalLine :level :length ifelse :level < 1 [ fd :length] [ DrawFractalLine (sum -1 :level) (quotient :length 3.00) left 60 DrawFractalLine (sum -1 :level) (quotient :length 3.00) right 120 DrawFractalLine (sum -1 :level) (quotient :length 3.00) left 60 DrawFractalLine (sum -1 :level) (quotient :length 3.00) ] end ; procedure to clear screen and position turtle to SetupTurtle cs setpos [-160 -10] right 60 clean end ; setup turtle then draw Koch's snowflake(5) SetupTurtle setpensize [2 2] repeat 3 [DrawFractalLine 5 330 right 120]
' Find agents owned by the current user ' and remove them (Adapted from examples at ' www.lotus.com) Dim session As New NotesSession Dim db As NotesDatabase Dim agentArray(1 To 10) As NotesAgent Dim count as Integer Dim answer as string count = 0 Set db = session.CurrentDatabase Forall a In db.Agents If ( a.Owner = session.UserName ) Then Set agentArray(count) = a count = count + 1 If (count > 10) Then Exit Forall End If End If End Forall answer = Inputbox$( "You have " & count & " agents. Delete them?" ) If (answer = "y") Or (answer = "yes") Then Forall a in agentArray Call a.Remove End Foreall End If
-- Simple Lua program that implements the -- bisection method for solving non-linear equations function bisect(f,a,b,fa,fb) write(n," a=",a," fa=",fa," b=",b," fb=",fb,"\n") local c=(a+b)/2 if abs(a-b) < delta then return c end n=n+1 local fc=f(c) if fa*fc < 0 then return bisect(f,a,c,fa,fc) else return bisect(f,c,b,fc,fb) end end -- find root of f in the inverval [a,b]. -- bisection requires that f(a)*f(b) < 0 function solve(f,a,b) delta=1e-6 -- tolerance n=0 local z=bisect(f,a,b,f(a),f(b)) write(format("after %d steps, root is %.10g\n",n,z)) end -- test the bisection code with -- a function: x^3 - x - 1 function f(x) return x*x*x - x - 1 end solve(f,1,2)
h where h = 1 fby merge(merge(2 * h, 3 * h), 5 * h); merge(x,y) = if xx <= yy then xx else yy fi where xx = x upon xx <= yy; yy = y upon yy <= xx; end; end;
Descriptions in this dictionary are ©1997-99 Neal Ziring. Some examples copyright of their respective authors. Some technologies and languages are trademarked. Permission to copy descriptions is granted as long as authorship credit is preserved.
Comments on this dictionary, corrections and suggestions, are all welcome. Please use email, the address is ziring@home.com
[Ziring MicroWeb Home] [Dictionary Start] [Sign Guestbook]
Dictionary and script maintained by Neal Ziring, last major modifications 3/18/98. Most recent additions to dictionary and master list, 1/00.