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


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

#lang typed/racket
(define x : Number 42)
(ann (assert x real?) Real)

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

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

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

ahhhh ok

lemme hack on it

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

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

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

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

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

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

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

@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

but sqr
always produces a Real

@s.carr1024 has joined the channel

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?

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

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

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

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

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

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

(most linux systems have portaudio in their repos)

@leif Sadly Windows 7 and Windows 8 :disappointed:

@mtelesha Oh, interesting.

I know some windows systems require you to init the package

Did you call pa-maybe-initialize
?


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

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

@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

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

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

Ah, okay.

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?

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?

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

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

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

@ben have you tried quad for PDF?

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

And this will probably be platform dependent.

Windows 7 and 8 you say?

yes :disappointed:

no

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

It is coming out of Either USB or 3.5mm

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

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

Can you link to the API?

(Racket has a really good FFI)

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

Investigating…

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

lol, fair.

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

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

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

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

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

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

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

that worked, btw

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
.

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

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

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

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

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

@lexi.lambda thanks again!

@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

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. :/

and it doesn’t have enough examples.

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

yes, rackdis looks like it needs a little love.

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

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

@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

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

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

those are bytestrings

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

gotcha. found that fn

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

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

so that’s kinda a way

ah ok

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