Al Dente/Examples

From Esolang
(Redirected from Al Dente examples)
Jump to navigation Jump to search
Back to Al Dente

Examples of Al Dente code.

Value conditional example

  BitStream tail;
  zero excludes one; or requires zero or one;
  BitStream inputFirst;
  BitStream inputSecond;
  BitStream output;

  BitStreamConditional tail;

  pickFirst excludes pickSecond; requires pickFirst and or pickSecond and; requires pickFirst and or pickSecond and;

  tail.pickFirst requires pickFirst;
  tail.pickSecond requires pickSecond;
  tail.inputFirst matches inputFirst.tail;
  tail.inputSecond matches inputSecond.tail;
  tail.output matches output.tail;

These classes demonstrate how a choice can be made between two BitStreams. Another class can state that a BitStream matches each of the two input streams of a BitStreamConditional, and also set one or the other (but not both) of pickFirst and pickSecond. The values of pickFirst and pickSecond will cascade down the BitStreamConditional via the requires chains. The elements of the input streams will be immediately mirrored into the BitStreamConditional. The appropriate events will then be copied into output and mirrored in the output stream.

Natural numbers and arithmetic

 Number tail;
 zero excludes succ; or tail.succ requires succ;

 Number in;
 Number out;
 Copier copier;
 copy requires (( and or (in.succ and out.succ)); matches in.tail;
 copier.out matches out.tail;
 copier.copy requires copy;
 copy requires copier.copy or;

 Number in1;
 Number in2;
 Number out;
 Copier copier;
 Copier in2copier;
 Copier outcopier;
 Add next;
 copier.copy matches; matches in2;
 copier.out matches out;
 outcopier.copy matches in1.succ; matches next.out;
 outcopier.out matches out;
 next.in1 matches in1.tail;
 in2copier.copy matches in1.succ; matches in2;
 in2copier.out matches next.in2.tail;

There you have it.

Hopefully multiplication won't be too complicated.