pezi_pink
2017-4-16 13:57:41

hello all! I was wondering if you can help me with the following problem. Here is a much distilled and silly example:

(define-syntax (test stx)
    (syntax-parse stx
      [(_ ex)
       #'(define z ex)
       ]))

(test 0)
z

z appears as unbound. I understand this is probably to do with contexts, phase-levels and such. I have experimented and read a lot, and learnt tons, but I have been unable to get this to work. This is obviously a silly example, in the real thing the returned syntax expression is some racket s-exp that has been parsed in a chunk from my #lang. The idea is to pass the racket code through untouched and have it expand into the top level of the module, so that the stuff in it can be later evaluated by other in-line expressions in my language.

Any pointers would be greatly appreciated :slightly_smiling_face:


leafac
2017-4-16 16:52:00

@pezi_pink: The name z is not bound outside the body of the test macro due to hygiene. Use the Macro Stepper in DrRacket and note that the z in expanded macro and the z outside it are different colors, meanings they are different variables, which happen to have the name name. Like there are many people named “Leandro” who aren’t me, we just happen to have the same name. The quick way out is to use with-syntax and datum->syntax to break hygiene (see http://pasterack.org/pastes/85576). But you should really learn about hygiene and how to use it to your advantage. Maybe there’s a better way to write macros for your use case, taking advantage of hygiene, that would compose better with other macros. To that end, I recommend you start with Fear of Macros (http://www.greghendershott.com/fear-of-macros/index.html) and then follow its references (§8). That’s how I learned about this stuff, anyway :slightly_smiling_face: Good luck!


pezi_pink
2017-4-16 17:37:54

@leafac thanks very much for the response, I did think it might also be a hygiene issue, but sometimes it hard to discern what layers you are in and where the problems lie in several layers of meta. I will try the “breaking” trick to see if I can get it to work - I think i tried all this stuff already but maybe I was not applying it correctly. Hopefully there is a nicer way to do it in the future. For a bit more context this is along the lines of what I am trying to achieve:

;this denotes a racket s-exp block
;which I pick up as a whole unit
<-
(define x 42)
(define y 42)
(define (test z)
  (+ y z))
->

; some custom language here that gets expanded
blah <% (test 10) %>  ; this inline expression should be able to "see" the block stuff above

thanks again for the tip :slightly_smiling_face:


leif
2017-4-16 18:29:40

@samth Thanks. the previous errors were masking that from me.


samth
2017-4-16 18:30:16

@leif is there something else erroring in the travis builds? if so, we should fix it


leif
2017-4-16 18:32:34

@samth At least when I merged there was.


samth
2017-4-16 18:33:19

I don’t think that’s a good reason to merge something with failing builds, unless we really can’t fix it


leif
2017-4-16 18:34:02

@samth I agree?


leif
2017-4-16 18:35:19

But I have no idea who’s commit started the errors.


samth
2017-4-16 18:38:20

what are the errors?



leif
2017-4-16 18:45:21

samth
2017-4-16 18:45:56

the first one seems to just be a transient failure


samth
2017-4-16 18:46:14

the second is on the release branch, which sometimes has other difficulties, but several configurations passed there


samth
2017-4-16 18:46:25

have you looked at what happened?


leif
2017-4-16 18:47:22

The builds for mast have been failing off and on for the past few weeks.


leif
2017-4-16 18:47:52

I ran the tests, noticed a bunch of errors that weren’t related to log.


samth
2017-4-16 18:48:38

pushing without a clean test run is not a good idea


leif
2017-4-16 19:39:26

@samth I fixed the tests.


leif
2017-4-16 19:39:36

At least the ones related to log.


leif
2017-4-16 19:39:51

It looks like they are all passing now (at least on the machines I tested it on.)


samth
2017-4-16 19:40:02

great


samth
2017-4-16 21:38:39

@leif the travis tests don’t seem to be working with your fix. can you take a look? https://travis-ci.org/racket/racket/builds/222617417


leif
2017-4-16 21:42:27

@samth Hmm…that does not appear to be log related: -------------------- raco pkg install --copy <https://bitbucket.org/mflatt/pkg-test.git?path=pkg-test1> FAILURE name: check-equal? location: /home/travis/build/racket/racket/pkgs/racket-test/tests/pkg/util.rkt:219:6 actual: 1 expected: 0 expression: (check-equal? cmd-status 0) message: "exit code" Check failure --------------------


samth
2017-4-16 21:42:48

is that what happens in all of them?


leif
2017-4-16 21:43:35

Nope, in another one the error is: The job exceeded the maximum time limit for jobs, and has been terminated.


leif
2017-4-16 21:44:24

@samth 4 of them have the first error message, 3 of them have the second.


samth
2017-4-16 21:44:38

did your changes cause anything new to get installed?


leif
2017-4-16 21:44:58

Nothing that I can imagine


leif
2017-4-16 21:45:30

The docs link to the math library


leif
2017-4-16 21:45:40

But they already linked to a lot of things iirc.


samth
2017-4-16 21:46:03

right, if you didn’t add any dependencies then that wouldn’t change things


leif
2017-4-16 21:46:09

The actual code did not have any #includes (that I added anyway)


leif
2017-4-16 21:46:19

I did add one, here:



leif
2017-4-16 21:47:12

In pkgs/racket-doc/info.rkt


leif
2017-4-16 21:47:20

But that’s the only place I added a dep.


leif
2017-4-16 21:48:16

And I mean, it was already depending on drraacket, pict, compiler-lib, future-visualizer, etc.


leif
2017-4-16 21:48:40

I added math-doc and math-lib (so I could link to fllogb


samth
2017-4-16 21:50:10

that shouldn’t be an issue


leif
2017-4-16 21:54:30

@samth FWIW this error happened off and on before my push: https://travis-ci.org/racket/racket/jobs/220284133


leif
2017-4-16 21:54:41

As for the build time exceeded though, I don’t have much o that yet


leif
2017-4-16 21:54:44

Looking into it.


samth
2017-4-16 21:55:21

may just need to be re-run if downloading took extra long or something


leif
2017-4-16 22:09:56

That might make sense. I’ll try that.


samth
2017-4-16 22:13:38

there should be buttons for rerunning builds


leif
2017-4-16 22:23:31

Yup, they’re rerunning as we speak. :wink:


samth
2017-4-16 23:11:37

well this time some of them passed


samth
2017-4-16 23:12:18

now it’s erroring about contacting http://unicode.org\|unicode.org again


leif
2017-4-17 00:50:35

Sigh, rats. Thanks anyway.