lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Apr 05, 2006, at 14:05, Lisa Parratt wrote:

David Jones wrote:
It's often useful in lexing. The functionality of ungetc will always be needed, and I think that's unavoidable. So if it didn't exist then lots of programs would end up implementing their own version of Standard C IO streams, but with one byte of pushback.

Meh - few excuses that still hold in this day and age for not buffering in memory before processing, imho.

Well, implementing ones own buffering is less-efficient, error prone, and not always simple. How do I decide which bit to buffer? Is my buffer a single array, in which case how do I arrange access to previous bytes (like ungetc) without copying; or is it multiple arrays, in which case how do I provide a natural access to the bytes within it?

In fact I think C is increasingly deployed in smaller and smaller devices. The 8-bit microcontrollers are growing up to a point where they can feasibly implement a reasonable approximation to C. The desktop and server machines are so fast that people are switching away from C and to languages like Python for interactive GUIs.

Personally, if I'm programming for a system that's big enough to implement mmap() (or equivalent) then I probably want to be using Python, not C. Conversely, if I'm using C, I'm not likely to be on a very big system and I probably do want to look after my bytes.

I'm curious as to why you don't like it so much. Is it buggy vendor implementations? Non-portable C code that relied on more than one byte of ungetc? Having to implement a C-like stream interface on top of an abstraction that didn't provide anything like ungetc? Or something else?

All of the above. It also adds a special case when coding implementations - makes the code fugly imho.

So in a world where ungetc didn't exist, do you think the two uses of it in lua would be made any simpler? Because one has to weigh up the ugliness of a support library against the ugliness of applications using that library.

drj