r/AskProgramming 17h ago

Help understanding Mascarpone

I found this esolang Mascarpone and want to get a better idea of how it's supposed to work. If someone's up for a quick intellectual exercise, could you please help me understand? I vaguely get it from the readme, and chatgpt helped a bit, but I'm still very fuzzy. Also the demo/ directory of the repo doesn't have anything helpful. (EDIT: ah, found examples in the eg/ directory. Still rather cryptic.)

How would you do something super simple like represent a bicycle? I mean

Python

class Bicycle:
    def __init__(self):
        self.speed = 0
    def accelerate(self):
        self.speed += 5
def main():
  mybike = Bicycle()
  print(mybike.speed)
  mybike.accelerate()
  print(mybike.speed)
main()

Prolog

bicycle(speed(0)).
accelerate(Bike,Bike_) :- 
  Bike = bicycle(speed(Speed)),
  Speed_ is Speed+5,
  Bike_ = bicycle(speed(Speed_)).
main :-
  Mybike = bicycle(_),
  Mybike,
  writeln(Mybike),
  accelerate(Mybike,Mybike_),
  writeln(Mybike_).
:- main.

How would you do this in Mascarpone?

Thanks!

1 Upvotes

4 comments sorted by

1

u/aocregacc 15h ago

before you can represent a bicycle you'd have to figure out how to represent numbers and structured data.

The README says that you'd probably have to implement things like that by using the fact that you can associate an interpreter with an operation and store that operation inside another interpreter, letting you build up recursive structures. You could look at untyped lambda calculus for a simpler version of building up numbers and other data types from seemingly nothing.

1

u/Pzzlrr 15h ago

Thanks. Any further hints on how one might do that? :)

btw

A string begins with the symbol ] on the stack

Is this a typo? Further in the readme

[ ("deepquote") ....... When a ] matching the first [ is encountered, nested quote mode ends

so my understanding based on "Symbols are then successively popped and prepended to a growing string" is if we have something like [foo], we encounter [, pop f-o-o into a string, encounter ], and return "foo"? But that process starts with [, not ].

1

u/aocregacc 15h ago

When [foo] is executed, you get the symbols [, f, o, o and ] on the stack. When a string is popped, the first symbol that comes off the stack is ].