Re: Schwartzian Transform
Adam Turoff wrote: This message is not an RFC, nor is it an intent to add a feature to Perl or specify a syntax for that feature[*]. Yay. We're all for making easy things easy, but the complexities of "map {} sort {} map {} @list" has always been befuddling to newbies, especially when reading the code left-to-right. So you think @s = map { $_-[0] } sort { $a-[1] = $b-[1] } map { [ $_, /num:(\d+)/ ] } @t; would be more clearly written as @s = schwartzian( { second_map = sub { $_-[0] }, the_sort= sub { $a-[1] = $b-[1] }, first_map = sub { [ $_, /num:(\d+)/ ] }, }, @t ); ??? I guess that would allow reordering the functions: @s = schwartzian( { first_map = sub { [ $_, /num:(\d+)/ ] }, the_sort= sub { $a-[1] = $b-[1] }, second_map = sub { $_-[0] }, }, @t ); Is that really an improvement? Every programmer understands right-to-left data flow when it's written with parentheses. Perl novices just need to understand that map { } sort { } map { } @ is a mere syntactic rewrite of map( , sort( , map( , @ ) ) ) -- John Porter Useless use of time in void context.
Re: Schwartzian Transform
"JP" == John Porter [EMAIL PROTECTED] writes: JP Is that really an improvement? JP Every programmer understands right-to-left data flow when it's JP written with parentheses. Perl novices just need to understand JP that JP map { } sort { } map { } @ JP is a mere syntactic rewrite of JP map( , sort( , map( , @ ) ) ) well, if anyone is so inclined, they can take over my Sort::Records module which is gathering major dust. it could be a standard module in perl6 and help out lots of people. its goal was/is to have the code describe the sort fields in any complex data tree or string. the module generates the perl code to extract the fields into a GRT makes a sub out of that. then you can pass that object lists of records and then do a sort. you can print out the generated code too for cutting and pasting. the sort object is reusable with other lists of data. input records can be strings, or any perl [LH]o[LH]. actual sort keys have to be scalars and they can be extracted via m// or substr or even custom callback code. so this eliminates the need to explicitly use map/sort/map and does all the key extraction and record management. no need to figure out the code for a schwartz (drop the 'ian') or GR transform. the basic design and coding was done but not finished. it got code reviewed and than i shelved it. any interest? i would help out but i can't drive the project now. uri -- Uri Guttman - [EMAIL PROTECTED] -- http://www.sysarch.com SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting The Perl Books Page --- http://www.sysarch.com/cgi-bin/perl_books The Best Search Engine on the Net -- http://www.northernlight.com
Re: Schwartzian Transform
On Tue, Mar 20, 2001 at 11:15:51PM -0500, John Porter wrote: @s = schwartzian( { second_map = sub { $_-[0] }, the_sort= sub { $a-[1] = $b-[1] }, first_map = sub { [ $_, /num:(\d+)/ ] }, }, @t ); Hm. I'd rather see: schwartzian({/num:(\d+)/}, {^_=^_}, @t), and have perl figure out how to do the forward and backword mappings. Hmm, I don't see why you couldn't write that right now. (Other then synthatical shugar -- currying and getting rid of the need for "sub {}"s.) Indeed, map $_-[0], sort {$sort($a-[1], $b-[1])} map [$_, $attrib($_)], @list; does what I intendeded. (Where ex $sort = sub {$_[0] cmp $_[1]}, and $attrib = sub {lc $_}.) (Of course, this doesn't always use the optimal form.) -=- James Mastros -- The most beautiful thing we can experience is the mysterious. It is the source of all true art and science. He to whom this emotion is a stranger, who can no longer pause to wonder and stand wrapt in awe, is as good as dead. -=- Albert Einstein AIM: theorbtwo homepage: http://www.rtweb.net/theorb/