Q-Ref

From Esolang
Jump to navigation Jump to search

Q-Ref is a queue-based language invented by User:Zzo38, with the only data type being queues of references of queues. The variable names must follow the regular expression ([A-Za-z_][A-Za-z_0-9]*).

Commands are: (to use reference dequeued from the queue, prefix with #)

  • A.B -- enqueue reference to B onto A
  • [ commands ] -- loop
  • <labelname> -- define label
  • -labelname -- goto label
  • A? -- exit loop if queue A is empty
  • macroname(parameter) -- call a macro
  • <macroname(code)> -- define macro (use $ to access parameter, % for a unique identifier for this invocation)
  • A+B -- make a copy of B and enqueue the reference to the copy onto A
  • /* comment */ -- comment
  • number -- repeat the next command that number of times (if it comes before a macro, the entire macro is repeated)

Built-in macros for I/O:

  • _outchar -- Output character by number given in parameter
  • _outcharcount -- Output character by number of items in the queue given by parameter
  • _outnumcount -- Output number of items in the queue given by parameter
  • _inchar -- Enqueue a number of references to itself by the input character
  • _innum -- Enqueue a number of references to itself by input number

Example to copy input to output until NULL:

_inchar(x)
[
 x? /* Quit if null */
 _outcharcount(x)
 [ #x? ] /* Empty it */
 _inchar(x) /* Input another character */
]

Example of a cyclic tag machine:

Yes.Yes
/* You must set List to the references of Yes and No */
[
 /* First cycle */
 [ #List?
  List.Yes List.Yes List.No /* Change according to what value you want */
 No? ]
 /* Second cycle */
 [ #List?
  List.No List.Yes /* Change according to what value you want */
 No? ]
]