whitequark / ast

A library for working with Abstract Syntax Trees.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

each and first

rubydesign opened this issue · comments

I seem to be writing a lot of node.to_a.each
would you accept an each on node?

Similarly, the multi-assignment works well for multiples . Often i have just a single value, so the choice seems to be node.to_a.first or (slightly more expressive) node.children.first
Both of which seem long, so i already have a first function on node, do you want that ?

You can do child, = *node. If this is not in the docs, it should be.

When do you use to_a.each?

hmm, i didn't know you could do that. Frankly looks weird, rather use my first.

each off course to go over children. you're saying i shouldn't have to. And maybe when i switch to the instance variable an your processor i won't. But now i still do and it seemed a sensible thing to have in there.
But i seem to be receiving a more is less attitude , yes ?
Always surprises me in ruby projects, ruby being known for having 7 ways of doing anything, but ok, i get it.

you're saying i shouldn't have to

I'm not. I am specifically asking what your use case is, because I have no idea what is it. I.e. children are usually heterogeneous; what common action over them is desirable?

ok, maybe the question was slightly ill formed then.
Because the answer to your question was so obvious.

If you're asking why i need to iterate. Other than off course, because i have a collection.
To process them.

Like if you have a (list) or a (hash)? Yeah, that's reasonable. I would accept a PR with each.

sort of, i have an s(:expression_list , exp1 , exp2...) which is inside all statements, so common.
But i'll try that Processor with a stack now.
The code i'm talking about is temporarily here btw of almost nothing

So, that processor / instance approach worked.
Quite like it even, so in total the switch to ast has bee great :-)