Starting a language after Beautiful Racket

74 views
Skip to first unread message

Pratyush Das

unread,
Apr 10, 2020, 8:20:17 AM4/10/20
to Racket Users
I am absolutely new to both Racket and language implementation.

I read through some portions of Beautiful Racket and the racket guide before trying to implement a language on my own and this is what I understand - 

I created a main.rkt which would be the boot module in my source directory, following the Beautiful Racket master recipe.

Every language should define and provide a read-syntax function. 

To make the new language read the source file, read-syntax must be defined something like - 
(define (read-syntax path port)
...)

Like in Beautiful Racket's wires language implementation, I want to read the source file line by line and wrap it in a macro. 
Beautiful Racket does it like this - 
  (define (read-syntax path port)
    (define wire-datums
      (for/list ([wire-str (in-lines port)])
        (format-datum '(wire ~a) wire-str)))

But this assumes that the br lang is being used(I think because of the format-datum syntax). How do I implement this without using the br lang?

Also, am I wrong in any of my assumptions so far?


Pratyush Das

unread,
Apr 10, 2020, 12:17:58 PM4/10/20
to Racket Users
A followup question - 

But this assumes that the br lang is being used(I think because of the format-datum syntax). How do I implement this without using the br lang?

...
(define src-lines (port->lines port))
  (define src-datums (format-datums '(handle ~a) src-lines))
...

Is it possible to use modules to just get the format-datums from the br language? 


--
You received this message because you are subscribed to a topic in the Google Groups "Racket Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/racket-users/qEXz8YcAisc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/180aae4b-9e79-43cc-9177-6c917acf0dc8%40googlegroups.com.


--
Pratyush Das(Reik)

Matthew Butterick

unread,
Apr 10, 2020, 2:42:16 PM4/10/20
to Pratyush Das, Racket Users
Three options:

1) Implement your language in `#lang br` now (and optionally convert to `racket/base` later) [1]

2) Import the `br/datum` module into a `#lang racket/base` program to get `format-datum` [2]

3) Reimplement `format-datum` your own way. You can see the underlying code by right-clicking on `format-datum` in DrRacket and selecting "Open Defining File".

You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAFzLTskQ70okYZj247VA2rGNWyoW62wCyyu3jqXHtzZdw3aJEg%40mail.gmail.com.

Pratyush Das

unread,
Apr 11, 2020, 3:06:36 AM4/11/20
to Matthew Butterick, Racket Users
Thanks!
--
Pratyush Das(Reik)
Reply all
Reply to author
Forward
0 new messages