Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a queue in ATS?

Tags:

ats

I can use a list like a stack, but what is a proper way to create a queue in ATS? For instance, say I have the following pseudo code:

val xs = queue_create()
val () = xs.enqueue(1)
val () = xs.enqueue(2)
val () = print(xs.dequeue()) // print 1
val () = xs.enqueue(3)
val () = print(xs.dequeue()) // print 2
val () = print(xs.dequeue()) // print 3

I should see that 1, 2, and 3 are printed out.


1 Answers

Since I'm unaware of a queue type built in the ATS standard library, I offer my own basic implementation from one of my projects, adapted from the code referenced in the Linear Channels for Asynchronous IPC chapter of the Introduction to Programming in ATS book.

See a working example in this snippet.

like image 114
Arets Paeglis Avatar answered Feb 17 '26 01:02

Arets Paeglis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!