mario.luis.guimaraes
2019-2-19 10:06:32

Good day! How does Racket differ from traditional parsers with respect to parsing conventional syntax instead of s-expressions? Anyone here with experience with both kind of tools who could provide a more informed and practical comparison?


jerome.martin.dev
2019-2-19 10:11:36

@mario.luis.guimaraes You can look at brag: https://docs.racket-lang.org/brag/


jerome.martin.dev
2019-2-19 10:12:00

It allows you to write grammars for any language


jerome.martin.dev
2019-2-19 10:15:44

The way it works is: 1. You write the lexer, which reads a character stream and generates tokens 2. You write the parser using a grammar DSL, which describes the rules for the position of tokens 3. You get an s-expression and can process it like any Racket syntax


diego
2019-2-19 10:16:20

@mario.luis.guimaraes for some examples of brag take a look at https://beautifulracket.com


mario.luis.guimaraes
2019-2-19 10:16:21

That sounds promising. But, how does brag compares to other traditional parser generators, like Lex and Yacc, Flex and Bison, OCaml’s Menhir? Is it on par to these tools?


mario.luis.guimaraes
2019-2-19 10:16:35

For example, could I write a Java parser using brag?


jerome.martin.dev
2019-2-19 10:18:12

In my experience, brag is useful for relatively “simple” languages. For more complex ones, I’d go with nanopass https://docs.racket-lang.org/nanopass


diego
2019-2-19 10:18:52

mario.luis.guimaraes
2019-2-19 10:23:32

Thanks for the links


mark.warren
2019-2-19 10:24:43

I don’t know what it written with but ProfessorJ might be worth a look https://docs.racket-lang.org/profj/index.html


mario.luis.guimaraes
2019-2-19 10:26:14

This means that for handling traditional languages (like Java or C) one has to resort to the same kind of tools in Racket as in other languages, is that so?


jerome.martin.dev
2019-2-19 10:28:38

Well I don’t know what you mean by “the same kind of tools” but lexers, parsers, tokenizers… whatever you call them are fairly similar in any languages. They’re just a bit easier to write in Lisp-like languages because you have easy access to AST


mario.luis.guimaraes
2019-2-19 10:29:09

Right, that is what I mean


soegaard2
2019-2-19 10:30:19

@mario.luis.guimaraes Traditional parser tools with a Racket twist: https://docs.racket-lang.org/parser-tools/index.html



soegaard2
2019-2-19 10:31:22

mario.luis.guimaraes
2019-2-19 10:32:12

So the advanced stuff that makes Racket more suited to language-oriented programming is geared only to support s-expressions based languages, is that so? (For the other conventional languages one was to use the typical parser and lexer tools)


soegaard2
2019-2-19 10:33:09

I don’t see like that. Lexing / parsing is a solved problem. S-expressions is just one kind of input.


mario.luis.guimaraes
2019-2-19 10:33:41

Or one uses the traditional parser and lexer tools to convert conventional syntax to s-expressions, and then we can use Racket’s full language-oriented potential thereon?


soegaard2
2019-2-19 10:33:44

The manipulation of syntax objects and easy rewriting between language constructs is the exciting part.


soegaard2
2019-2-19 10:33:52

Yes.


mario.luis.guimaraes
2019-2-19 10:34:11

Ok, understood, makes sense


jerome.martin.dev
2019-2-19 10:34:21

That’s usually how it’s done, yup


mario.luis.guimaraes
2019-2-19 10:35:38

Ok, so I see there are several variants of parser and lexers in Racket too. Which one would you consider more “industrial-strength” where I could start?


jerome.martin.dev
2019-2-19 10:35:51

The interesting part about this is that using s-expressions for anything internally, you get to stitch together different languages which may have different syntaxes externally, but work on the same structures internally


mario.luis.guimaraes
2019-2-19 10:36:15

Right! :thumbsup:


soegaard2
2019-2-19 10:36:39

parser-tools is definitely “industrial-strength”


mario.luis.guimaraes
2019-2-19 10:36:54

@jerome.martin.dev You use the traditional parser to convert to s-expressions and “get rid of conventional syntax” thereon.


mario.luis.guimaraes
2019-2-19 10:37:50

Thanks @soegaard2


jerome.martin.dev
2019-2-19 10:39:11

I don’t necessarily get rid of them, but it helps working on the same structures and have a single logic core, then multiple “language interfaces”


mario.luis.guimaraes
2019-2-19 10:39:49

I definitely have to look into this Racket language-oriented stuff. There seems something here in the combination of s-expressions and language-generation/integration that is somewhat vague and different from the rest, I suppose.


jerome.martin.dev
2019-2-19 10:40:21

usually I design my languages as s-expression first, close to the data I’m workin on, then I design a specific syntax if I feel the need to


mario.luis.guimaraes
2019-2-19 10:41:48

As anyone here experience with OCaml’s and Racket’s toolchains for language processing and analysis? Perhaps the two best available today …


mario.luis.guimaraes
2019-2-19 10:42:17

(I really find these two languages the best around for language processing, hence my question)


jerome.martin.dev
2019-2-19 10:42:18

I know some people are working with Coq and Haskell too


soegaard2
2019-2-19 10:43:36

Btw - I believe that ragg and brag both work by transforming the grammar into something that parser-tools can understand.


mario.luis.guimaraes
2019-2-19 10:43:48

yep, but anyone with common experience dealing with this stuff in OCaml and Racket? (I suppose Haskell is on par with OCaml)


jerome.martin.dev
2019-2-19 10:44:10

@soegaard2 yep, I love brag for that because it’s reeeeally simple to use


greg
2019-2-19 16:20:46

@mario.luis.guimaraes Maybe of interest to you if/when you want to shift from researching to trying some things hands-on: https://school.racket-lang.org/index.html


greg
2019-2-19 16:21:17

Looks like some course materials from last year, are here: https://summer-school.racket-lang.org/2018/plan/


mario.luis.guimaraes
2019-2-19 16:26:28

Thanks @greg.


greg
2019-2-19 16:33:31

I don’t know if anyone on #beginners will have done exactly the sort of project you want to do and done it thoroughly in all of Racket, OCaml, Haskell, etc. :slightly_smiling_face: Even if someone did, and thought X was their favorite, you might not agree. Different things “click” for different people. It’s good to do lots of research. Eventually, at some point, you may just need to dig in and try. ¯_(ツ)_/¯


mario.luis.guimaraes
2019-2-19 16:36:40

@greg yes, of course, but my question was to have some opinions from anyone that might have such practice, in order to know tradeoffs.


mario.luis.guimaraes
2019-2-19 16:37:57

I asked here in beginners just because I am a beginner with Racket; perhaps I should have tried in #general.


mario.luis.guimaraes
2019-2-19 16:40:02

Should I go with Racket or Ocaml for serious static analysis? I have to pick one because time is limited, hence I came here …


mario.luis.guimaraes
2019-2-19 16:40:14

… hence my question(s)


mario.luis.guimaraes
2019-2-19 16:41:18

I know OCaml is a strong choice for this in the “industry”. I wonder if Racket is at least on par to OCaml … but seems no one has such experience to inform me …


greg
2019-2-19 17:11:08

@mario.luis.guimaraes Is this a commercial project? What is the schedule like?


mario.luis.guimaraes
2019-2-19 17:12:00

yep, the part with static analysis probably end this year


mario.luis.guimaraes
2019-2-19 17:12:29

open source & commercial, the typical these days


mario.luis.guimaraes
2019-2-19 17:13:00

the static analysis part must be performant and efficient


greg
2019-2-19 17:13:24

Will you be the sole developer, or will there be a team?


mario.luis.guimaraes
2019-2-19 17:14:26

very small team to start


mario.luis.guimaraes
2019-2-19 17:15:08

thing is to put in cloud, somewhere


greg
2019-2-19 17:15:59

If you/the team has much experience with any of those langs (Racket, OCaml, Haskell, whatever) I’d say that’s important to consider, along with the supposedly inherent advantage of any of those langs at some specific problem domain. 10 months isn’t a long time.


greg
2019-2-19 17:16:29

If you spend the first N months just getting comfortable and productive with lang X, and all on the same page with conventions, etc.


mario.luis.guimaraes
2019-2-19 17:17:33

We have experience with Elixir and Erlang, but we know what’s in those langs (I have thaught Haskell once at university, but not used it in industrial practice)


mario.luis.guimaraes
2019-2-19 17:18:05

I have lots of experience with Elixir macros (second nature, programming macros is to me as easy as normal programming these days)


mario.luis.guimaraes
2019-2-19 17:18:33

In fact Elixir is a kind of Lisp for Beam, but with m-expressions


greg
2019-2-19 17:21:49

I don’t earn a commission if I convince you to use Racket :smile:. I’d still like you to use it. But if it were my company/$ and I had 10 months to ship something, I’d probably look at leveraging the thing the team knows how to use. So Elixir/Erlang. Maybe 1 or 2 people uses Racket (or Haskell or OCaml or X) for a piece of the problem.


greg
2019-2-19 17:22:34

But I’m biased, I think most software development problems have more to do with primates cooperating than with the tech per se. :slightly_smiling_face:


mario.luis.guimaraes
2019-2-19 17:22:45

Yes, Racket (or Haskell or OCaml or X) would be for a piece of the problem (heavy duty static analysis)


mario.luis.guimaraes
2019-2-19 17:24:00

For example, today I have been sanity testing a macro-based library I did in Elixir, and almost all of the bugs, if not all, have been due to type errors …


greg
2019-2-19 17:25:44

So Elixir is dynamically typed, “typespecs” sound sort of like contracts? Are you saying you wish you had a strong static type system, instead?


mario.luis.guimaraes
2019-2-19 17:26:41

Yes, but on the Beam, which there isn’t


mario.luis.guimaraes
2019-2-19 17:26:57

In this case the Beam wins for me, without any doubts


mario.luis.guimaraes
2019-2-19 17:29:57

Sorry, I was on the phone…


mario.luis.guimaraes
2019-2-19 17:30:41

Yep, Beam is fantastic, no doubts, but for heavy duty analysis might be slow.


mario.luis.guimaraes
2019-2-19 17:31:44

My original idea of Racket would be to generate DSLs for the Beam (or anything else that comes along), since I prefer Lisp syntax


mario.luis.guimaraes
2019-2-19 17:33:37

I tend to see Beam as an orchestrator at the core of a web server, with high-performance nodes in other languages.


mario.luis.guimaraes
2019-2-19 17:34:01

it is these nodes that are best suited for heavy duty stuff


mario.luis.guimaraes
2019-2-19 18:25:06

@greg I think I will explore Racket meta-programming tools for targeting other platforms with a Lisp-like language, but for parsing traditional languages, and since I like static types, I believe OCaml / Haskell is a better choice right now. Thanks.


mark.warren
2019-2-20 07:42:59

@mario.luis.guimaraes Have you considered LFE (Lisp Flavoured Erlang)? http://lfe.io/