exceeding nr of arguments in a list (or zf-expression)

demast.pjf@hsbrabant.nl demast.pjf@hsbrabant.nl
Thu, 13 Apr 2000 12:41:38 +0200


Thank you for the hints. You solution using arrays is a lot better, but my
students don't know Clean arrays (yet).

> Normally the 32 limit is not a problem, because functions with that
> many arguments are not comprehendible anyway...

I fully agree with this (nr of arguments to a function), but in the
situation of zf-expressions and  the nr of fields in a record the limitation
is sometimes a pitty. When using records you normally select a few fields in
the functions using these records, and although you can use nested records
there are situations where this is unnatural to do.

Paul

> -----Oorspronkelijk bericht-----
> Van: Ronny Wichers Schreur [mailto:ronny@cs.kun.nl]
> Verzonden: donderdag 13 april 2000 11:56
> Aan: Clean Mailing List
> Onderwerp: Re: exceeding nr of arguments in a list (or zf-expression)
>
>
> Hello,
>
> Paul de Mast wrote (to the Clean Mailing List):
>
>  > For solving puzzles zf-expressions are sometimes useful, but the
>  > maximum nr of expressions (generators and filters) is 32 according
>  > to the reference manual.
>  > [..]
>  > Any suggestions why the compiler thinks there are more then 32
>  > expressions?
>
> The essential limit is that in the Clean implementation functions
> (and constructors) can't have more that 32 arguments. Comprehensions
> are transformed to normal functions, and nested comprehensions are
> transformed to nested function.
>
> In your program the deepest generator uses all x's. In the transformed
> program all these x's will be lifted. Consequently the
> function for this
> generator will have 18 (lifted x's) + 19 (generators) = 37 arguments.
>
> Normally the 32 limit is not a problem, because functions with that
> many arguments are not comprehendible anyway (and terribly
> inefficient,
> should you care for that).
>
> It's not difficult to rewrite your program so that it doesn't lift
> all individuel elements of the hexagon. Also you rebuild the list
> of available numbers in every generator, which is not necessary:
>
> --------------------------------------------------------------
> ----------------------
> placements :: Int Hexagon [Int] -> [(Hexagon, [Int])]
> placements position hexagon numbers
> 	=	[	(place number position hexagon,
> removeMember number numbers)
> 		\\	number <- numbers
> 		]
> 	where
> 		place :: Int Int Hexagon -> Hexagon
> 		place number position hexagon
> 			=	{{e \\ e <-: hexagon} &
> [position] = number}
>
> empty_hexagon :: Hexagon
> empty_hexagon
> 	=	{	{undef \\ _ <- [0..19]}
> 		& 	[0] = -1 // [0] is not used (Paul uses
> one based indices)
> 		}
>
> magic_hexagon :: Hexagon
> magic_hexagon
> = hd [ x
> 		\\	(x, l) <- placements 1 empty_hexagon [1..19]
> 		,	(x, l) <- placements 2 x l
> 		,	(x, l) <- placements 3 x l
> 		|	x.[1] + x.[2] + x.[3] == 38
> 		,	(x, l) <- placements 4 x l
> 		,	(x, l) <- placements 8 x l
> 		|	x.[1] + x.[4] + x.[8] == 38
> 		,	(x, l) <- placements 7 x l
> 		,	(x, l) <- placements 12 x l
> 		|	x.[3] + x.[7] + x.[12] == 38
> 		, 	(x, l) <- placements 13 x l
> 		,	(x, l) <- placements 17 x l
> 		|	x.[8] + x.[13] + x.[17] == 38
> 		,	(x, l) <- placements 18 x l
> 		,	(x, l) <- placements 19 x l
> 		|	x.[18] + x.[19] + x.[17] == 38
> 		,	(x, l) <- placements 16 x l
> 		|	x.[16] + x.[19] + x.[12] == 38
> 		,	(x, l) <- placements 11 x l
> 		,	(x, l) <- placements 15 x l
> 		|	x.[7] + x.[11] + x.[15] + x.[18] == 38
> 		,	(x, l) <- placements 5 x l
> 		,	(x, l) <- placements 6 x l
> 		|	x.[4] + x.[5] + x.[6] + x.[7] == 38
> 		&&	x.[2] + x.[6] + x.[11] + x.[16] == 38
> 		,	(x, l) <- placements 9 x l
> 		|	x.[2] + x.[5] + x.[9] + x.[13] == 38
> 		,	(x, l) <- placements 10 x l
> 		|	x.[8] + x.[9] + x.[10] + x.[11] + x.[12] == 38
> 		&&	x.[1] + x.[5] + x.[10] + x.[15] + x.[19] == 38
> 		,	(x, l) <- placements 14 x l
> 		|	x.[13] + x.[14] + x.[15] + x.[16] == 38
> 		&&	x.[3] + x.[6] + x.[10] + x.[14] + x.[17] == 38
> 		&&	x.[4] + x.[9] + x.[14] + x.[18] == 38
> 	]
> --------------------------------------------------------------
> ----------------------
>
> Still quite a long program, but I can't be bothered now to
> generalise it
> for arbitrary hexagons.
>
>
> Cheers,
>
> Ronny Wichers Schreur
>
>