Skip to content

Commit

Permalink
Update example with new tuple syntax [av skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Lycken committed Apr 20, 2015
1 parent dee97f8 commit 331a156
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions doc/manual/metaprogramming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1037,11 +1037,11 @@ possible implementation is the following::

The same thing can be done using recursion::

sub2ind_rec(dims::()) = 1
sub2ind_rec(dims::(),i1::Integer, I::Integer...) =
sub2ind_rec(dims::Tuple{}) = 1
sub2ind_rec(dims::Tuple{},i1::Integer, I::Integer...) =
i1==1 ? sub2ind_rec(dims,I...) : throw(BoundsError())
sub2ind_rec(dims::(Integer,Integer...), i1::Integer) = i1
sub2ind_rec(dims::(Integer,Integer...), i1::Integer, I::Integer...) =
sub2ind_rec(dims::Tuple{Integer,Vararg{Integer}}, i1::Integer) = i1
sub2ind_rec(dims::Tuple{Integer,Vararg{Integer}}, i1::Integer, I::Integer...) =
i1 + dims[1]*(sub2ind_rec(tail(dims),I...)-1)

Both these implementations, although different, do essentially the same
Expand Down

0 comments on commit 331a156

Please sign in to comment.