
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.

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

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

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?

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

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

(I might not be able to help though…)

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

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

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

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

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)))))])

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)

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

#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))

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

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

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

I suspect that’s why the autoquoting behavior is happening

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))

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

Simply write your own write-proc

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

Was just hoping to save time. :smile:

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

Oh wait

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

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

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

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

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

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

@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.

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”

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.

thanks for the help

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

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.

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

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

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

and has slightly improved in my increasingly dismal DrRacket performance.