munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.75k stars 1.03k forks source link

Request, could you cover basic input from the user? #977

Closed PaperPrototype closed 3 years ago

PaperPrototype commented 3 years ago

Or at least some pointers to as to how to implement it? Or mayeb some external resources that we can look at :)

It would make the book very useful, because aside from making a cool language, we could actually make something useful.

I'm not saying the book is bad, it's just I can't see how not adding input is a good idea (aside from making the book shorter.

I mean, your book is a great starting point, but I want to make something... real.

nocturn9x commented 3 years ago

Just add a native function that reads from stdin within your language of choice? Unless you wanna reinvent the wheel and interact with very low level (not to mention platform specific) kernel-mode APIs

You can check my (quite bad actually) implementation of clox in Nim here (check out natReadLine inside src/stdlib.nim)

Cheers!

munificent commented 3 years ago

Just add a native function that reads from stdin within your language of choice?

This is the answer. There's really nothing technically interesting about adding support for user input, which is why I omitted it from the book. All you need is a native function like input() that reads from stdin and returns the result.

PaperPrototype commented 3 years ago

@munificent If its so simple why exclude it from the book :P

PaperPrototype commented 3 years ago

@nocturn9x Thanks!

nocturn9x commented 3 years ago

@munificent If its so simple why exclude it from the book :P

As bob mentioned, there's nothing special about doing that. No design challenge, no interesting coding technique, it's just literally a function that reads from standard input