Queue/Definition: Difference between revisions
Content added Content deleted
m (BBC BASIC moved to the BASIC section.) |
(add lambdatalk code) |
||
Line 3,998: | Line 3,998: | ||
{{VI solution|LabVIEW_Queue_Definition.png}} |
{{VI solution|LabVIEW_Queue_Definition.png}} |
||
=={{header|Lambdatalk}}== |
|||
The APIs of queues are built on lambdatalk array primitives, [A.new, A.disp, A.join, A.split, A.array?, A.null?, A.empty?, A.in?, A.equal?, A.length, A.get, A.first, A.last, A.rest, A.slice, A.duplicate, A.reverse, A.concat, A.map, A.set!, A.addlast!, A.sublast!, A.addfirst!, A.subfirst!, A.reverse!, A.sort!, A.swap!, A.lib]. Note that the [A.addlast!, A.sublast!, A.addfirst!, A.subfirst!] primitives are the standard [push!, shift!, pop!, unshift!] ones. |
|||
<syntaxhighlight lang="scheme"> |
|||
{def queue.add |
|||
{lambda {:v :q} |
|||
{let { {_ {A.addlast! :v :q}}} |
|||
} ok}} |
|||
-> queue.add |
|||
{def queue.get |
|||
{lambda {:q} |
|||
{let { {:v {A.first :q}} |
|||
{_ {A.subfirst! :q}} |
|||
} :v}}} |
|||
-> queue.get |
|||
{def queue.empty? |
|||
{lambda {:q} |
|||
{A.empty? :q}}} |
|||
-> queue.empty? |
|||
{def Q {A.new}} -> Q [] |
|||
{queue.add 1 {Q}} -> ok [1] |
|||
{queue.add 2 {Q}} -> ok [1,2] |
|||
{queue.add 3 {Q}} -> ok [1,2,3] |
|||
{queue.get {Q}} -> 1 [2,3] |
|||
{queue.add 4 {Q}} -> ok [2,3,4] |
|||
{queue.empty? {Q}} -> false |
|||
{queue.get {Q}} -> 2 [3,4] |
|||
{queue.get {Q}} -> 3 [4] |
|||
{queue.get {Q}} -> 4 [] |
|||
{queue.get {Q}} -> undefined |
|||
{queue.empty? {Q}} -> true |
|||
</syntaxhighlight> |
|||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
Definition: |
Definition: |