general.hpp File Reference

Plans for Maxima-components regarding abstract data types. More...

Go to the source code of this file.

Detailed Description

Plans for Maxima-components regarding abstract data types.

Create milestones
Iterators and ranges
  • In the Maxima context, it seems that iterators do not refer to memory addresses and the like, and so we can make iterators aware themselves of being dereferencible or not.
  • A forward iterator is a list of length at least one, with the first component either "done" or the index.
  • If the first component is not "done", then we have at least two further components, functions for obtaining the value, and for incrementing an iterator (in place).
  • Example:
    it : [0,lambda([it],it[1]),lambda([it],block([i:it[1]], if i < 10 then it[1]:i+1 else it[1]:done, it))];
    while it[1]#done do (
      it = it[3](it)
  • Some helper functions:
    state(it) := it[1]$
    value(it) := it[2](it)$
    increment(it) := it[3](it)$
    successor(it) := block([nit:copy(it)], increment(nit), nit)$
    decrement(it) := it[4](it)$
    predecessor(it) := block([nit:copy(it)], decrement(nit), nit)$
    advance(it,n) := it[5](it,n)$
    print_range(it) :=
     while state(it)#done do (print(value(it)), increment(it));
    it2list(it) := block([res:[]],
      while state(it)#done do (res:cons(value(it),res), increment(it)),
    it_generator(n) := [
     buildq([n],lambda([it],block([i:it[1]], if i < n then it[1]:i+1 else it[1]:done))),
     lambda([it], it[1]:it[1]-1),
     buildq([n],lambda([it,a],block([i:it[1]+a], if i <= n then it[1]:i else it[1]:done)))
  • If we have four components, then we have a bidirectional iterator, and if we have five components, then we have a random access iterator.
  • All operations on iterators except of state are only defined if the iterator is dereferencible, that is, if the state is not "done".

Definition in file general.hpp.