count.txt -- functions involving natural number counting and indexing uses: natnum.ax -- natural number arithmetic ... The following counting functions are defined in this file: length -- length of a sequence const_seq -- create sequence of n copies of an expression select -- select ith value of sequence replace -- replace ith value delete -- delete ith value insert -- insert value before ith position select_prefix -- select prefix of length n select_suffix -- select suffix of length n replace_prefix -- replace prefix of length n replace_suffix -- replace suffix of length n delete_prefix -- delete prefix of length n delete_suffix -- delete suffix of length n select_substr -- (prefix length, substring length) select_substr_ij -- (prefix length, total length) replace_substr, replace_substr_ij delete_substr, delete_substr_ij insert_substr -- insert substring at ith position *** to be done: for, for* -- "for loop" functional forms Note that we number sequence elements starting at zero. length -- length of a sequence (length () %0)< (zero %0). (length (% $) %n+1)< (length ($) %n), (succ %n %n+1). const_seq -- sequence of n copies of an expression (const_seq %0 % ())< (zero %0). (const_seq %n+1 % (% $))< (const_seq %n % ($)). (succ %n %n+1), ! better definition: (const_seq %n % %seq)< (zero_or_more % %seq), (length %seq %n). select the ith value of a sequence (numbering from 0): (select %i ($i % $) %)< ! order of arguments? (length ($i) %i). replace the ith value of a sequence: (replace %i ($i % $) %x ($i %x $))< (length ($i) %i). delete the ith value of a sequence: (delete %i ($i % $) ($i $))< (length ($i) %i). insert value before the ith value: (insert %i ($i $) %x ($i %x $))< (length ($i) %i). select prefix of length n: (select_prefix %n ($n $) ($n))< (length ($n) %n). select suffix of length n: (select_suffix %n ($ $n) ($n))< (length ($n) %n). -- also get suffix/prefix after removing prefix/suffix of length n replace prefix of length n: (replace_prefix %n ($n $) ($x) ($x $))< (length ($n) %n). ! -- note that replacement string need not be of length n replace suffix of length n: (replace_suffix %n ($ $n) ($x) ($ $x))< (length ($n) %n). delete prefix/suffix of length n: (delete_prefix %n ($n $) ($))< (length ($n) %n). (delete_suffix %n ($ $n) ($))< (length ($n) %n). select substring of length n starting at position i: (select_substr %i %n ($i $n $) ($n))< (length ($i) %i), (length ($n) %n). ! Another version: ! Instead of the length n of the substring n, ! could give the position j following the substring: (select_substr_ij %i %j ($i $n $) ($n))< (length ($i) %i), (length ($i $n) %j). replace substring of length n starting at position i: (replace_substr %i %n ($i $n $) ($x) ($i $x $))< (length ($i) %i), (length ($n) %n). (replace_substr_ij %i %j ($i $n $) ($x) ($i $x $))< (length ($i) %i), (length ($i $n) %j). delete substring of length n starting at position i: (delete_substr %i %n ($i $n $) ($i $))< (length ($i) %i), (length ($n) %n). (delete_substr_ij %i %j ($i $n $) ($i $))< (length ($i) %i), (length ($i $n) %j). insert substring at position i: (insert_substr %i ($i $) ($x) ($i $x $))< (length ($i) %i). *** Could also measure lengths from the end of the sequence. Or could use negative numbers as indices from the end of the sequence? -- probably not -- better to stick with pure natural numbers here! *** to be done -- decimal index in symbol! (2nd_elem <2nd_elem>) -- get 2nd elem from seq (as head gets 1st) (3rd_elem <3rd_elem>) etc. -- let syntax support arbitrary number here (do we count from 0 or 1?!) (prefix_of_x_elems ), x is a const (groups_of_x_elems ) -- a partitioning of a sequence into structure membership tests: (null_seq ()) -- arg is null seq (1expr_seq (%)) -- arg is seq with 1 expr (2expr_seq (%1 %2)) -- ... etc. -- let syntax convert fn name into expr with natural number??? (same_expr_seq (% ... %)) -- 0 or more occurrences of same expr (closure % (% ... %)) -- seq of 0 or more of a particular expr (1expr_seq % (%)) -- same expr (2expr_seq % (% %)) etc. The "for" loop functional form is defined as follows: -- need to make form of %func more generic (for %n %func %const %input %output), ! 0..n-1 iterations (for* () %n %func %const %input %output); (for* %i %j %func %const %input %output), ! iterate for i..j-1 (< %i %j), (%func %i %const %input %x), (succ %i %i+1), (for* %i+1 %j %func %const %x %output); (for* %i %i %func %const %x %x); dummy function to test "for" loop functional form: !x (dummy_insert %i %const ($) ((%i %const) $));