Thread overview
"Little Scheme" and PL Design (Code Critique?)
Nov 17, 2022
jwatson-CO-edu
Nov 19, 2022
Jack Pope
Nov 20, 2022
jwatson-CO-edu
Nov 21, 2022
Paul Backus
Nov 25, 2022
jwatson-CO-edu
Nov 22, 2022
JG
Nov 25, 2022
jwatson-CO-edu
November 17, 2022

I just pushed a D implementation of "Little Scheme", which is a limited educational version of Scheme, to GitHub.

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 (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 or a free list 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
  2. Math and Inequality Primitives
  3. Lists and Structures
  4. Lexer
  5. Parser
  6. Environment / Variables
  7. Primitive Functions
  8. Control Flow
  9. Evaluator
  10. REPL

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.
November 19, 2022

On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu wrote:

>

Atom (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 or a free list 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.

November 20, 2022

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 (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.

November 21, 2022

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 and std.process provide platform-independent interfaces for this that should work on both Windows and Linux.

November 22, 2022

On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu wrote:

>

I just pushed a D implementation of "Little Scheme", which is a limited educational version of Scheme, to GitHub.

[...]

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.

November 25, 2022

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 and std.process provide platform-independent interfaces for this that should work on both Windows and Linux.

Splendid! High praise to the contributors that were able to do this on multiple platforms!

November 25, 2022

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", which is a limited educational version of Scheme, to GitHub.

[...]

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.