Re: Need Advice: Union or Variant?

2022-11-18 Thread jwatson-CO-edu via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:38:26 UTC, jwatson-CO-edu wrote: Thank you, something similar to what you suggested reduced the atom size from 72 bytes to 40. Oh, based on another forum post I added constructors in addition to reducing the atom size 44%. ```d struct Atom{ F_Type kin

Re: Need Advice: Union or Variant?

2022-11-18 Thread jwatson-CO-edu via Digitalmars-d-learn
On Thursday, 17 November 2022 at 22:49:37 UTC, H. S. Teoh wrote: Just create a nested anonymous struct, like this: struct Atom { F_Type kind; union { // anonymous union struct { Atom* car; /

Re: Need Advice: Union or Variant?

2022-11-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 17, 2022 at 10:16:04PM +, jwatson-CO-edu via Digitalmars-d-learn wrote: > On Thursday, 17 November 2022 at 21:05:43 UTC, H. S. Teoh wrote: [...] > > struct Atom { > > F_Type kind; > > union { // anonymous union > > Atom* car

Re: Need Advice: Union or Variant?

2022-11-17 Thread jwatson-CO-edu via Digitalmars-d-learn
On Thursday, 17 November 2022 at 21:19:56 UTC, Petar Kirov [ZombineDev] wrote: On Thursday, 17 November 2022 at 20:54:46 UTC, jwatson-CO-edu wrote: I have an implementation of the "[Little Scheme](https://mitpress.mit.edu/9780262560993/the-little-schemer/)" educational programming language writt

Re: Need Advice: Union or Variant?

2022-11-17 Thread jwatson-CO-edu via Digitalmars-d-learn
On Thursday, 17 November 2022 at 21:05:43 UTC, H. S. Teoh wrote: Question: **Where do I begin my consolidation of space within `Atom`? Do I use unions or variants?** In this case, since you're already keeping track of what type of data is being stored in an Atom, use a union: stru

Re: Need Advice: Union or Variant?

2022-11-17 Thread Petar via Digitalmars-d-learn
On Thursday, 17 November 2022 at 20:54:46 UTC, jwatson-CO-edu wrote: I have an implementation of the "[Little Scheme](https://mitpress.mit.edu/9780262560993/the-little-schemer/)" educational programming language written in D, [here](https://github.com/jwatson-CO-edu/SPARROW)". It has many probl

Re: Need Advice: Union or Variant?

2022-11-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 17, 2022 at 08:54:46PM +, jwatson-CO-edu via Digitalmars-d-learn wrote: [...] > ```d > enum F_Type{ > CONS, // Cons pair > STRN, // String/Symbol > NMBR, // Number > EROR, // Error object > BOOL, // Boolean value > FUNC, // Function > } > > struct Atom{ >

Need Advice: Union or Variant?

2022-11-17 Thread jwatson-CO-edu via Digitalmars-d-learn
I have an implementation of the "[Little Scheme](https://mitpress.mit.edu/9780262560993/the-little-schemer/)" educational programming language written in D, [here](https://github.com/jwatson-CO-edu/SPARROW)". It has many problems, but the one I want to solve first is the size of the "atoms" (un