jeapostrophe
2019-8-11 09:51:51

The surprise you have for the change of syntax is interesting to me, because we’ve been thinking about what changes to make and how to make them for over a decade and making incremental progress along the way. (Jon Rafkind, the student that Matthew worked on Honu with, started in 2007 and caused a lot of ideas to be talked about during his dissertation work.) Very early, DrRacket supported the various non-Sexpr snip syntaxes. Honu was merged and available back then in 2010 or 11, I believe. More recently, in 2015 we added the cdot (#%dot) notation as another way to get a little closer. For me, this is an extremely slow evolution of Racket over a very long time.


steveh2009
2019-8-11 14:25:10

@soegaard2 Is there a way to use #:mutable just once in a struct definition to have every field mutable?


sorawee
2019-8-11 14:33:42

@steveh2009 (struct foo (a b c) #:mutable)


stefan.kruger
2019-8-11 14:55:45

Are there some examples somewhere on how to use parameters when using threads? I want each thread to have its own copy of a “global, mutable” hash holding some state — or am I already on the wrong side of the tracks?


jarcane
2019-8-11 14:59:31

argh. the curse of quoted values is upon me. Does anyone have experience with make-constructor-style-printer?


sorawee
2019-8-11 15:00:33

I used to use it. What’s the question?


sorawee
2019-8-11 15:00:39

(I might not be able to help though…)


jarcane
2019-8-11 15:02:58

Basically, I have a struct, which contains a function, which when called, returns a quoted list


jarcane
2019-8-11 15:03:38

And the trouble is, if I return that list from the second lambda arg for make-constructor-style-printer, then it prints it out with each of the pairs in that list quoted


jarcane
2019-8-11 15:05:47

Ie, it does this: > (def Foo (thing-s (thing (foo 1) (bar 2)))) > Foo (thing '(bar 2) '(foo 1))


jarcane
2019-8-11 15:06:26

When what I’d want there is (thing (foo 2) (bar 1))


jarcane
2019-8-11 15:07:18

My struct def then looks like this: (struct thing-s (proc) #:methods gen:custom-write [(def write-proc (make-constructor-style-printer (fn (obj) 'thing) (fn (obj) ((thing-s-proc obj)))))])


jarcane
2019-8-11 15:08:39

I’ve tried various alternate implementations and it seems like make-constructor-style-printer is automatically quoting any list elements of the list returned by the second lambda (fn here because this is partially in Heresy)


jarcane
2019-8-11 15:09:40

This is a problem because for various complicated reasons, technically that result, while usable, is not a constructor style printing of things. I suspect I may have to actually write my own custom writer


sorawee
2019-8-11 15:12:58
#lang racket

(require racket/struct)

(struct bar (x)
  #:methods gen:custom-write
  [(define write-proc
     (make-constructor-style-printer
      (lambda (obj) 'bar)
      (lambda (obj) (list (bar-x obj)))))])

(struct foo (x)
  #:methods gen:custom-write
  [(define write-proc
     (make-constructor-style-printer
      (lambda (obj) 'foo)
      (lambda (obj) (list (foo-x obj)))))])

(foo (bar 1)) ;=> (foo (bar 1))

sorawee
2019-8-11 15:13:41

I think there’s nothing wrong with your thing-s


sorawee
2019-8-11 15:13:50

It’s foo and bar that need to be adjusted.


jarcane
2019-8-11 15:14:07

Well, foo and bar aren’t structs. They’re just internal symbols


jarcane
2019-8-11 15:14:31

I suspect that’s why the autoquoting behavior is happening


jarcane
2019-8-11 15:16:44

The actual constructor macro is for an object-like thing, and the syntax looks like (thing (foo 1) (bar 2)). Internally, this makes a lambda, which closes over an alist like: '((foo 1) (bar 2))


sorawee
2019-8-11 15:19:45

Another way is to not use make-constructor-style-printer.


sorawee
2019-8-11 15:19:58

Simply write your own write-proc


jarcane
2019-8-11 15:20:02

Yeah, I’m suspecting that may have to be the way.


jarcane
2019-8-11 15:20:10

Was just hoping to save time. :smile:


jarcane
2019-8-11 15:21:24

also, I think a custom printer is slightly more backwards compatible. My CI build just failed because make-constructor-style-printer is from 6.3


sorawee
2019-8-11 15:22:51

Oh wait


sorawee
2019-8-11 15:24:09

Can we use unquoted-printing-string to do anything? I guess not.


jarcane
2019-8-11 15:24:32

Hmm, I looked at that but I’m not sure it’s meant for it.


jarcane
2019-8-11 15:25:05

Possibly if I converted each list to a string first, and then wrapped it in unquoted-printing-string, that might work.


sorawee
2019-8-11 15:27:55

Yeah, but at that point, you might as well write your own write-proc


jarcane
2019-8-11 15:28:19

Yep. It seems hacky, and it also is only available in 6.10


jarcane
2019-8-11 15:28:33

And I would still like to get this code working in 6.1 again some day for reasons


soegaard2
2019-8-11 15:40:46

@stefan.kruger parameters are implemented with thread local cells. That is when you create a new thread it inherits current parameter values, but changes to a parameter does not affect the other threads. So I think parameters will just work for you.


jarcane
2019-8-11 15:52:12

Well, I have a working implementation sort of, but not one that entirely obeys the rules of “can be read back as a valid syntax for replicating itself”


jarcane
2019-8-11 15:53:11

But I think by and large I’m OK with this for now as this is a larger problem in the language I’ll have to get to later.


jarcane
2019-8-11 15:53:17

thanks for the help


markus.pfeiffer
2019-8-11 17:07:51

Sligthly surprised to find out that racket 7.4 essentially built without problems on my alpine-raspberry pi


ryanc
2019-8-11 18:44:02

You can get the effect you want, printing like (thing (foo 2) (bar 1)) by having the second argument to make-constructor-style-printer return a list of auxiliary structs containing a symbol and a value. The auxiliary struct type (you only need one) should print by pretending that the symbol is its constructor and the other value is the single argument. You can define that auxiliary printer with make-constructor-style-printer too.


jarcane
2019-8-11 18:48:00

Mmm. I wound up just going with defining my own.


jarcane
2019-8-11 18:48:38

Which still has some quirks owing to the vagaries of write/display/print, that I shall probably want to spend some time sorting out


jarcane
2019-8-11 19:25:24

I’m glad to see that so far CS racket is fine


jarcane
2019-8-11 19:25:37

and has slightly improved in my increasingly dismal DrRacket performance.