Are the attributes of syntax classes similar to the attributes of Knuth & Wegner’s attribute grammars (https://en.wikipedia.org/wiki/Attribute_grammar)?
@kellysmith12.21 Yes.
Is there a paper that formally defines Racket’s syntax/parse and syntax class facilities?
(there is also the Reference of course)
Thanks!
I hope this is a meaningful question, but how do I see a full stack trace in DrRacket? I got this error just now: . . ../../Applications/Racket v7.7/share/pkgs/datalog/stx.rkt:55:10: for-each: contract violation
expected: list?
given: #<void>
…and that’s all it shows
if I open the file datalog/stx.rkt
and look at line 55 I don’t see a for-each
as named in the error, just:
(eval-statement (datalog-stmt stmt)))
is there something like a debugger (eg pdb in python)?
If you are using DrRacket, you should have these icons when error appears
Click the left icon. That will show a detailed “stacktrace”
Also make sure that it says: “Language: racket, with debugging”
if it simply says “Language: racket” (without “with debugging”), you need to adjust a setting via the language menu.
thanks, that now shows
how do I get deeper in?
That’s as detailed as it can provide you, assuming that you have “with debugging” on.
Perhaps you can say what do you expect to happen
yes it’s “with debugging”
I’m used to a debugger where I can go up and down the stack(?) and inspect values at each level - is there anything like that? here I think I’m still not seeing the actual code that raised the error, just some outer layer
Is this #lang racket
or datalog
?
its #lang racket
and I did the datalog stuff in racket syntax
Can you provide me program that you are working on?
I actually just have a discussion with people on how to improve this stack trace a few days ago (though I don’t think that improvement would help your situation)
for context… I am passing an impersonated hash into datalog as the theory for sure the problem is in my impersonator implementation in this case the code is probably simple enough for me to solve by bisect it/stare hard at the code/trial and error
but it’s more of a general question about how to debug things in Racket
Quick info for you: you can’t “inspect values at each level” because Racket is free to eliminate any bindings that is no longer needed.
But if the stack trace is not helpful, that should be fixed
So if you can provide an example of a program that causes this problem, that would be great.
Ah
I think what happens here
is that errortrace couldn’t instrument code in datalog library
because datalog is already compiled to bytecode
I could be wrong though.
thanks, I don’t totally understand the first part but I will try to read more about it
I’ll put my code in a gist, there’s not much to it at the moment
if I click the “Builtins” tab I get some deeper parts of the stack trace (I think…) but it has highlighted some very large chunks of code like datalog/runtime.rkt: 73:0
and that’s the whole (define (prove thy q)...)
function, about 75 lines
Also, I’m not totally free right now. Will try to find some free time tonight to look into this.
no worries, I will research elsewhere as well, thanks for your help
here is the gist in case it helps re better stack traces: https://gist.github.com/anentropic/976121f288e7f0a2e91e8de082f44096 (see comment at the bottom)
I want to write a function my-apply
which behaves like apply
in typed/racket, so I query the type of apply
: > (:print-type apply)
(All (a b) (-> (-> a * b) (Listof a) b))
It seems that apply
only accepts 2 arguments, I’m a little confused. Do I miss something?
It used to be the case that apply
accepts only two arguments I think?
At least that’s how it was in some versions of Scheme
Thanks, I don’t know how to write my-apply
, can you give me some advice?
apply
is a little weird — if you use it as a higher-order function it has a less-useful type than if you use it directly
To write my-apply
, you have to use apply
.
what should my-apply
type look like? This is where I am confused.
Is this what you want: #lang typed/racket
(: my-apply (All (a b) (-> (-> a * b) (Listof a) b)))
(define (my-apply f l) (apply f l))
Thanks, I hope my-apply
can work like this: > (apply + 1 2 3 '(2))
- : Integer [more precisely: Positive-Integer]
8
> (my-apply + 1 2 3 '(2)) ; -> 8
Unfortunately you can’t describe that type in Typed Racket
I understand now. Thank you.
We’ve actually thought about adding that capability to ->*
but it’s a bunch of complexity for something not that useful outside of the type of apply
.
you can see https://github.com/racket/racket/pull/564 and https://github.com/racket/typed-racket/pull/623 which are related to this
Thanks!
It looks like my diagnosis is wrong. DrRacket already instruments datalog library
Here’s an output from the errortrace in the command-line
for-each: contract violation
expected: list?
given: #<void>
errortrace...:
/Users/sorawee/git/racket/racket/share/pkgs/datalog/runtime.rkt:103:4: (for-each (lambda (clause) (define renamed (rename-clause clause)) (define selected (clause-head ....)) (cond ((....) ....))) (get thy (subgoal-question sg)))
/Users/sorawee/git/racket/racket/share/pkgs/datalog/eval.rkt:37:5: (prove (current-theory) (query-question s))
/Users/sorawee/git/racket/racket/share/pkgs/datalog/stx.rkt:55:10: (idY21 lifted/18 (idY300 lifted/18 (list (bytes->path (....)) (quote ....) (....) ....) (idY127 lifted/18 (....) ....)))
/Users/sorawee/git/racket/racket/share/pkgs/datalog/stx.rkt:53:9: (->substitutions (lambda (g1) (let-values (((g12) g1)) (let-values (....) ....))) (idY21 lifted/18 (idY300 lifted/18 (list ....) (....))))
so it shows that (subgoal-question sg)
evaluates to (void)