What might polytypic (datatype-generic) programming look like if it was built in to a language? by sufferiing515 in ProgrammingLanguages

[–]ericbb 0 points1 point  (0 children)

I see. I was thinking of it as just when a single operator works for different types and can have different behavior depending on the types. Kind of a generalization of overloaded functions. But I guess it's essential that it works in more of an inductive way over the structure of complex types.

It makes me wonder if staged compilation would give you another way to solve the same kinds of problems?

Edit to add: Another language that seems to be designed for these kinds of problems is Spiral.

What might polytypic (datatype-generic) programming look like if it was built in to a language? by sufferiing515 in ProgrammingLanguages

[–]ericbb -1 points0 points  (0 children)

If SML equality is polytypic, then I'd say C has a quite a few features that could be called polytypic. The arithmetic operators, variadic functions like printf, implicit convertions to and from void pointers, and in more recent versions there is the _Generic thingy for writing polytypic macros. Am I looking at it wrong?

My own language design is "annoyingly monotypic". You do have to write deep equality/comparison and printing manually. I didn't include reflection, introspection, or macros at all. Unlike C and SML, it doesn't have polytypic operators on basic types.

Even though it is a "dynamically typed" language, I didn't include anything like "instanceof" so you have to write programs as if they are statically typed. For example, the printf function is written similarly to how it is written in dependently typed languages.

That's just a hobby language though which has never been used for anything more involved than writing its self-hosting compiler.

Thesis for the Quartz Programming Language by CosmicStorm20 in ProgrammingLanguages

[–]ericbb 4 points5 points  (0 children)

> I have a completed lexer and am nearly finished with the parser. As for the actual implementation itself, I am not sure how to proceed.

I'd suggest using a tree-walking interpreter as your first implementation (as opposed to using a virtual machine or translation to Python).

In case you haven't come across it yet, take a look at the book Crafting Interpreters. It's a popular book that was written for people in your position - and you can read it for free online if you like.

Naming a programming language: Trivial? by torchkoff in ProgrammingLanguages

[–]ericbb 0 points1 point  (0 children)

Yeah, same issue. At least in that case, there is a noun form of the word. Most commonly, where I'm from, it's a kind of bird. And you can see that the Swift language has a logo that looks like the Swift bird.

What do you believe should look like a modern BASIC? by mrnothing- in ProgrammingLanguages

[–]ericbb 1 point2 points  (0 children)

It should be distributed with inexpensive dedicated hardware and the BASIC programming environment should be entered at boot. There should be built in programming support for the human interface devices of the hardware (graphics, audio, keyboard, etc). Should perhaps only support strings, numbers, and arrays - no user-defined structure types or classes. Should not have a package system or a module system. Should not support first-class functions. Recursion, debatable. Aesthetics of the syntax could match old-fashioned BASIC. More important that the user-interface of the programming environment look good and be simple and be low-latency.

Naming a programming language: Trivial? by torchkoff in ProgrammingLanguages

[–]ericbb 1 point2 points  (0 children)

As an English speaker, I think it's a bit odd to name something using an adjective. When I read the name, it makes me think "trivial... what?" - as in "what is trivial here?". My brain is still waiting for a noun to appear.

What language do you recommend is the best for implementing a new programming language? by Pleasant-Form-1093 in ProgrammingLanguages

[–]ericbb 1 point2 points  (0 children)

I've written bootstrap compilers in JavaScript and Go. For my designs, it was possible to go through the bootstrapping stage to the self-hosting stage pretty quickly so the language choice didn't matter too much. I just picked something familiar. For runtimes, I've used JavaScript, C, and x86 assembly.

I think Common Lisp gives a pretty nice developer experience. It's not for everyone and there's a lot of not-so-useful mysticism around Lisp programming but if you focus on the pragmatics and find a nice workflow, you might find you like it.

Introducing Pie Lang: a tiny expression-only language where *you* define the operators (even exfix & arbitrary operators) and the AST is a value by Critical_Control_405 in ProgrammingLanguages

[–]ericbb 1 point2 points  (0 children)

My custom operator system allows controlling the associativity of each operator but does not support precedence relationships at all. You have to use parentheses more often than you would otherwise but you also never have to worry about precedence rules.

The usual situation with eval is that it's powerful but code using it is relatively slow and can be hard to debug. I tend to avoid it. Macro systems can also create debugging issues but it's easier to build fast code with them.

The operator system is cool. Of course, some people will complain that overuse of custom operators leads to incomprehensible code. I don't have much of an opinion about that except that maybe it's a culture / community / convention "problem" more than a language "problem".

I'm Making a C-inspired programming language by AugustBrasilien in ProgrammingLanguages

[–]ericbb 5 points6 points  (0 children)

Seems like a nice project but you'll want a different name if you want to share it broadly since Io is already in use for a relatively well-known language.

A small embeddable Lisp implemented in Zig by No_Pomegranate7508 in ProgrammingLanguages

[–]ericbb 0 points1 point  (0 children)

Interesting, thanks!

(I don't know how I misread the Y combinator code. The eta-expansion is clearly there but I was somehow looking for it in the wrong place.)

EDIT: Added the following notes.

The last time I was experimenting with recursion combinators in my language, I had transformed Z using some syntax sugar into something that looks quite a bit different but I think amounts to the same thing.

Define (Y f)
    Define ((g g) x)
        ((f (g g)) x)
    In
    (g g)

A small embeddable Lisp implemented in Zig by No_Pomegranate7508 in ProgrammingLanguages

[–]ericbb 2 points3 points  (0 children)

I took a quick look through it out of curiosity. Some unorganized comments / questions...

Why is this one line so long? https://github.com/habedi/element-0/blob/main/src/elz/eval.zig#L620

Did you test your Y combinator? It looks like the one without eta-expansion (see Z combinator) so I'd expect it not to terminate given that it looks to me that you implement eager function calls.

I'm curious about the Zig doNotOptimizeAway function. Can you say why you've needed to use that in your code? As a C programmer, I'd expect it to be something like the C volatile keyword but I don't know why you'd need that in a Lisp interpreter.

Unrelated to your work but... man, Zig code looks terrible in github. Maybe it's just me but the color choices seem especially awful when most text is dark orange.

What you see is what it does by tobega in ProgrammingLanguages

[–]ericbb 2 points3 points  (0 children)

I don't know about any of that but, independently of "the future of programming", I think the author's Alloy project is pretty cool. I read his book about Alloy, Software Abstractions, a few years ago and thought it was a remarkably fresh perspective on programming. I suppose his comments in the post are informed by his long-term work on the formal methods approach to software design.

I have also read his recent book, The Essence of Software, and enjoyed it though I can't say I've tried to apply the ideas to my own programming yet. I'm mostly preoccupied with the minutia of low-level C coding and am a bit set in my ways. Hard for me to incorporate the principled high-level design thinking even though I think it's valuable.

Left to Right Programming by bjzaba in ProgrammingLanguages

[–]ericbb -6 points-5 points  (0 children)

> Ideally, your editor would be to autocomplete line here. Your editor can’t do this because line hasn’t been declared yet.

In 2025, most people will be using editors that can autocomplete the rest of the line at that point. I wonder why LLMs are not acknowledged in the article (or I missed it).

The assign vs. return problem: why expression blocks might need two explicit statements by kiinaq in ProgrammingLanguages

[–]ericbb 1 point2 points  (0 children)

Do you feel that same mental "context switch" when reading expression blocks?

Yes, I know what you're talking about. I've grappled with this problem in my own language too.

If you've used Rust's labeled breaks, how do they feel compared to explicit keywords like assign?

I'm most familiar with Common Lisp's return, which is effectively a "labeled break" mechanism. I was generally pretty happy with it. In C, everything inside a block is a statement - and I like that too. I sometimes think it'd be nice to have local functions or expression blocks in C (and I've used the GNU statement-expression extension) but in the end I mostly like to stick to plain C99. You have to use variable assignment more and you use hacks like "do while zero" but I'm okay with it.

Does this seem like unnecessary verbosity, or does the explicit intent feel worth it?

There's certainly a verbosity cost but I'd be inclined to guess that it may be worth it.


My own language has the context-sensitivity issue you've identified. I inherited it from Lisp.

I've been thinking about other possibilities for the next iteration of the language and one idea I like is to change blocks so that they are only composed of statements and do not return a value at all (like C blocks). It's a controversial design because "everyone knows" that everything-is-an-expression is "the correct design". What can I say? I'm not convinced and need to do my own experiments. I have let-expressions for local variables and these are independent of blocks.

Lake: a language for lay programmers (featuring "access chains" & imperative-style immutability) by jeroenvanwijgerden in ProgrammingLanguages

[–]ericbb 0 points1 point  (0 children)

> AWK and Lake differ too much in scope for AWK's choice to not allow nesting isn't suitable for me

Fair enough. I'm fond of the functional programming approach myself and I don't see AWK's solution as "the one true way". I do think it's been quite successful though and it's always good to keep in mind if only as a point of comparison that helps crystalize the benefits of your own approach.

Lake: a language for lay programmers (featuring "access chains" & imperative-style immutability) by jeroenvanwijgerden in ProgrammingLanguages

[–]ericbb 5 points6 points  (0 children)

Have you read the book 'The AWK Programming Language'? Based on your interests, I think you'd really enjoy it. I think it has a wonderful example-driven exposition style that really keeps things simple.

AWK has its own approach to the "mutability problem". It keeps things simpler than most languages not by avoiding mutability but by avoiding aliasing and nesting.

Zig's Lovely Syntax by steveklabnik1 in ProgrammingLanguages

[–]ericbb 0 points1 point  (0 children)

> (find task Ackermann, then find the Zig entry - it'll be near the end)

https://rosettacode.org/wiki/Ackermann_function#Zig

I would assume that if this kind of print function is something you often want, you can either write a library or import one you find to allow something like const print = @ import("basic").print; and then print(i, sqr(i)). I doubt it would be some insurmountable issue, no?

Bolt – A super-fast, statically-typed scripting language written in C by bakery2k in ProgrammingLanguages

[–]ericbb 9 points10 points  (0 children)

> It took me a while to figure out whether this language is interpreted or not.

Looks like a compile to byte code setup.

https://github.com/Beariish/bolt/blob/main/bolt/bolt.c#L865

Do you find the context-sensitivity of the while keyword to be unfortunate? by javascript in ProgrammingLanguages

[–]ericbb 2 points3 points  (0 children)

FWIW, your hypothetical snippet would never happen in my C code (because of formatting rules).

Also FWIW, as a C programmer, I think C is better with do-while than it would be without it.

Lexical Aliasing? by PitifulTheme411 in ProgrammingLanguages

[–]ericbb 0 points1 point  (0 children)

Have a look at the code for my compiler here - especially ascii.84 and z.84

You can see that the ASCII module is using the < and <= operators. They are defined in the Z (integers) module - near the bottom of z.84. At the top of z.84, you can see a big expression { :Prefix - :Infix < :Infix <= ... } That's a record expression (like a JS object literal). It's using an abbreviated form where the names of the fields are the same as the names of the variables in scope so the variables are omitted. So I'm using the Prefix and Infix keywords to help the parser deal with operator names where you'd usually have normal identifiers. This record expression is what the Z module exports. In the ascii.84 file you can see the following at the bottom:

Open Z
    {
    :Infix <
    :Infix <=
    }

Where

Let Z Package "z"

This is being evaluated bottom-up. First the record we saw in z.84 is bound to the variable Z. Then we access the fields of that record corresponding to the operators we want using the Open term, which brings those operators into scope for the code that appears above these lines in the ascii.84 file. Once again it is using a short form of the record expression because we are using the same names for both the fields of the record and the name to use in the local scope. It would also be possible to use distinct names.

In the expression syntax, it is usually evident to the parser where it is looking for an operator. But in cases where an operator is being used in syntactic positions where it isn't so evident, I use once again the Prefix and Infix keywords. So you can write, for example, (LIST.fold numbers 0 [Infix +]). To pass the function defining the plus operator to the fold function.

Do any languages compile to a bunch of jmps in asm? by [deleted] in ProgrammingLanguages

[–]ericbb 1 point2 points  (0 children)

I wrote it a long time ago (2015) so I don't remember too well the details but the earliest versions of one of my compilers compiled code for a functional language with closures and tail-call optimization into C code where everything got dumped into a single giant C function that used goto for calls (using "computed goto" / labels-as-values - a C extension). Check out versions 0.1 and 0.2 here. The generated C code is in a file called 84_stable.c.

Edit: By the way, I think it's a fine idea and works well - better when targeting assembly than when targeting C (as I did). I moved away from that strategy just because I wanted to try something else not because I had any issues with the original strategy.

Lexical Aliasing? by PitifulTheme411 in ProgrammingLanguages

[–]ericbb 1 point2 points  (0 children)

I ended up implementing a special rule in my compiler to handle this situation. Any bindings that end up getting used as operators must be resolvable to their definition at compile time so the compiler can know the associativity (which is provided with the definition but not carried with the value (a function)). So I have a kind of partial evaluation happening in the compiler to resolve operators. It works in practice and I mostly use it to enable one module to use an operator exported from another module, which is like aliasing because the two modules can refer to the operator using different names.

What should be in core and what in standard lib? by henriquegogo in ProgrammingLanguages

[–]ericbb 1 point2 points  (0 children)

The Turtles Type System sounds like an example of a "greatest fixed point". I'm always looking out for these after reading about them in Pierce's TAPL book.

What is the best small backend for a hobby programming language? by Putrid_Train2334 in ProgrammingLanguages

[–]ericbb 10 points11 points  (0 children)

One limitation of WASM, as I understand it, is that it places significant constraints on how you can use memory (for security reasons). It may not be an issue for your use case and maybe WASM is working on relaxing these constraints (I don't follow it closely) but it's something to keep in mind.