sorawee
2020-10-1 07:08:28

sorawee
2020-10-1 07:09:03

Would it be better to email @asumu directly? I don’t know if he’s active on Slack.


noahstorym
2020-10-1 09:25:38

Hello, I met a problem about match  in typed/racket: #lang typed/racket (define-type Type (U Number Symbol)) (ann (lambda (arg) (match arg [(or (? number? x) (? symbol? x)) x])) [-> Type Type]) It failes with the following message: Type Checker: type mismatch expected: Type given: (U False Type) in: x

And if I change  Type  to a Refine  Type: #lang typed/racket (define-type Variable (Refine [var : Symbol] (! var 'λ))) (define-predicate variable? Variable) (define-type Type (U Number Variable)) (ann (lambda (arg) (match arg [(or (? number? x) (? variable? x)) x])) [-> Type Type]) It failes: Type Checker: type mismatch expected: Type given: (U Complex False Symbol)

If Type  is a recursive Refine  type: #lang typed/racket (define-type Variable (Refine [var : Symbol] (! var 'λ))) (define-predicate variable? Variable) (define-type Type (U Number Variable (Listof Type))) (ann (lambda (arg) (match arg [(or (? number? x) (? variable? x)) x])) [-> Type Type]) It will stuck in an endless loop.


noahstorym
2020-10-1 11:26:25

Here is another problem about define-predicate : #lang typed/racket (define-type Foo (List Any)) (define-predicate foo? Foo) (define-type Bar-List (Listof Bar)) (define-type Bar (U Foo Bar-List)) (define-predicate bar-list? Bar-List) (define-predicate bar? Bar) I tried to define a predicate bar? for Bar by define-predicate , but it failed: Type Checker: Type Bar could not be converted to a predicate: required a flat contract but generated a chaperone contract in: Bar then I defined bar? manually: #lang typed/racket (define-type Foo (List Any)) (define-predicate foo? Foo) (define-type Bar-List (Listof Bar)) (define-type Bar (U Foo Bar-List)) (define-predicate bar-list? Bar-List) (: bar? [-> Any Boolean : Bar]) (define bar? (λ (arg) (or (foo? arg) (bar-list? arg)))) (displayln (bar? '((1) ((2)) (((3)))))) ; #t It works well. Why doesn’t define-predicate work for Bar ?


greg406
2020-10-1 13:11:23

@greg406 has joined the channel


jestarray
2020-10-1 16:00:52

so (string->symbol "1") results in '\|1\| . which is the symbol of an integer. how would i convert this to an integer? I can do (symbol->string) and then string to number but im looking for another built in way


samth
2020-10-1 16:04:26

@jestarray that’s the way.


jestarray
2020-10-1 16:05:13

ahh alright


samth
2020-10-1 16:06:29

I suppose you can do something like: (read (open-input-string (let ([v (open-output-string)]) (display "1" v) (get-output-string v))))


samth
2020-10-1 16:06:35

But I don’t recommend that


jaz
2020-10-1 16:09:50

You can potentially save a bit by using symbol->immutable-string to (maybe?) avoid a string copy.


jaz
2020-10-1 16:10:23

(symbol->string returns a mutable string for what I assume are historical reasons.)


jestarray
2020-10-1 16:11:32

feels a bit dirty but eh


jaz
2020-10-1 16:12:24

why do you say that?


jestarray
2020-10-1 16:16:36

its a few extra steps, not to mention the string allocation


jaz
2020-10-1 16:18:42

The string allocation is what I’m addressing with symbol->immutable-string. I agree there shouldn’t be a need to allocate to do this. Extra steps though… if you mean going by way of the symbol’s string representation, then that doesn’t seem “extra” to me.


gknauth
2020-10-1 16:20:10

The machine probably doesn’t think of it as dirty, probably 00101010111011100011110 one way and 1101010101010110100011101100110 another way.


samth
2020-10-1 16:28:38

Why are you converting from strings to numbers via symbols at all?


jestarray
2020-10-1 16:43:50

ohh wait, i can simplify it to just (string->number) , in short I have a string “monster_swingsword_north_0”, the filename of image(s) animation for my game and i run it through a (map string->symbol (string-split str "_"))to dice them up, pickout the pieces and map everything to a number. It just occuried to me i can just store the (string-split) and index into that just for the number


andrzej
2020-10-1 17:06:38

@andrzej has joined the channel


blerner
2020-10-1 19:16:42

@robby or @mflatt — I have a student submission saved in v7.8 of DrR. It’s a wxme file containing embedded images. I have a server-side script that tries to load the file and process it, running under xvfb-run. And I’m seeing the following error: insert-file in text%: error loading the file (read-from-file-failed) context...: /usr/share/racket/pkgs/gui-lib/mred/private/wxme/text.rkt:2727:2: insert-port method in text% /usr/share/racket/pkgs/gui-lib/mred/private/editor.rkt:212:23 /usr/share/racket/pkgs/gui-lib/mred/private/editor.rkt:206:19 /opt/bottlenose/lib/assets/render-racket.rkt:173:0: render (submod "/opt/bottlenose/lib/assets/render-racket.rkt" main): [running body] temp35_0 for-loop run-module-instance! Any ideas what might be causing this? (I don’t have racket 7.8 locally on my laptop (because the ubuntu PPA hasn’t been updated yet) so I can’t reproduce this locally. I can send you the relevant files and scripts, if you like.)


robby
2020-10-1 19:18:25

wasn’t it you who told me that that means it is actually a 7.7 file?


robby
2020-10-1 19:18:45

But really, I don’t know.


blerner
2020-10-1 19:19:14

I had thought so! :slightly_smiling_face: But I looked in the file and its preamble says #reader(lib"<http://read.ss\|read.ss>""wxme")WXME0109 ## #\| This file uses the GRacket editor format. Open this file in DrRacket version 7.8 or later to read it.


blerner
2020-10-1 19:19:31

(this is a different file than that one that I’d commented on)


robby
2020-10-1 19:19:34

If you have dev tools installed, building racket consists of just “make” and getting coffee. And the .sh download from will install in a directory that you can just throw away if you don’t want it. It isn’t like it does crazy stuff on your file system or anything.


robby
2020-10-1 19:20:05

You don’t need to put it into /usr or anything like that. It’s totally self-contained.


robby
2020-10-1 19:20:32

I can’t tell what might be going wrong with that file, I’m sorry.


blerner
2020-10-1 19:20:38

k, thanks


blerner
2020-10-1 19:24:24

ok, I downloaded Racket 7.8 and have it in a local dir. Even opening the file in DrRacket 7.8 fails


blerner
2020-10-1 19:24:27

same error


azriel
2020-10-1 20:51:26

OK, here’s more confusion related to the student languages. If I type

(string-&gt;number "1.00")

into DrRacket’s Interactions window in Beginning Student, it produces the integer 1. But if I put the following into m.rkt:

#lang htdp/bsl (inexact? (string-&gt;number "1.0"))

and run using racket -t m.rkt, Racket produces #t, i.e, it converts to an inexact number. How can I make the two environments give me the same answer?


sorawee
2020-10-1 21:03:01

#lang htdp/bsl is somewhat “broken” in that sense. The recommendation I saw is to use the dropdown menu to choose Beginning student language


azriel
2020-10-1 21:03:48

Yes, and when using DrRacket I absolutely do. The trouble is that this is arising in a back-end shell script that grades student submissions, so it has to work from the command line. Any way to make that work?


samth
2020-10-1 21:07:01

You can run BSL programs from the command line, and they should work as you see in DrR


azriel
2020-10-1 21:07:42

Are there instructions for doing so?


samth
2020-10-1 21:08:19

just run them with racket


samth
2020-10-1 21:08:28

or do you mean how to write them?


samth
2020-10-1 21:09:00

If so, I’m not sure why you want to write a new program in BSL


azriel
2020-10-1 21:12:21

Consider the following program:

(require test-engine/racket-tests) (check-expect (inexact? (string-&gt;number "1.0")) false) (test)

If I enter that program in the Definitions window in BSL and press run, it works OK. Now, put this into a file n.rkt:

#lang htdp/bsl (require test-engine/racket-tests) (check-expect (inexact? (string-&gt;number "1.0")) false) (test)

When I run it with racket n.rkt, it fails. What’s the difference? “Just run them with racket” is precisely what I’m hoping to be able to do, but I can’t account for the differences in behaviour.


sorawee
2020-10-1 21:13:46

I want to understand what you want to do better. If “1.0” is written in students’ code, then it’s an integer. If it’s written in instructor’s code, then it’s an inexact number. But the fix is easy. You just change it to “1".


samth
2020-10-1 21:14:26

What I’m saying is that if you put that in the definitions window in DrRacket, and then save the file, and then run that file with racket file.rkt it will do the right thing


samth
2020-10-1 21:15:00

#lang htdp/bsl is not useful for any purposes that I know of


azriel
2020-10-1 21:15:30

If I leave it out, I get an error message starting with “default-load-handler: expected a `module’ declaration…”


lmrosso
2020-10-1 21:15:43

@lmrosso has joined the channel


samth
2020-10-1 21:16:07

Are you getting the text of the file that the student writes in the definitions window, or the actual saved file?


samth
2020-10-1 21:16:23

And if the former, why?


azriel
2020-10-1 21:16:29

Ah, you mean include the invisible header information in the saved student file. Let me check that.


azriel
2020-10-1 21:17:49

No, even with the full header information, the test fails because the number is parsed as an inexact.


azriel
2020-10-1 21:18:15

#reader(lib "<http://htdp-beginner-reader.ss\|htdp-beginner-reader.ss>" "lang")((modname a02q3) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))  

(require test-engine/racket-tests) (check-expect (inexact? (string-&gt;number "1.0")) false) (test)


azriel
2020-10-1 21:19:02

@sorawee, it’s more subtle than that. I’m distilling a more complicated test scenario down to this simple demonstration of different behaviour.


sorawee
2020-10-1 21:19:14

Sorry. I think we are having the https://en.wikipedia.org/wiki/XY_problem.

Can you show what students’ program look like? And how are you planning to autograde it?


azriel
2020-10-1 21:20:06

Sure, let me try to expand a little.


sorawee
2020-10-1 21:20:28

What you write above: (check-expect (inexact? (string-&gt;number "1.0")) false)

is not really grading, because everything is “fixed” already. There’s no input from student program.


samth
2020-10-1 21:22:26

Ok, I can reproduce the problem. If you put (check-expect (inexact? (string-&gt;number "1.0")) false) in a BSL program, save it, and then require the test submodule of that program, you get a failure.


azriel
2020-10-1 21:23:01

So it’s related to test-engine/racket-tests?


samth
2020-10-1 21:24:48

No.


samth
2020-10-1 21:25:06

This program has the same surprising behavior: #lang racket (require (prefix-in h: lang/htdp-beginner)) (inexact? (h:string-&gt;number "1.0"))


samth
2020-10-1 21:25:17

as in, it prints #t


azriel
2020-10-1 21:26:22

Weird. I noticed that there’s a hidden configuration option for string->number that could affect this, but I can’t see why it should flip in this context.


samth
2020-10-1 21:29:33

That’s almost certainly the issue then


samth
2020-10-1 21:29:54

Note that the beginner docs are wrong for string->number (in the example)


azriel
2020-10-1 21:30:10

@sorawee Let’s say you wanted to write a function that receives a dollar amount in a string, and produces the corresponding number of cents as an integer. So, for example, I’d want (cents "14.23") to produce 1423.


samth
2020-10-1 21:30:55

Or rather, the problem is that you need to set (read-decimal-as-inexact? #f)


azriel
2020-10-1 21:30:58

A student might happily write this in DrRacket:

(define (cents amt) (number-&gt;string (* 100 (string-&gt;number amt)))) (check-expect (cents "1.00") "100")

And that works just fine. But when we run the same check-expect in our command-line testing environment, it fails for the reasons given above.


azriel
2020-10-1 21:31:51

@samth Yes, I saw that. But first of all, I don’t know how to get access to that function from the student languages (sorry, that’s my own naivety), and second, I don’t know what other traps might be lurking beyond this one which I just happened to discover.


sorawee
2020-10-1 21:32:09

Here’s a workaround:

  1. Create grader.rkt with the content:

#lang racket (dynamic-require '(submod "file-to-grade.rkt" test) #f) 2. Create launcher.rkt with the content:

;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "<http://htdp-beginner-reader.ss\|htdp-beginner-reader.ss>" "lang")((modname b) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #t))) (require "grader.rkt")


sorawee
2020-10-1 21:32:27

And run racket launcher.rkt


azriel
2020-10-1 21:32:54

So It’s unsatisfying to apply a single band-aid here, only to get stuck again (and indeed, see my much earlier question about using errortrace). I really want a big hammer that makes everything behave just like it does in the teaching languages.


azriel
2020-10-1 21:33:37

@sorawee Whoops, sorry, the function should produce the integer number of cents as a string. (This is extracted from a longer problem…)


sorawee
2020-10-1 21:33:54

Actually, only one file might suffice if we require dynamic-require from racket in launcher.rkt


sorawee
2020-10-1 21:35:31

Yeah, so launcher.rkt could be:

#reader(lib "<http://htdp-beginner-reader.ss\|htdp-beginner-reader.ss>" "lang")((modname b) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #t))) (require racket) (dynamic-require '(submod "file-to-grade.rkt" test) #f)


samth
2020-10-1 21:37:40

I would also suggest looking at make-evaluator, which is what I use and which takes an specification that includes specific BSL handling


azriel
2020-10-1 21:47:46

Yes, I had started to look into make-evaluator a little bit, and it seems like a more industrial strength solution to creating a command line harness for running student code. I’m worried that it won’t solve problems like the one above directly, but it might at least give me the ability to patch problems as I see them.


azriel
2020-10-1 22:03:37

Hmm, it’s might be challenging to get check-expect tests working inside an evaluator.


peterzhong2023009
2020-10-1 22:20:29

@peterzhong2023009 has joined the channel


badkins
2020-10-1 22:27:21

Anyone have a nice way to format code with line numbers in slideshow ? I’m finding the code macro very nice, but I haven’t found a nice way to easily reference portions of the code.


samth
2020-10-1 23:50:01

@azriel the handin-server does it, you might look at that


azriel
2020-10-1 23:51:17

Oooh, I hadn’t seen that. Thanks.


azriel
2020-10-1 23:53:31

Forgive my ignorance, where can I find a copy of the source code?


azriel
2020-10-1 23:53:52

nvm, found it on github.


samth
2020-10-2 01:39:12

@azriel Shriram Krishnamurti also recently wrote a package for autograding using gradescope, you might look into that


azriel
2020-10-2 01:39:40

Thanks! I’m definitely willing to bug Shriram on twitter :slightly_smiling_face: