MathGroup Archive 1992

[Date Index] [Thread Index] [Author Index]

Search the Archive

beauty contest. the winner is...


well,  quite a few people entered the pageant and there was alot to learn
from all of the entries

the rules of the contest were changed a bit to allow for a more general
startlist (deeper nesting) 

startlist = {{a, a, a}, {{{b, b}, {b, b, b}}}, {a}} ;

the consensus was that pattern matching was the best 'flattening' tool. 

in no particular order:  

startlist //. {a___,{b__List},c___} :> {a,b,c}
{{a, a, a}, {b, b}, {b, b, b}, {a}}

Cases[ startlist, {_Symbol..}, -1]
{{a, a, a}, {b, b}, {b, b, b}, {a}}


(#//.{b__List} :> b)&/@startlist
{{a, a, a}, {b, b}, {b, b, b}, {a}}


not alot to say here except that the last program is interesting from the
viewpoint of a functional programming style because it applies Map to a
list and produces a longer list. This is very 'unfunctional' and it arises
because M allows you to change datatypes in the list (a list is changed
into a sequence - as we know, Sequence is an odd duck of an M definition
which is quite useful). 'real' functional programmers, ML, Miranda, Haskell
types (this is a pun), hate this sort of thing since they are into B&D
programming (of course, they also hate side effects so there's no
accounting for taste).

thanks to everyone who participated. it was very educational and of course,
preferable to actually working.









  • Prev by Date: Re:Determinant function in Mathematica
  • Next by Date: Upgrades that aren't (old and new bugs).
  • Previous by thread: Determinant function in Mathematica
  • Next by thread: Upgrades that aren't (old and new bugs).