www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - "Little Scheme" and PL Design (Code Critique?)

reply jwatson-CO-edu <real.name colorado.edu> writes:
I just pushed a D implementation of "[Little 
Scheme](https://mitpress.mit.edu/9780262560993/the-little-schemer/)", which is
a limited educational version of
[Scheme](https://en.wikipedia.org/wiki/Scheme_(programming_language)), to
[GitHub](https://github.com/jwatson-CO-edu/SPARROW).

_Here I would like to discuss aspects of programming language 
design from a novice's perspective, including D-specific aspects, 
rather than try to get forum members to comb through 1500 lines 
of code._

**Problems / Topics**:
* Whenever I create an 
[`Atom`](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L66)
(unit of data), I throw it on the heap and never bother to delete it.  I
understand that D does GC for me. I am interested in using either [timed
GC](https://wiki.dlang.org/Memory_Management#Smooth_Operation) or a [free
list](https://wiki.dlang.org/Memory_Management#Free_Lists) for finer control of
GC.  Which is best for the application, do you think?

* Compatibility with both Windows and Linux. What do I need to 
consider?
   - Can I create threads/processes under Windows?

* PL Authors: Please share what you wish you knew when staring 
your programming/scripting language.

* I am open to questions/critiques.



**Components**:
1. 
[Data](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L43)
1. [Math and Inequality 
Primitives](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L231)
1. [Lists and 
Structures](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L348)
1. 
[Lexer](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L443)
1. 
[Parser](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L630)
1. [Environment / 
Variables](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L443)
1. [Primitive 
Functions](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L630)
1. [Control 
Flow](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L1006)
1. 
[Evaluator](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L1127)
1. 
[REPL](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L1462)

**Notes**:
* The repo is called SPARROW because I want to transform Little 
Scheme into my own language through small changes as a way to 
teach myself PL design.
* SPARROW is not a topic of research.  I do not have an 
application in mind other than learning as a side hobby.
Nov 17 2022
next sibling parent reply Jack Pope <zedlan invec.net> writes:
On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu 
wrote:
 [`Atom`](https://github.com/jwatson-CO-edu/SPARROW/blob/mai
/lil_schemer.d#L66) (unit of data), I throw it on the heap and never bother to
delete it.  I understand that D does GC for me. I am interested in using either
[timed GC](https://wiki.dlang.org/Memory_Management#Smooth_Operation) or a
[free list](https://wiki.dlang.org/Memory_Management#Free_Lists) for finer
control of GC.  Which is best for the application, do you think?
If you wish to automatically de-allocate the oldest atoms, one approach might be to put them in a ring buffer. Its size will affect the relative time needed for deleting and overwriting the oldest elements. You can hard code the size based on experimentation or allow ongoing automatic adjustment based on some formula. I think there are some interesting ring buffer packages in the DUB registry.
Nov 19 2022
parent jwatson-CO-edu <real.name colorado.edu> writes:
On Saturday, 19 November 2022 at 19:16:41 UTC, Jack Pope wrote:
 On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu 
 wrote:
 [`Atom`](https://github.com/jwatson-CO-edu/SPARROW/blob/mai
/lil_schemer.d#L66) (unit of data), I throw it on the heap and never bother to
delete it.  [...]
If you wish to automatically de-allocate the oldest atoms, one approach might be to put them in a ring buffer. Its size will affect the relative time needed for deleting and overwriting the oldest elements. You can hard code the size based on experimentation or allow ongoing automatic adjustment based on some formula. I think there are some interesting ring buffer packages in the DUB registry.
Thank you, but I do not think the atoms will be freed in order, especially those holding user-defined functions. A ring buffer would be more appropriate for processing items in a stream or for otherwise implementing a queue.
Nov 20 2022
prev sibling next sibling parent reply Paul Backus <snarwin gmail.com> writes:
On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu 
wrote:
 * Compatibility with both Windows and Linux. What do I need to 
 consider?
   - Can I create threads/processes under Windows?
[core.thread][1] and [std.process][2] provide platform-independent interfaces for this that should work on both Windows and Linux. [1]: https://druntime.dpldocs.info/core.thread.html [2]: https://phobos.dpldocs.info/std.process.html
Nov 21 2022
parent jwatson-CO-edu <real.name colorado.edu> writes:
On Monday, 21 November 2022 at 14:36:43 UTC, Paul Backus wrote:
 On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu 
 wrote:
 * Compatibility with both Windows and Linux. What do I need to 
 consider?
   - Can I create threads/processes under Windows?
[core.thread][1] and [std.process][2] provide platform-independent interfaces for this that should work on both Windows and Linux. [1]: https://druntime.dpldocs.info/core.thread.html [2]: https://phobos.dpldocs.info/std.process.html
Splendid! High praise to the contributors that were able to do this on multiple platforms!
Nov 25 2022
prev sibling parent reply JG <someone somewhere.com> writes:
On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu 
wrote:
 I just pushed a D implementation of "[Little 
 Scheme](https://mitpress.mit.edu/9780262560993/the-little-schemer/)", which is
a limited educational version of
[Scheme](https://en.wikipedia.org/wiki/Scheme_(programming_language)), to
[GitHub](https://github.com/jwatson-CO-edu/SPARROW).

 [...]
I think using the d garbage collector is a good idea. (I have written two implementations of scheme like languages one in c and one in d, and I found it a great pleasure not to have to write a GC for the d one). On the other hand if you want to write one there is no obstruction doing so in d.
Nov 22 2022
parent jwatson-CO-edu <real.name colorado.edu> writes:
On Tuesday, 22 November 2022 at 08:19:44 UTC, JG wrote:
 On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu 
 wrote:
 I just pushed a D implementation of "[Little 
 Scheme](https://mitpress.mit.edu/9780262560993/the-little-schemer/)", which is
a limited educational version of
[Scheme](https://en.wikipedia.org/wiki/Scheme_(programming_language)), to
[GitHub](https://github.com/jwatson-CO-edu/SPARROW).

 [...]
I think using the d garbage collector is a good idea. (I have written two implementations of scheme like languages one in c and one in d, and I found it a great pleasure not to have to write a GC for the d one). On the other hand if you want to write one there is no obstruction doing so in d.
Have you put your Schemes up on GitHub? What are the biggest lessons you learned from writing them? Yes, allowing D GC to do its thing is my course for the time being. In the near future I want to test starting the interpreter with a block of variable memory allocated to see if this reduces cache misses at runtime. The results of this test will determine if, and the degree to which, I will fiddle with GC.
Nov 25 2022