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
Lucid (programming language)
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!
{{Short description|Dataflow programming language}} {{For|the Lisp software company|Lucid Inc.}} {{primary sources|date=April 2018}} {{Infobox programming language |name = Lucid |logo = |paradigm = [[Dataflow programming|Dataflow]] |year = 1976 |designer = Edward A. Ashcroft<br/>William W. Wadge |developer = |latest release version = |latest release date = |typing = Typeless |implementations = pLucid, GIPSY |dialects = Granular Lucid, Indexical Lucid, Tensor Lucid, Forensic Lucid, Lucx, JOOIPL |influenced_by = [[ISWIM]] |influenced = [[SISAL]], [[PureData]], [[Lustre (programming language)|Lustre]] }} '''Lucid''' is a [[dataflow programming]] language designed to experiment with non-[[Von Neumann architecture|von Neumann]] programming models. It was designed by Bill Wadge and Ed Ashcroft and described in the 1985 book ''Lucid, the Dataflow Programming Language''.<ref name="book"/> pLucid was the first [[interpreter (computing)|interpreter]] for Lucid. ==Model== Lucid uses a demand-driven model for data computation. Each statement can be understood as an equation defining a network of processors and communication lines between them through which data flows. Each [[variable (computer science)|variable]] is an infinite stream of values and every function is a filter or a transformer. [[Iteration]] is simulated by 'current' values and 'fby' (read as 'followed by') operator allowing composition of streams. Lucid is based on an [[algebra]] of histories, a history being an infinite sequence of data items. Operationally, a history can be thought of as a record of the changing values of a variable, history operations such as first and next can be understood in ways suggested by their names. Lucid was originally conceived as a disciplined, mathematically pure, single-assignment language, in which verification would be simplified. However, the [[dataflow]] interpretation has been an important influence on the direction in which Lucid has evolved.[https://web.archive.org/web/20110514103454/http://hopl.murdoch.edu.au/showlanguage2.prx?exp=960] ==Details== In Lucid (and other [[dataflow]] languages) an expression that contains a variable that has not yet been [[Free variables and bound variables|bound]] waits until the variable has been bound, before proceeding. An expression like <code>x + y</code> will wait until both x and y are bound before returning with the output of the expression. An important consequence of this is that explicit logic for updating related values is avoided, which results in substantial code reduction, compared to mainstream languages. Each variable in Lucid is a stream of values. An expression <code>n = 1 fby n + 1</code> defines a stream using the operator 'fby' (a [[mnemonic]] for "followed by"). fby defines what comes after the previous expression. (In this instance the stream produces 1,2,3,...). The values in a stream can be addressed by these operators (assuming x is the variable being used): <code>'first x'</code> - fetches the first value in the stream x, <code>'x'</code> - the current value of the stream, <code>'next x'</code> - fetches the next value in the stream. <code>'asa'</code> - an operator that does some thing 'as soon as' the condition given becomes true. <code>'x upon p'</code> - upon is an operator that repeats the old value of the stream x, and updates to the new values only when the stream p makes a <code>true</code> value available. (It serves to slow down the stream x) i.e.: <code>x upon p</code> is the stream x with new values appearing upon the truth of p. The computation is carried out by defining filters or transformation functions that act on these time-varying streams of data. ==Examples== ===Factorial=== {{main|Factorial}} <syntaxhighlight lang="prolog"> fac where n = 0 fby (n + 1); fac = 1 fby ( fac * (n + 1) ); end </syntaxhighlight> ===Fibonacci sequence=== {{main|Fibonacci sequence}} <syntaxhighlight lang="prolog"> fib where fib = 0 fby ( 1 fby fib + next fib ); end </syntaxhighlight> ===Total of a Sequence=== <syntaxhighlight lang="prolog"> total where total = 0 fby total + x end; </syntaxhighlight> ===Running average=== {{main|Running average}} <syntaxhighlight lang="prolog"> running_avg where sum = first(input) fby sum + next(input); n = 1 fby n + 1; running_avg = sum / n; end; </syntaxhighlight> ===Prime numbers=== {{main|Prime number}} <syntaxhighlight lang="prolog"> prime where prime = 2 fby (n whenever [[isprime]](n)); n = 3 fby n+1; isprime(n) = not(divs) asa divs or prime*prime > N where N is current n; divs = N mod prime eq 0; end; end </syntaxhighlight> ====Dataflow diagram==== {{main|Dataflow diagram}} [[File:Prime numbers sequence dataflow diagram (Lucid).png|center|579x579px]] ===Quick sort=== {{main|Quick sort}} <syntaxhighlight lang="prolog"> qsort(a) = if eof(first a) then {{not a typo|a}} else follow(qsort(b0),qsort(b1)) fi where p = first a < a; b0 = a whenever p; b1 = a whenever not p; follow(x,y) = if xdone then y upon xdone else x fi where xdone = iseod x fby xdone or iseod x; end end </syntaxhighlight> ====Data flow diagram==== <syntaxhighlight lang="text"> --------> whenever -----> qsort --------- | ^ | | | | | not | | ^ | |---> first | | | | | | | V | | |---> less --- | | | | | V V ---+--------> whenever -----> qsort -----> conc -------> ifthenelse -----> | ^ ^ | | | --------> next ----> first ------> iseod -------------- | | | ----------------------------------------------------------- </syntaxhighlight> ===Root mean square=== {{main|Root mean square}} <syntaxhighlight lang="prolog"> sqroot(avg(square(a))) where square(x) = x*x; avg(y) = mean where n = 1 fby n+1; mean = first y fby mean + d; d = (next y - mean)/(n+1); end; sqroot(z) = approx asa err < 0.0001 where Z is current z; approx = Z/2 fby (approx + Z/approx)/2; err = abs(square(approx)-Z); end; end </syntaxhighlight> ===Hamming problem=== {{main|Hamming problem}} <syntaxhighlight lang="prolog"> 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; </syntaxhighlight> ====Dataflow Diagram==== [[File:Hamming problem dataflow diagram (Lucid).png|center|[[Hamming problem]] dataflow diagram]] ==References== {{Reflist|refs= <ref name="book">{{Cite book | first1 = William W. | last1 = Wadge | first2 = Edward A. | last2 = Ashcroft | date = 1985 | title = Lucid, the Dataflow Programming Language | publisher = Academic Press | isbn = 0-12-729650-6 | url = https://archive.org/details/luciddataflowpro00wadg_0 | access-date = 8 January 2015 | url-access = registration }}</ref> }} ==External links== *[https://code.google.com/p/plucid/ pLucid] {{Authority control}} [[Category:Academic programming languages]] [[Category:Concurrent programming languages]] [[Category:Declarative programming languages]] [[Category:Experimental programming languages]] [[Category:Reactive programming languages]] [[Category:Query languages]]
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)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Authority control
(
edit
)
Template:For
(
edit
)
Template:Infobox programming language
(
edit
)
Template:Main
(
edit
)
Template:Not a typo
(
edit
)
Template:Primary sources
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)