From: Sergei S. <ser...@ya...> - 2007-03-18 21:15:11
|
--- Eric Wilhelm <scr...@gm...> wrote: > # from Sergei Steshenko > # on Saturday 17 March 2007 07:16 pm: > > >I am not sure I clearly understand what it's about, but why new > > syntax/language to describe hierarchical relationship if Perl already > > supports hierarchical data structures ? > > One word: concisification > > >my $children_array_ref = # or should it be hash ref ? > > No, order matters. > > > [ > > { # first child > > oops, we lost the order now > > > custom_bit => > > { > ... > > text_ctrl => > > { > > type => 'ctrl', > > label => "", # I'm not sure about this > > style => > > { > > te => MULTILINE|READONLY|DONTWRAP > > # these are meant to be bitwise OR'ed constants > > } > > Yeah, but the te => 'string|string|string' means the style() function > can append wxTE_ to the front, so-as to Wx->"wxTE_$thing" it. > > > } > > }, > > > > { # second child > > ... > > } > > ]; > > >Whenever I see another language inside Perl, I'm getting really > > nervous - another (possibly incomplete) definition, another (possibly > > buggy) parser ... > > Nope, no parser. > > >Well, the original example is likely still Perl, but why a subroutine > > where plain hierarchical data structure should suffice ? > > The data structure would basically have to be array refs all the way > down. Also, the style() function does some mapping. The idea was > basically to make a mini-language that would add some unverbosity and > other conveniencification. > > (The Bushism-ated words are jokes. You should laugh now. I'm not > really going to extendify the language like that.) > > A sufficiently expressive data-structure would be good, but it wouldn't > be declarative. The benefit of the declarative bits of code is that > their procedural guts can remove the need for ']]]]]]]]]]'(did I get > enough brackets in there?)-ish stuff. I'm still on the fence about > many details of implementing either or both. > > --Eric > -- > software: a hypothetical exercise which happens to compile. I don't quite understand the ']]]]]]]]]]' part - do you think that nested function calls are any better ? The point of Perl data structures is that is is also (and primarily) code. I.e. suppose you need to write something like this: { ... funky_array => [1, 2, 3, 5, 8 ...], # element is the some of previous two, and this way # 100 times; ... } . So, this is Perl, and there is more than one to do it, and I would do it this way: { ... funky_array => do{ my @tmp_array; # no name clash danger, the scope # protects from name contention my $number_of_times = 100; # I said 100 times, dodn't I ? my $previous_element = 0; my $element = 1; while($number_of_times-- > 0) { $element += $previous_element; push @tmp_array, $element; $previous_element = $element; } \@tmp_array; # the array reference to be returned } }; So, the point of this example is that there should be canonical/normalized data structure and there can be infinite number of ways to produce it. IMO the power of Perl is anonymity - this ensures no name clashes, and the 'do' statement is an anonymous executable/executed code block returning a value (array reference in this case). Define the canonical form and give user freedom to produce it - this is how I'm writing my stuff. ... FWIW, have a look at http://exit1.org/Gtk2-Ex-FormFactory/ - though this is for gtk2-perl, the idea is still OK IMO. Regards, Sergei. Applications From Scratch: http://appsfromscratch.berlios.de/ ____________________________________________________________________________________ Now that's room service! Choose from over 150,000 hotels in 45,000 destinations on Yahoo! Travel to find your fit. http://farechase.yahoo.com/promo-generic-14795097 |