maxim_jaffe
2020-8-31 22:55:19

Hello! Does someone know of tutorials that focus on building #lang languages with interpreters as “backends” rather then source-to-source compilers (expanders)?


maxim_jaffe
2020-8-31 23:00:44

I’m guessing it should be down at the expander level, but not sure how to go about it. Also I was wondering, with read-eval-print design, were exactly does the printer fit, in the expander..?


maxim_jaffe
2020-8-31 23:01:42

I like racket’s idea of syntax objects and all the libraries, but a full blown source-to-source compiler is likely overkill for what I am working right now…


cris2000.espinoza677
2020-8-31 23:02:14

it might not, have you read Beautiful Racket?


cris2000.espinoza677
2020-8-31 23:02:31

maxim_jaffe
2020-8-31 23:04:18

yup, read it quite a whole ago (year?)! It’s quite nice, but I think it does follow this source-to-source approach mostly? I’ve been playing around with interpreters tutorials written in other languages (Python, ML, Go, etc) but I just feel racket would be more convenient..!


cris2000.espinoza677
2020-8-31 23:04:32

also you could make a module evaluator based on your language, to make your own eval https://github.com/racket/racket/wiki/Sandbox-examples


cris2000.espinoza677
2020-8-31 23:04:43

what do you want to do?


maxim_jaffe
2020-8-31 23:05:56

An interpreter in which a lot of syntax can be redefined on the fly (a bit like what’s has been explored in Honu and Rhombus)


maxim_jaffe
2020-8-31 23:06:12

a controlled natural language


maxim_jaffe
2020-8-31 23:07:13

I mean I’ve followed quite a lot of typical lisp meta-circular evaluators


maxim_jaffe
2020-8-31 23:07:39

even seen a few examples in racket but they don’t take advtange of #lang from what I could see


maxim_jaffe
2020-8-31 23:08:09

The sand-box examples look promising


maxim_jaffe
2020-8-31 23:08:19

will look more carefully thanks @cris2000.espinoza677


sorawee
2020-8-31 23:09:11

> a full blown source-to-source compiler is likely overkill I’m not sure why you think writing interpreter is easier than the “source-to-source” approach. The point of the compilation approach is that you don’t need to bother giving semantics to primitive constructs, because Racket has already done that for you. You can just reuse whatever Racket gives to you already.


cris2000.espinoza677
2020-8-31 23:09:13

you’re welcome, although you started to scare me, because i have some idea of what you want, but you seem further in front in your racket journey than me lol


cris2000.espinoza677
2020-8-31 23:09:39

yeah what @sorawee said


maxim_jaffe
2020-8-31 23:09:44

problem is I’m writing a portuguese interpreter


maxim_jaffe
2020-8-31 23:09:52

so… lots of mappings


cris2000.espinoza677
2020-8-31 23:10:13

sure so? isn’t like you dont have a lot of mappings with an interpreter


cris2000.espinoza677
2020-8-31 23:10:43

some approaches to keeping variables names in interpreted languages need a hash map


maxim_jaffe
2020-8-31 23:10:57

yeah that’s what I’ve done in Python basically


maxim_jaffe
2020-8-31 23:11:17

used a hash to keep the environment


cris2000.espinoza677
2020-8-31 23:12:31

what would be your approach to make it easier to have a portuguese interpreter? :thinking_face:


sorawee
2020-8-31 23:12:47

I don’t see how sandbox will solve your problem, btw.

In any case, if you really want to interpret, you can just redefine #%module-begin to quote the whole program and call your interp function on the quoted value.


cris2000.espinoza677
2020-8-31 23:12:52

you know racket identifiers are utf–8?


maxim_jaffe
2020-8-31 23:13:27

@sorawee yeah thought of that was wondering if that would be the way


maxim_jaffe
2020-8-31 23:13:31

yup


maxim_jaffe
2020-8-31 23:13:52

it’s just easier to stay at Subject Verb Object all the time


maxim_jaffe
2020-8-31 23:14:09

then having to translate to VSO and back


sorawee
2020-8-31 23:14:45

Can you give me an example AST that you are working on?


maxim_jaffe
2020-8-31 23:15:04

actually I don’t aim to have AST…


sorawee
2020-8-31 23:15:06

I’m really curious if the macro approach would be difficult/tedious as you said


maxim_jaffe
2020-8-31 23:15:16

TDOP


sorawee
2020-8-31 23:15:45

I mean, sure, but you gotta operate on some representation of the program. I meant those representation.


maxim_jaffe
2020-8-31 23:15:50

Maybe it’s not as bad as I think, it’s just I’m quite confortable with interpreters versus compilers..!


maxim_jaffe
2020-8-31 23:16:05

plus don’t have to much time to go into the compiler route


maxim_jaffe
2020-8-31 23:16:46

I mean I sort of have an AST, but I just build it along the way and interpret it


maxim_jaffe
2020-8-31 23:17:07

blocks inside blocks


maxim_jaffe
2020-8-31 23:18:31

maxim_jaffe
2020-8-31 23:18:46

Inspired a lot by CGOL/TDOP


maxim_jaffe
2020-8-31 23:19:14

also construction grammar from cognitive linguistics, where there is not distinction between lexicon and grammar really


maxim_jaffe
2020-8-31 23:19:26

it’s just a single dynamic thing


maxim_jaffe
2020-8-31 23:20:21

anyways thanks for the links and tips @cris2000.espinoza677 @sorawee, you’re likely right in many aspects, I just don’t have the time to explore them for now :sweat_smile:


maxim_jaffe
2020-8-31 23:25:02

One issue with dynamic syntax is how do you compile non-delimited function (logo style) for which you only know how many arguments you take at runtime? I mean the only solution I can think is a fully typed language, possibly with good inference, but that’s even more overkill hehe…


maxim_jaffe
2020-8-31 23:25:54

Just saw they have similar discussions with Honu and Rhombus


cris2000.espinoza677
2020-8-31 23:26:37

ok so this is going over my head. but you want a function that accepts many arguments?


maxim_jaffe
2020-8-31 23:26:48

assuming you have higher-order functions note


maxim_jaffe
2020-8-31 23:27:55

possibly, but ideal not more then 4 or 5, and most would be 1 (intransitive verb) 2 (transitive verb) or 3 (ditransitive verb)


maxim_jaffe
2020-8-31 23:28:41

but [] for example is a n* argument expression


maxim_jaffe
2020-8-31 23:28:58

same goes for {} "" ()


maxim_jaffe
2020-8-31 23:29:11

and that would be the simplest use case


cris2000.espinoza677
2020-8-31 23:30:00

https://docs.racket-lang.org/reference/procedures.html?q=keyword-apply#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._make-keyword-procedure%29%29\|make-keyword-procedure you have that, and change #%app? … i actually dont know what to say… ill see myself out, idk if i can help you… I hope you find someone you can, actually you should ask in #general


maxim_jaffe
2020-8-31 23:30:54

yeah I mean I’ve thought about keywrods (I like Python and Smalltalk in that sense)


maxim_jaffe
2020-8-31 23:31:07

but sometimes keywords get in the way


cris2000.espinoza677
2020-8-31 23:31:39

you could have a syntax transformation between what you want to keywords idk.


cris2000.espinoza677
2020-8-31 23:31:55

also i think this is a more #general type of question


maxim_jaffe
2020-8-31 23:32:12

@cris2000.espinoza677 yeah maybe I should try #general but wanted to check for any obvious tutorials first I might have missed


maxim_jaffe
2020-8-31 23:32:38

Yeah cool idea


maxim_jaffe
2020-8-31 23:32:48

transforming to keywords


maxim_jaffe
2020-8-31 23:35:28

thanks for your time @cris2000.espinoza677]


cris2000.espinoza677
2020-8-31 23:35:58

you’re welcome!


wanpeebaw
2020-9-1 04:17:31

-> Arrow notation could be a potential alternative syntax for lambda.