Open sebffischer opened 3 months ago
This would mean, however, that there is an additional indirection because currently the list directly contains Expr
and would then contain Obj::Expr
. we might want to make List
generic.
Yeah - that's certainly one concern I have. Representing ExprList
as List<Obj>
means that we need to do some dispatch on the Obj
enum (or maybe in the future, trait
) even though we know that every element is a Expr
. For something as central as the language AST, this would definitely make it annoying to program around and perhaps come with a small performance hit.
We might be going off on an abstraction detour, but we could also handle List
s as heterogenous Vector
s and ExprList
as another homogeneous Vector<Expr>
to avoid the dispatch and clean up the internal api for working with the AST.
We might be going off on an abstraction detour, but we could also handle
List
s as heterogenousVector
s andExprList
as another homogeneousVector<Expr>
to avoid the dispatch and clean up the internal api for working with the AST.
Yeah, I was already wondering this for the List
, let's see how easy that refactor is.
If we represent List
as Vector<Obj>
, we would thereby also solve https://github.com/dgkf/R/issues/105, so maybe this is the right call.
We might be going off on an abstraction detour, but we could also handle
List
s as heterogenousVector
s andExprList
as another homogeneousVector<Expr>
to avoid the dispatch and clean up the internal api for working with the AST.
Maybe this then also means that we have to refactor Vector
from an enum
to a Vector<T>
generic. Thereby we could then conveniently use Vector<Expr>
for ExprList
and Vector<Obj>
for List
, while still not mixing ExprList
, List
and the other atomic vectors too much in the code base.
If you think this is a good idea, I can give this a try.
@dgkf Before I invest time in this it would be great to get your feedback on whether you would be okay with refactoring the Vector
enum into a generic Vector<T>
. This would mean that the Obj::Vector
variant would become Obj::Character
, ..., Obj::Double
.
I think it would allow us to solve https://github.com/dgkf/R/issues/105#issuecomment-2261845031, which is on the v0.4 milestone
Fundamentally I have no issue with testing it out. I think we should be able to go this route even if we kept the current Obj::Vector(Vector::{Double,Character,..})
as well as Obj::List(List)
where List
is just a type alias for Vector<Obj>
.
I lean toward this style because it will make it easier to differentiate Scalar
and Array
types when we get to those. If there are other benefits, then just be mindful to consider how data with different dimensions should be represented in the Obj
enum.
And just regarding the milestone - I tried to tag things that looked realistic, but regardless of what makes the cut I plan to do the release in the next days. Since I don't think this is a realistic timeframe for this feature, I'm going to bump this one to 0.4.1
As @dgkf suggested in the discussion here: https://github.com/dgkf/R/pull/146, we can replace
ExprList
by just using anObj::List
with expressions.