this post was submitted on 16 Jun 2023
9 points (100.0% liked)

Programming Languages

1159 readers
1 users here now

Hello!

This is the current Lemmy equivalent of https://www.reddit.com/r/ProgrammingLanguages/.

The content and rules are the same here as they are over there. Taken directly from the /r/ProgrammingLanguages overview:

This community is dedicated to the theory, design and implementation of programming languages.

Be nice to each other. Flame wars and rants are not welcomed. Please also put some effort into your post.

This isn't the right place to ask questions such as "What language should I use for X", "what language should I learn", and "what's your favorite language". Such questions should be posted in /c/learn_programming or /c/programming.

This is the right place for posts like the following:

See /r/ProgrammingLanguages for specific examples

Related online communities

founded 1 year ago
MODERATORS
 

As in /r/ProgrammingLanguages, we will have a thread every month where you can post PL-related projects you are working on. Unlike the main posts, this thread is much more lenient: you should post even if you only have minor updates or something tangentially related to programming languages.

How much progress have you made since last time? What new ideas have you stumbled upon, what old ideas have you abandoned? What new projects have you started? What are you working on?

Once again, feel free to share anything you've been working on, old or new, simple or complex, tiny or huge, whether you want to share and discuss it, or simply brag about it - or just about anything you feel like sharing!

The monthly thread is the place for you to engage /c/programming_languages on things that you might not have wanted to put up a post for - progress, ideas, maybe even a slick new chair you built in your garage. Share your projects and thoughts on others' ideas, and most importantly, have a great and productive month!

Also see: https://www.reddit.com/r/ProgrammingLanguages/comments/13x2iv3/june_2023_monthly_what_are_you_working_on_thread/

top 10 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 1 year ago (1 children)

A language designed around the idea of data mutation. Like, just doing data mutation. No functions, no stack, just here's some data and here's how it changes. It's very similar to imperative languages as you might guess, but it basically removes functions from the main data path and simplifies everything which leads to some weird syntax and features.

There are still functions in some ways via a trait system kind of like Rust (also where and polymorphism appears), but it's not quite the same.

I don't really know exactly how to explain it beyond that, so here's a snippet:

[Import]
std

[Data]
a :: Int = 4
b :: Int = 5
a_str :: &Char = []

[Mut]
std.out write "The sum of 4 and 6 is "
b += 1
a += b
a_str alloc_num_str a
std.out write a_str

Not that += here is not equivalent to a = a + b, but rather += is the name of a Numeric trait procedure. Using words I might call it add. It's a add b or with C++-esque syntax it's like (&c)->add(b) or something.

There is a File struct in the std module and a Write trait implemented for &Files that includes a write(&Char) procedure as well as an instance of an &File called "out." So to write a string of characters to stdout, you do std.out write <characters>

So from this, I can say that procedures in traits in this language are like mini versions of the stuff under [Mut] that you can call with parameters. These procedures can also have embedded C code which is how you interact with external stuff and how the core and standard libraries are implemented.

Trait and struct definitions go under [Type] and have their own syntax

Forcing all logic to be an explicit mutation of a singular datum may end up being the worst way to program ever, but it's at least a different way

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

Update: I wrote up a quick manual for the language explaining concepts in more depth and reworking the syntax

[–] [email protected] 1 points 1 year ago (1 children)

Here's a couple example programs.

hello_world.mjut

# Print a simple hello world message
let msg :: &Char = "Hello, world!\n"
mutate:
- stdout write msg

truth_machine.mjut

# Truth machine - if you input a 1, it prints 1 forever
# But a 0, it prints 0 & quits
let inp :: Char = 0
mutate:
- stdin alloc_read_line # Read data into stdin :: &Char
- inp := stdin:0
- inp -= '0'
- if inp - goto quit;
- forever:
    + stdout write "1"
    + goto forever
- quit:
    + stdout write "0"

I think I have it fleshed out enough to get a basic version working. I'll write up a lexer and parser tomorrow (it's after midnight, so actually today lol) probably

[–] [email protected] 2 points 1 year ago (1 children)
[–] [email protected] 1 points 1 year ago

Parser done. Time for Code Generation. I'm going to transpile to C for now

[–] [email protected] 3 points 1 year ago (1 children)

I was trying to create a programming language that doesn't have a parser. It has only AST nodes. The program is edited only inside a special editor.

Nodes in the language are defined as

type Node = ref object
  kind: Node
  childs: seq[Node]
  data: seg[byte]

That is, the node type is literally another node, which allows you to create as many types of nodes as you want without changing the program in any way. Some nodes may be functions.

For example, this is what the "function" and looks like:

note that and contains recursion to itself in the error.
also note that string "false" is just representation of what this constant means, there is no need to create new string "false" every time.

And this is what the "function" x looks like, the use of which can be seen in and:

[–] [email protected] 2 points 1 year ago

You might want to look at Pharo (+ other Smalltalk variants) and Racket. They both have non-text syntax and deep meta-programming "code as data" capabilities. They're also both very unique and a lot different from even each other.

In Pharo and other Smalltalks, everything is an object: not just classes and functions, even the GUI and runtime itself. Code is stored in a persistent "image", opening it in the Pharo IDE is like starting up a VM, and you can modify the environment e.g. to program custom IDE features. See the Wikipedia on Smalltalk and Pharo's "Discover" page.

In Racket and other LISPS, everything is an s-expression, and syntax is "quoted" and manipulated by powerful macros ("code as data"). Racket's macros are powerful enough to add entirely new language features like type systems [2] and object-oriented code, and even entirely new languages with alternate syntax [2]. See "Beautiful Racket". DrRacket also allows you to embed images and "snips" inside of .rkt files (.rkt files are text, but the embedded content will be encoded and usable in DrRacket).

There are other examples too, like MPS (DSL creator whose syntax isn't text) and lambda calculus where everything is a lambda (unnamed function), even numbers. But I think Smalltalk is closest to what you've implemented

[–] [email protected] 2 points 1 year ago

Finally got back to writing my language, Flower. It's going to be slow crawl onwards, but at least I'm back at developing it.

[–] [email protected] 2 points 1 year ago

Currently I'm neck deep in re2c's guts, trying a manual translation to another language for learning purposes. I've found a fair few bugs (and far more ... questionable code) and will file them in bulk once I'm done. Note that some bugs aren't exposed in the command-line tool (or at least common uses thereof).

[–] [email protected] 1 points 1 year ago

The prototype chain in JavaScript (and presumably other prototype-based OOP languages) is really quite similar to the scope chain for local variable lookup: first try to find the property/variable in the current object/scope, and if not found, look in the prototype / parent scope until we reach the outermost object/scope.

I've been thinking for quite a while now about the idea of a language that merges these two concepts into one. I'm not ready to talk about it much yet -- it's still very much in the planning phase, but I'm planning to post about it if and when I make significant progress on it.

load more comments
view more: next ›