Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't attempt to typeset code if the syntax object is not original #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

default-kramer
Copy link
Contributor

No description provided.

@AlexKnauth
Copy link
Owner

AlexKnauth commented Feb 4, 2019

I don't think this is the right change. Just dropping the form like this doesn't seem right to me.

It also depends on how most languages operate with what they output in the reader:

  1. Some #lang languages might just not have the original? property set at all. If you're defining a reader from scratch, its tricky. If you're just making a quick #lang for a specific purpose its not worth it, and if you're not using DrRacket you might not even notice.
  2. Some #langs might figure out how to put the original? property on things, and just set everything to original? even when it doesn't make sense.
  3. Some #langs might put forms even furthur inside the syntax, like outputting (module _ language/runtime (#%module-begin (language-specific-begin form ...))).

I don't know how many #langs have any of those 3 problems vs how many use original? in exactly the way we expect.

My idea for this would be to either modify split-module-syntax or make a new function that would be called on the second output value of split-module-syntax.

@default-kramer
Copy link
Contributor Author

Re: 1 and 3, I agree. Re: 2, I would say there is no need to try to support such a language.

It's possible (and maybe even likely) that I'm missing something here, but I don't think 1 and 3 are solvable in the general case. You have to either make assumptions about the #lang in question, or else you need way more input from the caller. Consider a stack-based arithmetic language (idea borrowed from Beautiful Racket). Say the original source code is 1 2 + 100 * and the reader produces the following piece of syntax

(module stacker-mod racket
  (define args '())
  (define (handle x)
    (if (procedure? x)
        (let ([result (x (car args)
                         (cadr args))])
          (set! args (cons result (cddr args)))
          result)
        (set! args (cons x args))))
  (handle 1)
  (handle 2)
  (handle +)
  (handle 100)
  (handle *))

(No expansion is required, this will run directly out of the reader.) The desired output of code-examples is

> 1
> 2
> +
3
> 100
> *
300

Or is it? Maybe the desired output is

> 1 2 +
3
> 100 *
300

Let's just assume that the first output is what we want. We are still in trouble if the lang does not help us out with the syntax-original property. How do we know that (define args '()) is a "fabricated" piece of syntax, vs (handle 1) which does have some basis in the original source code?

And a final problem, say this lang does use the syntax-original property but the property is set on 1 instead of on (handle 1). It still seems shaky to assume that the result of (handle 1) should correspond to the "1" from the original source code.

@AlexKnauth
Copy link
Owner

AlexKnauth commented Feb 4, 2019

That makes me think of a worse possible example:

(module stacker-mod racket
  (define args '())
  (define (handle x)
    (if (procedure? x)
        (let ([result (x (car args)
                         (cadr args))])
          (set! args (cons result (cddr args)))
          result)
        (set! args (cons x args))))
  (custom-begin
    (handle 1)
    (handle 2)
    (handle +)
    (handle 100)
    (handle *)))

How would it distinguish the custom-begin form from the handle forms?

By the way, one of the reasons I'm thinking about custom begin forms like this is that some of the languages I want to be able to use this with, such as dssl2, expand to some sort of begin form.

@default-kramer
Copy link
Contributor Author

default-kramer commented Feb 5, 2019

Thinking more about this, one possibility is to require the language to have REPL support. Then require the caller to pass each REPL interaction individually. For example

(code-examples #:lang "stack-arithmetic" "1" "2" "+" "100" "*")

Would set up the REPL for the language and then each string of code would get read, evaluated, and typeset individually. This removes all ambiguity (I think), but obviously puts more burden on the caller.

(Edit: or if the language doesn't have a REPL, allow the caller to provide a REPL-like function that takes a string and produces a syntax object.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants