Live data from Hacker News

Writing Your Own Programming Language

github.com

81–90 of 95 posts

Re: Writing Your Own Programming Language

#81

Earlier quoted context omitted.

... reading sexp's is technically parsing but it is so far removed from something like a C parser that it's really not the same animal. I mean, you can write a function to build a list from a sexp in a few minutes, while even a basic hand-written C parser will take days/weeks/months depending on your familiarity. So, that's a reason why it is said. (edit: also, if the course implements scheme IN scheme, then you don'…

> ... reading sexp's is technically parsing but it is so far removed from something like a C parser that it's really not the same animal. Yeah it is obviously a lot easier to parse than traditional, imperative languages like C. I just do not like the phrase, as it gives this "magic" vibe to Scheme. I mean its syntax is beautiful and simple, but there is definitely no magic there.

McCarthy's basic evaluator for LISP in a page or two in a high-level language (esp LISP). That's not magic but good design gets plenty close. ;)

Re: Writing Your Own Programming Language

#82

Peter Norvig's "(How to Write a (Lisp) Interpreter (in Python))" ( http://norvig.com/lispy.html ) covers a superset of this material and makes more sense, and actually has a portable implementation you can run yourself. If you're going to do this, use Norvig as a guide.

Thanks for the link! One nice thing about the original post is that it runs inside of a Swift playground, which, for those with Xcode (or an iPad) can be a fast way of learning and experimenting. I could see someone starting with this project and then easily expanding their knowledge by modifying it using resources like the one you linked to.

Re: Writing Your Own Programming Language

#83
post #41

Earlier quoted context omitted.

But most compilers have a parser. Scheme doesn't need one ;) http://calculist.org/blog/2012/04/17/homoiconicity-isnt-the-...

Why is it so often stated, that Scheme doesn't need a parser? I mean the AST is simpler then in other languages, but at the end of the day, you have to parse SEXPs, don't you? I mean let's say you evaluate > (+ 2 3) You have to parse the string "(+ 2 3)" and will then evaluate it to 5?

"It's easy to parse scheme" is one of those pretty stories that is often repeated but untrue. A similar one is "it's easy to implement scheme in scheme".

It is true for toy compilers of language subsets, and those are often done. And few people ever explore real scheme compiler internals.

The readers in real scheme compilers are generally a large pile of ugly code. A decade or so ago, I recall Bigloo's was the cleanest I'd found, with a regular expression based parser framework. I can't quickly find the files to link. But after wading through many other implementations, it was a breath of fresh air. But not simple, and not small.

Here's a quick quote from a Chicken changelog: "2.7 Fix several bugs (expt, integer?, rational?, =, eqv?, -) found by importing the number tests from Gauche and writing an extensive test for number syntax edge cases. Complete rewrite of number parser (it should fully conform to the R7RS superset of R5RS number syntax now)."

Re: Writing Your Own Programming Language

#84
post #55

Earlier quoted context omitted.

When I think about writing my own language, I think of something with as few parenthesis as possible and all the examples use Lisp.

You can make the LISP do something other than parenthesis. An early example was Dylan language. You can also use LISP to power the compiler as both intermediate and executable language like Julia did. Outwardly, it's a powerful, pleasant language many people would like. On inside, its power came from that fact that the syntax was immediately translated to & manipulated in femtolisp. My favorite use of LISP to bootstr…

Re: early example, CGOL was two decades before Dylan.

https://en.wikipedia.org/wiki/CGOL

Re: Writing Your Own Programming Language

#85
post #17
post #3

Honest question: why do tutorials in this topic seem to always use functional languages/syntax as examples? Our compilers class at MST had us re-implement a lisp compiler, but didn't touch on why we used lisp specifically (other than the professor liking it; we were a largely C++ school). Do they think functional languages are simpler / less complex / easier to understand? Is there something inherently easier to impl…

I can probably answer the LISP question; the Core LISP Languages is incredibly simple. It has only 8 or so keywords you really need and 5 syntax forms (probably wrong, I don'T have the exact numbers in my head) It comes with very few special forms and makes no difference between a variable, function or macro. Everything is same-y.

Yeah, if you ignore the reader, garbage collector, hash table implementation, vectors, object system, stack unwinding, representation of closures, etc, etc. all you're left with is a handful of special forms. Unicode support? Why, practically just a footnote; leave that to the summer students.

Re: Writing Your Own Programming Language

#86
post #17

Earlier quoted context omitted.

I can probably answer the LISP question; the Core LISP Languages is incredibly simple. It has only 8 or so keywords you really need and 5 syntax forms (probably wrong, I don'T have the exact numbers in my head) It comes with very few special forms and makes no difference between a variable, function or macro. Everything is same-y.

Yeah, if you ignore the reader, garbage collector, hash table implementation, vectors, object system, stack unwinding, representation of closures, etc, etc. all you're left with is a handful of special forms. Unicode support? Why, practically just a footnote; leave that to the summer students.

>Reader

Not quite sure what you mean there. If you are talking about the Lexer, it's also rather simple since LISP doesn't need lookahead. Everything is in prefix notation.

>Garbage Collector

Which can be incredibly simple since you only have the persistent global scope and the list local scope, so you only discard data that goes out of scope. There are no references

Heck, you could probably just write the Garbage Collector in LISP too.

>Hash Table

LISP-family languages usually aren't called LISP for being Hash Table Processors. There are only lists.

>Vectors, Object System, Stack Unwinding, Closures

Not needed either, you can macro Vectors, you can macro the Object System, you have lists, not a stack and closures are a basic property of the language last I checked.

>Unicode

---------

LISP is a rather simple language since you can write a macro for almost everything, a minimal implementation only needs a couple keywords. Object Systems are usually implemented via macros.

It is special because after implementing a minimal set, you can program the language itself to provide the rest.

And I'd like you to name another language that is not assembler or original BASIC where you would not have to implement all this stuff while remaining as simple and expressive as LISP.

I don't think you really need any of this complicated 1960s and later stuff. LISP is the second oldest programming language, it's really not complex.

Re: Writing Your Own Programming Language

#87
post #86

Earlier quoted context omitted.

Yeah, if you ignore the reader, garbage collector, hash table implementation, vectors, object system, stack unwinding, representation of closures, etc, etc. all you're left with is a handful of special forms. Unicode support? Why, practically just a footnote; leave that to the summer students.

>Reader Not quite sure what you mean there. If you are talking about the Lexer, it's also rather simple since LISP doesn't need lookahead. Everything is in prefix notation. >Garbage Collector Which can be incredibly simple since you only have the persistent global scope and the list local scope, so you only discard data that goes out of scope. There are no references Heck, you could probably just write the Garbage Co…

> Not quite sure what you mean there.

The Reader is the thing which reads the many Lisp data structures: lists, symbols, floats, integers, strings, characters, vectors, arrays, structures, ...

> Which can be incredibly simple since you only have the persistent global scope and the list local scope, so you only discard data that goes out of scope. There are no references

Lisp has references.

> Heck, you could probably just write the Garbage Collector in LISP too.

Basically you can't.

> LISP-family languages usually aren't called LISP for being Hash Table Processors. There are only lists.

All Lisp have hash-tables since decades. Internally the symbol table is a hash-table in most Lisp implementations.

> Not needed either, you can macro Vectors, you can macro the Object System, you have lists, not a stack and closures are a basic property of the language last I checked.

You can't. You don't see to know what a macro is. If you only have linked lists, you can't make vectors. No macro will help you with that.

> Object Systems are usually implemented via macros.

They aren't. Object systems are a mix of new data structures, functions and some macros. In Common Lisp, the CLOS system is a layering of data structures, functions and only at the top are macros. Parts of CLOS then are defined in itself.

> It is special because after implementing a minimal set, you can program the language itself to provide the rest.

But it is not done that way. You won't implement arithmetic as a macro.

> while remaining as simple and expressive as LISP.

Once you have all that, Lisp is no longer simple.

> LISP is the second oldest programming language, it's really not complex.

Check the recent Scheme standard for some entertainment.

Re: Writing Your Own Programming Language

#88
post #87
post #86

Earlier quoted context omitted.

>Reader Not quite sure what you mean there. If you are talking about the Lexer, it's also rather simple since LISP doesn't need lookahead. Everything is in prefix notation. >Garbage Collector Which can be incredibly simple since you only have the persistent global scope and the list local scope, so you only discard data that goes out of scope. There are no references Heck, you could probably just write the Garbage Co…

> Not quite sure what you mean there. The Reader is the thing which reads the many Lisp data structures: lists, symbols, floats, integers, strings, characters, vectors, arrays, structures, ... > Which can be incredibly simple since you only have the persistent global scope and the list local scope, so you only discard data that goes out of scope. There are no references Lisp has references. > Heck, you could probably…

I think you're completely failing to understand my point.

https://stackoverflow.com/questions/3482389/how-many-primiti...

You only need about 9 primitives and can build the rest from there.

You can implement arithmetic as macros and functions, from scratch.

>Internally the symbol table is a hash-table in most Lisp implementations.

Point me at a language that won't require a symbol table that is not assembler.

Really do it.

Point me at a language that is simpler to implement than LISP and is not assembler. (and maybe not brainfuck)

>If you only have linked lists, you can't make vectors.

If you have a turing complete language, you can do everything. I don't think you know what a turing-complete language is.

>In Common Lisp, the CLOS system is a layering of data structures, functions and only at the top are macros. Parts of CLOS then are defined in itself.

How nitpicky.

>Lisp is no longer simple.

Compared to most other popular languages, it is.

Re: Writing Your Own Programming Language

#89
I took a university course where we built an interpreter for MicroScheme. It was a difficult project but was also really awesome and rewarding. I'd like to go back and do it again without deadlines to really understand it better. I think functional programming languages can be a great choice for implementing an interpreter since metaprogramming is their forte and Racket's match function helped a lot, it's like the most powerful thing I've ever seen[1]

[1] https://docs.racket-lang.org/reference/match.html

Re: Writing Your Own Programming Language

#90

Earlier quoted context omitted.

You can make the LISP do something other than parenthesis. An early example was Dylan language. You can also use LISP to power the compiler as both intermediate and executable language like Julia did. Outwardly, it's a powerful, pleasant language many people would like. On inside, its power came from that fact that the syntax was immediately translated to & manipulated in femtolisp. My favorite use of LISP to bootstr…

Re: early example, CGOL was two decades before Dylan. https://en.wikipedia.org/wiki/CGOL

It's a little weird in syntax but definitely an improvement in the side-by-side examples. Thanks for telling me about it.
Post reply on HN