Thanks for explaining, I'll change my code accordingly; after all it'll also remain more efficient this way -- rns.
On Sun, Mar 2, 2014 at 3:43 AM, Jeffrey Kegler < [email protected]> wrote: > The original motive here was efficiency. That's taken more-than-usually > seriously in this case, because array descriptors are one of the few > upper-layer features which are mostly about efficiency -- everything they > do could be done as well or better in Perl code, but at a substantial > penalty in efficiency. > > In XS, a reference is a pointer copy (one machine instruction) and > incrementing the SV's reference count. A scalar means a copy of another > scalar, which means creating a new SV, a much more costly operation. > Depending on context, creating an SV is not a huge overhead -- a Perl > script is creating SV's all the time. But here the context is that > avoiding this kind of overhead is *exactly* why array descriptors were > created. > > In addition, with the release not long ago of the CPAN indexed version, > there is now the issue of backward compatibility. > > This makes these scalars, for most purposes, read-only. (Though you could > do your own copy-on-write.) A workaround might be to keep the scalars in > their original state, and add a new field to the array. In this case it > would mean you have "cooked" and "raw" versions of the name. This also > might have other advantages: It's a more functional (fewer side effects) > style of coding, and the "raw" version may even come in handy later. > > Hope this helps, jeffrey > > On 03/01/2014 04:41 PM, Ruslan Shvedov wrote: > > As in script <https://gist.github.com/rns/9299823#file-refs-in-ast-t>, > output<https://gist.github.com/rns/9299823#file-refs-rather-than-scalars-in-ast>. > > > A symbol, e.g. 'bracketed' in one ast node is followed by ${\$VAR1->[0]} > in its place in all ast nodes downwards. > > My use case where I'd appreciated scalars rather than refs in > *ast_symbol_name_to_id* sub below in my > transpiler<https://github.com/rns/MarpaX-Regex/blob/master/t/translation.t>, > this > assignment > > $ast->[0] = "$name/$symbol" > > > changes all downward nodes and the below subs stops working. > > Is it possible that symbol and name descriptors always produce scalars > in AST's? > > # > # convert nodes' symbol, name tuples to id's > # > sub ast_symbol_name_to_id { > my ($ast) = @_; > if (ref $ast){ > my ($name, $symbol, @nodes) = @$ast; > warn "ast_symbol_name_to_id:", "'$name', '$symbol'"; > if ($name eq $symbol){ > $ast->[0] = $name; > } > else{ > $ast->[0] = "$name/$symbol"; > } > splice @$ast, 1, 1; > map { ast_symbol_name_to_id ( $_ ) } @nodes; > } > } > > > > -- > You received this message because you are subscribed to the Google Groups > "marpa parser" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- > You received this message because you are subscribed to the Google Groups > "marpa parser" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "marpa parser" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
