Recursive data-types

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 27 04:40:17 PDT 2014


On 27/09/2014 11:26 p.m., ponce wrote:
> I'm dabbling with Scheme interpreter and ultimately I would need to
> declare the following types.
>
> --------------
>
> struct Function
> {
>      Environment env;
>      Atom params;
>      Atom body_;
> }
>
> // An atom is either a string, a double, a symbol, a function or a list
> of atoms
> alias Atom = Algebraic!(string, double, Symbol, Function, This[]);
>
> --------------
>
> These definitions can't work since Function and Atom need each other in
> this recursive definition.
>
> How to get out of this trap?
> Do I have to drop Algebraic and go back to manual tagged unions?

Converting Function to a class. No where near ideal. But it'll work.


More information about the Digitalmars-d-learn mailing list