
Suppose that I’m making a #lang
that reuses some things from Racket but has different syntax. Is there a general approach to ensuring that errors get reported in a way that makes sense in the syntax of the #lang
? One concrete example would be imports/exports: if surface syntax like import foo except (bar, baz)
is transformed into (require (except-in foo bar baz))
, then an erroneous import needs to be explained in terms of the import ...
syntax, not (require ...)
.

No. You will need to catch the error and rewrite it. Alternatively (not always possible) check what you can first, then call/use the Racket construct. That way you have fewer error types to worry about.

That works, thanks, @soegaard2.

@mbk.racket has joined the channel

@mflatt My current project is a pretty straightforward bf program translator, which converts the Brainfuck program into a racket module and executes it. It took 20 seconds to execute a famous sample program mandelbrot.b.
https://gist.github.com/sleepnova/0277a1a9bf5f6fe104e222d379452688
But a jit-compiler written in C using DynASM took only 3.2 seconds to execute the same program without any optimization.
Warning - Content in Traditional Chinese https://hackmd.io/@0140454/ByZPlJ6ye?type=view
- How could there be such a big difference?
- Is there any way to make the Racket version comparable to the C version?

I have issues copying a struct with an #:auto field. It seems struct-copy is not smart enough to detect this situation and not call the constructor with the auto argument. Example: > (struct fish ([age #:auto #:mutable]) #:auto-value 0)
> (struct shark fish (color))
> (struct-copy shark (shark 'blue) [color 'green])
; shark: arity mismatch;
; the expected number of arguments does not match the given number
; expected: 1
; given: 2
; arguments...:
; 0
; 'green
; Context:
; /usr/share/racket/collects/racket/repl.rkt:11:26

is this a bug or expected behaviour of struct-copy?

Is this the latest version of Racket?

No, 7.8

Pretty recent.

Check the source of struct-copy.

Hmm. Where is it defined?

Found it. I don’t see anything about auto values. https://github.com/sorawee/racket/blob/master/racket/collects/racket/private/define-struct.rkt#L948

Does struct-copy
work with auto fields for structs with no super structs?

No it does not either. I looked at the source, but are not familiar enough with macros to understand what is going on. Is it even possible to check if a field of a struct is automatic?

It’s pretty low-level code. The function struct-type-info
can return how many auto fields there are: auto-field-cnt: the number of fields defined by the structure type without a counterpart in the constructor procedure (not counting fields created by its ancestor types);

And since all automatic fields get the same value, that should be enough for struct-copy
I think.

I agree, it should be possible to change the behaviour of struct-copy to work in such cases as well. So should I open an issue for this?

I think that’s a good idea.

The main thing is probably to make the program functional instead of using set!
. Also, the generated code is large, so I had to setenv PLT_CS_COMPILE_LIMIT=100000
to convince Racket CS to really compile it; that didn’t help so much with the set!
version, though. With the limit raised, here’s a functional version that runs in about 3 seconds instead of about 17 seconds on my machine;

Can redex use same terminals for non-terminals? like I use same dot to represent two different empty contexts. (Γ ::=
· ;; empty
(Γ ◃ x : τ))
(ψ ::=
· ;; empty
(ψ ◃ τ))
I guess no, redex-match
can’t match it correctly while in define-judgment-form
it works well.


I am comparing this piece of code from struct-copy
(define-values (the-struct-info maybe-field-info) (id->struct-info #'info stx))
(define construct (cadr the-struct-info))
(define pred (caddr the-struct-info))
(define accessors (cadddr the-struct-info))
(define parent (list-ref the-struct-info 5))
to the values returned by struct-type-info
: name
init-field-cnt
auto-field-cnt
ascessor-proc
mutator-proc
immutable-k-list
super-type
skipped?
and can’t get the lists to match. For example, counting from 0, the super-type
aka parent ought to have the index 6?

I tried the above code with Racket BC v7.9, and it took 38.9 seconds instead of 20.8 seconds or 3 seconds. Quite a big difference.

should be fine. Can you give an example of redex-match not doing the right thing?

this would be consistent with the documentation of module racket/struct-info. Not sure what the relationship to.procedure struct-info from base is

Hi, David, I use a scratch buffer to test a little, found it works fine in simple code (so I think the problem lies on mine, sorry for that :)

It matches the output of make-struct-type
. I must be missing something.

After using raco ctool
to embed a Racket module into a C source file, with the --runtime
flag passed in, is it possible to change the root path to the runtime files at runtime? I’m trying to embed some Racket code that depends on gregor
(which has some runtime support files for tzdata) into an iOS app, but the only way to know where those files end up within the built app is to query some iOS APIs at runtime (CFBundleGetMainBundle
and co.). Using relative paths via the --runtime-access
flag doesn’t seem to work.

@popa.bogdanp I was reminded about your app store app recently. How did the experiment turn out? (Btw - It doesn’t show up in the app strore when I search for “Remember” - it helps to add a “Quick”. Is there a way for you to add search terms?)

None of the Racket bits were a problem for getting past the review process. They requested some small revisions before allowing the app to be published, mostly to do with the UI and the biggest one being that I add a guide on first run. The app has sold 20 units against 780 views and 6.6k impressions so it has a fairly low conversion rate :sweat_smile:, but at least it’s covered the developer license for a couple of years. I’m thinking about porting it to iOS as well (hence the question above) so we’ll see how that goes, too.

Re. the search terms, it doesn’t look like I have any control over that stuff.

Thanks for the info. Good to hear Racket wasn’t a problem. Just curious, what’s the difference between a view and an impression?

I think a view is counted when someone clicks on the app to view its details and impressions are counted whenever it shows up in a list (search results, featured lists, etc.).

I actually think the conversion rate is okay - but it’s tricky to get the number of views up.

Yes, if you only take sales reported against views, then it’s not too bad. The website for the app points at both the App Store and Gumroad so that probably has ended up cannibalizing some App Store sales as well, because on Gumroad you pay what you want. On Gumroad there were 124 sales.

I see. Yes that’s definitely a factor.

If you need to quote a happy customer: https://thenextweb.com/apps/2020/02/11/remember-is-an-app-that-lets-you-set-reminders-from-macos-spotlight/

Despite the low number of sales, though, I’m happy with how it turned out. I was the primary audience for this app and I use it all the time :smile:

@pawel.to.malpa has joined the channel

@jagen315 has joined the channel

@jason.hemann has joined the channel

If I remember how this all works, the paths are meant to be relative to the executable, so they’re found through (find-system-path 'exec-file)
and (find-system-path 'orig-dir)
.

So, you need a way to set those in an embedding application.

good evening, I’m working on a multimethod-like thing. I originally had it adding instances at runtime, but I decided I needed to lift it into phase 1. Now I’m having trouble getting the instances between modules. Any advice?

In BC, there’s scheme_set_exec_cmd
and scheme_set_original_dir

In CS, there are fields for those in racket_boot_arguments_t
.

Can I have both Racket BC and Racket CS installed and switch back and forth without any problem? Currently I need to run raco setup
each time when using different version. Otherwise, the following problems will occur. read-compiled-linklet: virtual-machine mismatch expected: "chez-scheme"

I tried the above code with Racket CS v7.9, and it took 52.8 seconds to complete.

If you build from a Git checkout using make both
, then they coexist more peacefully. Racket BC is racketbc
, racobc
, etc., and it uses a bc
subdirectory of compiled
.

It’s hard to know exactly what you are running into, but I recommend the paper “advanced macrology and the implementation of typed scheme” as a place to start

I’m puzzled, because it runs the same for me with v7.9 CS. That’s all in the part wrapped by time
, not compilation (which might otherwise be related to the other thread)?

I have both Racket BC and CS v7.9 installed from pre-compiled dmg files. Do they interfere with each other?

Not necessarily, but it depends on how you install packages.

You can avoid package interference for user-scoped by giving one of the installations a different name with raco pkg config -i --set name
.

I use raco pkg install
normally. But I have to raco setup before switch between the two to avoid virtual-machine mismatch
error.

Changing one of the names will help. Probably the installers should come with different names to help avoid that problem, and we’ll consider that for the next release.

thanks! I got it working, I was on the right track. the problem was I was storing the instances inside a gvector in a define-syntax. each module was getting a fresh copy so the mutations weren’t carrying over (I suppose that is why it is called “syntax-local-value”). I had to do it inside a generated begin-for-syntax
instead, as in the paper.

One strange thing is that I don’t have to setenv PLT_CS_COMPILE_LIMIT=100000
to convince Racket CS to run it.

It will run, but in a hybrid interpreted—compiled mode. If you’re not setting the environment variable, that would also explain the slowness.

That’s great, now it finished within 4.2 seconds! It would be nice to have some indication of the execution mode.

macro of the day: (regexp-define (as bs cs) #rx"(a*)(b*)(c*)" "aabbbbc")
;; matches regexp against string and binds each group to a variable
;; as is bound to "aa"
;; bs is bound to "bbbb"
;; cs is bound to "c"

match
has a redex
pattern form that works similarly: (match "aabbbbc"
[(regexp #rx"(a*)(b*)(c*)"
(list _ as bs cs))
___])

hmm, maybe I should add this to racket/match

if I require that the regexp is always a constant literal, I can do lots of validation too to get good error messages and enforce that the number of identifiers is consistent with the number of groups