Brian Dunning's FileMaker Custom Functions

DQ_New ( initialContents )

Creates a double-ended queue (DeQue)

  Average rating: 4.4 (26 votes) Log in to vote

Stephen Hanna   Stephen Hanna
Stephen J. Hanna Consulting

Share on Facebook Share on Twitter

  Sample input:
DQ_New( List( "apple" ; "pear" ) )
  Sample output:

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This is a "constructor" function for a package that implements a double-ended queue (DeQue, sometimes pronounced "deck"). DeQues can be used to implement Stacks (LIFO), Queues (FIFO), or more general data structures. Five operations are defined on DeQues: Push and Pop, which add and remove items from the front (top) of the DeQue (thus causing it to behave like a stack); Put and Pull, which add and remove items from the end (bottom) of the DeQue (so Push and Pull are the basic FIFO queue operators); and Count, which returns the number of items in the DeQue.

These functions implement DeQues as global variables, but you don't need to know this or the names of the created variables. DQ_New returns the name of the variable it creates, and all the other manipulation functions accept this name as their first (or only) parameter. Thus, a typical usage sequence would be:

Set Variable [ "$myStack" ; DQ_New ( "apple" ) ) ]
Set Variable [ "$dummy" ; DQ_Push ( $myStack ; "banana" ) ]
Set Variable [ "$dummy" ; DQ_Put ( $myStack ; "cherry" ) ]
Set Variable [ "$myCount" ; DQ_Count ( $myStack ) ] // $myCount = 3
Set Variable [ "$fruit" ; DQ_Pull ( $myStack ) ] // $fruit = "cherry"
Set Variable [ "$fruit" ; DQ_Pop ( $myStack ) ] // $fruit = "banana"
Set Variable [ "$myCount" ; DQ_Count ( $myStack ) ] // $myCount = 1



Bruce Robertson   Bruce Robertson
Mar 28, 2013
Not one of your function definitions is is valid.

For instance you describe a function DQ_New ( initialContents )

But in fact the function definition does not contain a parameter "initialContents"
Stephen Hanna   Stephen Hanna, Cupertino
Mar 28, 2013
All of the functions are valid (at least to FileMaker), although I grant that there is a discrepancy between the names I used for the parameters in the description and the names used in the functions themselves. The parameter names used in the function are arbitrary, as long as they conform to FileMaker variable-naming rules. However, I have changed the name of the parameter in DQ_New() to match the description.
Bruce Robertson   Bruce Robertson
Mar 29, 2013
You should do the same thing (correct the param names) for the other functions.

I also note that trying to use the data viewer to experiment with any of these functions results in a rapid accumulation of new instances of global variables.
Stephen Hanna   Stephen Hanna, Cupertino
Mar 29, 2013
On the comment about global variables: Yes, that's true, because that's how the routines store the data structures. In normal use, you'd create one new structure, and hence one global variable, for each data structure you want to use. You'd then use the other functions (Push and Pop if you want to treat it as a stack, Push and Pull if you want a queue) to manipulate those structures. The idea is that you don't have to know what variables are being created behind the scenes -- just store the name that DQ_New returns to you in your own variable (or field), and pass that to the subsequent routines. [Note, by the way, that there are a total of six routines, only four of which have been posted so far: Pop and Pull are still awaiting approval.]
Darrel   Darrel, Portland
Jun 12, 2018
You list DQ_Pull and DQ_Pop which are a great complement to the set but I don't see them available.
Can you add them to the LIST so that they also can be downloaded?

Log in to post comments.


Note: these functions are not guaranteed or supported by Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 16 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: