Queue/Definition: Difference between revisions

→‎{{header|J}}: Added implementation involving only functional programming.
(→‎{{header|J}}: Added implementation involving only functional programming.)
Line 826:
 
=={{header|J}}==
Object oriented technique, using mutable state:
 
<lang J>queue_fifo_=: ''
Line 843 ⟶ 844:
0=#queue
)</lang>
 
Function-level technique, with no reliance on mutable state:
 
<lang J>
pop =: ( {.^:notnull ; }. )@: > @: ] /
push =: ( '' ; ,~ )& > /
tell_atom =: >& {.
tell_queue =: >& {:
is_empty =: '' -: queue
 
make_empty =: a: , a: [ ]
onto =: [ ; }.@]
 
notnull =: [: -. 0 e. $
</lang>
 
See also [[FIFO (usage)#J]]
Anonymous user