d_run
2017-10-4 14:14:23

Question about Typed Racket: it looks like > wants a Real but most math operators want Number - is there a way to cast a Number to Real for something like (if (> x (+ y z)) ...)



pnwamk
2017-10-4 14:46:44

others who have written more Typed Racket may have better advice… but from my view you could (1) use Real more often instead of Number if that works, or (2) something like the following that can quickly ensure something is a Real (or error in this case):


pnwamk
2017-10-4 14:46:56
#lang typed/racket

(define x : Number 42)

(ann (assert x real?) Real)

pnwamk
2017-10-4 14:48:11

Although many math operators may accept any Number, they will also accept Real (since any Real is a Number), and many (I think…) should know that if they got a Real, they will produce a Real


samth
2017-10-4 14:48:40

@d_run that’s because (< (sqrt -1) 1) is a runtime error in regular untyped Racket


samth
2017-10-4 14:49:01

what I would do for that function is just have it take Real as input


d_run
2017-10-4 14:53:05

ahhhh ok


d_run
2017-10-4 14:53:10

lemme hack on it


mtelesha
2017-10-4 15:20:22

I want to make a volume meter in Racket. What library would I look for?


d_run
2017-10-4 16:05:28

Okay so the problem i have is that I have functions that return the result of a math operation which is a Number and I am passing that to another function which needs a Real


d_run
2017-10-4 16:05:57
; Get magnitude of vector (length)
(: vector-mag (-> vect Number))
(define (vector-mag a)
  (sqrt (+ (expt (vect-x a) 2) (expt (vect-y a) 2))))

; Convert vector to a unit vector (magnitude of 1)
(: vector-normalize (-> vect vect))
(define (vector-normalize a)
  (define m (vector-mag a))
  (if (zero? m)
      a
      (vector/ a m)))

d_run
2017-10-4 16:06:43

in this case vector-mag is returning the result of sqrt which is a Number and that is getting passed to vector/ down in the bottom of vector-normalize which wants a Real


samth
2017-10-4 16:10:14

@d_run #lang typed/racket (struct vect ([x : Real] [y : Real])) ; Get magnitude of vector (length) (: vector-mag (-> vect Real)) (define (vector-mag a) (sqrt (+ (sqr (vect-x a)) (sqr (vect-y a)))))


samth
2017-10-4 16:10:51

@mtelesha Racket GUI library? Sound library? Or some other kind of library?


d_run
2017-10-4 16:15:09

@samth just so I understand, I need to use sqr because expt can return types other than Number or an exception or something?


samth
2017-10-4 16:21:58

@d_run the issue is that (expt i 3) is not a Real, but (expt i 2) is, and Typed Racket isn’t currently smart enough to tell the difference


samth
2017-10-4 16:22:08

but sqr always produces a Real


s.carr1024
2017-10-4 16:49:20

@s.carr1024 has joined the channel


s.carr1024
2017-10-4 16:55:22

Hello! I’m trying to script GDB with racket as a subprocess. However, I’m having trouble reading/writing to the subprocess. I thought it was a buffering issue. Here is a small reproduction of my issue: #lang racket (define GDB-PROMPT #"(gdb) \n") (define NEWLINE 10) (define-values (proc o i e) (subprocess #f #f #f "/usr/bin/gdb" "--interpreter=mi2")) (file-stream-buffer-mode o 'none) (file-stream-buffer-mode i 'none) (file-stream-buffer-mode e 'none) ; read menu (10 lines long) (read-bytes-line o) (read-bytes-line o) (read-bytes-line o) (read-bytes-line o) (read-bytes-line o) (read-bytes-line o) (read-bytes-line o) (read-bytes-line o) (read-bytes-line o) (read-bytes-line o) ; read (gdb) \n (read-bytes-line o) (write-bytes #"-file-exec-and-symbols a.out\n" i) (flush-output i) (read-bytes-line o) ; (read-bytes-line o) ; read done (write-bytes #"-break-insert *main\n") (flush-output i) (sleep 1) (read-byte o) The final line blocks forever. Could some one please suggest how I should go about reading/writing to a subprocess when I don’t know exactly when it will respond?


mtelesha
2017-10-4 17:00:14

@samth there is RSound but it already isn’t working on my computer and I want to distribute this to about 20 computers


mtelesha
2017-10-4 17:01:47

@samth RSound uses portaudio “This package includes the portaudio dynamic libraries for Windows and Mac, where I believe that users will have trouble compiling and installing such a package”


mflatt
2017-10-4 17:03:43

@s.carr1024 It looks like you’re missing i as the output port for the last write-bytes


s.carr1024
2017-10-4 17:05:23

@mflatt you’re right! I should have known better. I’ve made that mistake several times already :wink: thank you


lexi.lambda
2017-10-4 17:06:33

@s.carr1024 if you wrap everything with (parameterize ([current-output-port i]) ....), then you won’t have to specify the port, and you won’t be able to make the mistake :)


leif
2017-10-4 17:11:26

@mtelesha What systems do you want to distribute it on?


leif
2017-10-4 17:11:38

(most linux systems have portaudio in their repos)


mtelesha
2017-10-4 17:11:59

@leif Sadly Windows 7 and Windows 8 :disappointed:


leif
2017-10-4 17:12:25

@mtelesha Oh, interesting.


leif
2017-10-4 17:12:42

I know some windows systems require you to init the package


leif
2017-10-4 17:13:10

Did you call pa-maybe-initialize?



leif
2017-10-4 17:14:04

Actually, better idea, can we take a step back…you want to make a volume meeter, may I ask what you want it for?


samth
2017-10-4 17:20:15

@mtelesha maybe ask about the RSound problems on the mailing list


mtelesha
2017-10-4 17:21:16

@samth I’m checking on my OpenSUSE machine right now. I am thinking it is a Windows portaudio issue. Doesn’t look like there are other options besides portaudio currently


leif
2017-10-4 17:24:44

@mtelesha More or less…depend on your application. :slightly_smiling_face:


mtelesha
2017-10-4 17:26:24

@leif I teach LITTLE kids that wear headphones. I need to know if the computer is playing audio to them and if it is the kids need to know not to touch the screen yet.


leif
2017-10-4 17:29:06

Ah, okay.


leif
2017-10-4 17:29:42

So in that case you aren’t generating any sound, so much as you want to see the sound that the system is generating, coorect?


s.carr1024
2017-10-4 17:31:20

OK that was a bug in my reproduction of my real bug. My real problem is that I cannot read from the gdb subprocess after I send any of the exec-* commands. For example: https://gist.github.com/scottcarr/e9605a0b4c058f4e853b0ac11f1a3abe Is it because gdb’s exec-* commands fork or something like that?


ben
2017-10-4 18:25:07

scribble PDF question: is there an easy way to print landscape & large fonts?


ben
2017-10-4 18:25:34

(forwarded from blerner, the idea is to make an “accessible” version of a class handout)


mtelesha
2017-10-4 20:17:13

@leif Yes I just want to know that sound is being played and then have some events triggered


mtelesha
2017-10-4 20:17:53

@ben have you tried quad for PDF?


leif
2017-10-4 20:20:48

@mtelesha Ah, okay. Hmmph. I’m not even sure if portaudio can handle that. As it’s just a library to produce sound, not monitor it.


leif
2017-10-4 20:21:06

And this will probably be platform dependent.


leif
2017-10-4 20:21:13

Windows 7 and 8 you say?


mtelesha
2017-10-4 20:21:43

yes :disappointed:


ben
2017-10-4 20:21:49

no


leif
2017-10-4 20:22:21

Okay….hmm…next question, is the sound coming out of a standard 3.5mm jack?


mtelesha
2017-10-4 20:23:06

It is coming out of Either USB or 3.5mm


mtelesha
2017-10-4 20:30:31

seems like I need to have access to the Windows Mixer. I see how to access it in C , but my C skills are decades old


leif
2017-10-4 20:31:31

@mtelesha Oh bleh, ya, that makes things harder.


leif
2017-10-4 20:31:37

Can you link to the API?


leif
2017-10-4 20:31:47

(Racket has a really good FFI)


leif
2017-10-4 20:33:39

Ah, it’s a c++ api, not c…that’s harder. :disappointed:


leif
2017-10-4 20:33:47

Investigating…


mtelesha
2017-10-4 20:34:08

@leif Well this will be my new pet project for a little bit to try and get the API to sound mixer. I’m always thinking of fringe cases.


leif
2017-10-4 20:34:43

lol, fair.


leif
2017-10-4 20:34:55

Sadly C++ and FFIs don’t mix very well. :disappointed:


mwb
2017-10-4 20:36:36

hi racketeers, thanks in advance for looking. I am trying to use the rackdis package to connect to a remote redis server. All of the examples I’ve found use the following to initiate a connection: >(define redis (new redis%)) >(send redis init) I’m unsure about the syntax for adding the ip address and port of the remote server. In the docs the definition of redis% starts like this: >(define redis% > (class > object% > (init-field [ip “127.0.0.1”] [port 6379] [timeout 1]) > (field [out null] [in null]) > (super-new)

and it ends like this: >(define/public (init) > (define-values (i o) (tcp-connect ip port)) > (set! in i) > (set! out o)))) I’m pretty new to Racket and can’t quite figure out how to set the IP and Port. There is “public” setter for timeout but not one for IP and Port


leif
2017-10-4 20:38:25

@mtelesha Can you send me a copy of mmsystem.h?


leif
2017-10-4 20:38:34

It looks like this is the file that contains all of the smarts.


leif
2017-10-4 20:38:40

But I don’t have immediate access to a windows pc.


lexi.lambda
2017-10-4 20:40:34

@mwb try (new redis% [ip "1.2.3.4"] [port 1234])


mwb
2017-10-4 20:44:55

thank you @lexi.lambda I appreciate the help again (you’ve helped before!). I guess I should have tried that looking at the definition. What am I looking at there in the definition? redis% is defined as a class I guess? But I just don’t see where in the definition it shows that there is a short circuit to stuff my args into the init-field fn


mwb
2017-10-4 20:45:03

that worked, btw


lexi.lambda
2017-10-4 20:45:50

that’s just how the racket class system works, so init-field is just a part of class syntax. you might want to read the section of the racket documentation on racket/class.


lexi.lambda
2017-10-4 20:46:15

this is probably a good place to start http://docs.racket-lang.org/guide/classes.html


mwb
2017-10-4 20:46:34

@lexi.lambda mostly joking but I was hoping by using racket I wouldn’t have to think about classes


lexi.lambda
2017-10-4 20:46:38

(I find the section of the reference on classes a little uncharacteristically difficult to read)


lexi.lambda
2017-10-4 20:47:02

@mwb me, too. I don’t use racket/class. but the author of the redis package did, so you probably have to think about them if you want to use that package. :)


mwb
2017-10-4 20:47:44

thank you though. if init-field is part of the class syntax that makes perfect sense. I had not come across it before


mwb
2017-10-4 20:47:50

@lexi.lambda thanks again!


lexi.lambda
2017-10-4 20:48:51

@mwb if you search for identifiers in the docs, they’ll usually link to something useful http://docs.racket-lang.org/search/index.html?q=init-field


lexi.lambda
2017-10-4 20:49:28

but… the racket/class reference is laid out in a bit of an odd way, so a lot of the docs for the various class-related forms are in other places. :/


lexi.lambda
2017-10-4 20:49:36

and it doesn’t have enough examples.


mwb
2017-10-4 20:50:30

slightly more examples than rackdis does though: https://docs.racket-lang.org/rackdis/index.html


lexi.lambda
2017-10-4 20:52:24

yes, rackdis looks like it needs a little love.


mwb
2017-10-4 20:56:23

apologies for the sarcasm. I actually really appreciate anyone who’s created a module/package and gone out of their way to get it published in a repo. we’re lucky to have anything at all


ben
2017-10-4 21:59:39

update from blerner he’s happy after: (1) using a TeX style to enter landscape mode for the document, and (2) putting \fontsize{28pt}{40pt}\selectfont at the top of the document


ben
2017-10-4 22:00:32

@leif any thoughts on turning a scribbled PDF into a “very large print” version? If not I’ll turn this into a stackoverflow Q/A


leif
2017-10-4 22:01:47

Probably should be a so question. My main thought is you’ll want to replace the style file…


mwb
2017-10-4 22:49:52

hi, last question for the day. I’m getting a list back from redis, which is good. it looks like it’s a list of strings but string functions reject them. They members the list have a ‘#’ in front of them. For example: >#“do I not look like a string” I think this has something to do with the contract but can’t figure out how to massage it into a string


jaz
2017-10-4 22:50:23

those are bytestrings


cfinegan
2017-10-4 22:51:03

you want bytes->string/utf-8 to turn them into strings


mwb
2017-10-4 22:51:23

gotcha. found that fn


mwb
2017-10-4 22:52:06

is there an fn that I could have used to determine what type I had? something that would have returned ‘bytestring’?


jaz
2017-10-4 22:54:51

um, in a typed-racket repl, you could enter #"dfsdgvsd", and you’ll see the type


jaz
2017-10-4 22:54:56

so that’s kinda a way


mwb
2017-10-4 22:55:22

ah ok


mwb
2017-10-4 22:56:35

>> #“haha” >- : Bytes >#“haha”