6.6.1 An append program

Prev Up Next Page 79 of 800 Search internet

Put this in append.lgs:

   ""P append
   ""R base
   ""D 17
   " ++ "
   page ( ""N , ""C )
   title "Append"
   bib "@MISC{dummy}"
   main text "
   \item "[[ value define x ++ y as
             if x atom then y else x head :: x tail ++ y end define ]]"
   \item "[[ etst << 1 ,, 2 >> ++ << 3 >> ; << 1 ,, 2 ,, 3 >> end test ]]"
   appendix "
   \item This space intentionally left blank
   end page

Then compile:

   > lgc append.lgs

Line 4 defines the new construct x ++ y and Line 11 to 12 value defines it such that it can append to lists. Line 13 tests that it can append << 1 ,, 2 >> and << 3 >>. The base page contains macro definitions which make << 1 ,, 2 >> macro expand to 1 :: 2 :: true.

Line 3 assigns charge 17 to the append construct. Charges are the exact opposite of priorities: constructs with high charge has low priority and vice versa.

We assign charge 17 to the append construct which is the same as the charge of the pairing construct x :: y. You can check that by going to the index of the base page, click 'Extract', and go to the charge section.

As an alternative to ""D 17 you can write ""D " :: ". That gives the append construct the same charge as the pair construct without listing the charge explicitly. I prefer using numbers for the sake of readability of the source but use the other way of stating charges as a quick hack when I don't care about readability.

If you need a charge between e.g. charge 17 and 18, you can call it 17.1. If you need one between 17 and 17.1 you can call it 17.1.5, and so on.

The charge of the pair and append constructs is odd. For that reason, they are post-associative. Post-associative constructs are right associative in text that runs left to right, left associative in text that runs right to left, bottom associative in text that runs top to bottom, and clockwise associative in text written in clockwise spirals.

A charge like is odd because the last non-zero value is odd. Trailing zeros are insignificant so charge equals charge 2.4.5.

Line 8 and 15 cite 'dummy' and thereby choke bibtex so it does not whine about missing citations.

Prev Up Next Page 79 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05