soegaard2
2019-2-18 09:08:04

@oldsin I haven’t used brag so I can’t say how error reporting can be improved there. An alternative is to use the lexer generator <https://docs.racket-lang.org/parser-tools/Lexers.html?q=lexer> . Here you can choose whether to parse the tokens using your own recursive descent functions, or to use the parser generator (LALR(1)) <https://docs.racket-lang.org/parser-tools/LALR_1__Parsers.html?q=lexer>


soegaard2
2019-2-18 09:08:59

It has the same quirks as other yacc/bison style parsers.


soegaard2
2019-2-18 09:09:30

earl
2019-2-18 11:11:45

@earl has joined the channel


contact
2019-2-18 11:15:35

Dear all, i’m trying to test a thing that get a syntax-object as an input and outputs a datum as an output. Is there a way to write down the syntax object in a file ? Here is what drracket shows me :


soegaard2
2019-2-18 11:16:25

Click the little blue arrow at the left.


soegaard2
2019-2-18 11:16:33

This folds out the syntax object.


contact
2019-2-18 11:16:36

I expected to be able to build an object like that so that they are equal like (syntax ...) but it’s not so simple apparently


soegaard2
2019-2-18 11:16:58

You can now click at individual identifiers to see the associated source location etc.


contact
2019-2-18 11:17:45

contact
2019-2-18 11:17:48

ok thx!


soegaard2
2019-2-18 11:18:43

Also: it’s difficult to use equal? to compare syntax objects.


hoshom
2019-2-18 11:44:42

Is there any convenient way to cast a struct into it’s child (providing the extra values the child struct type needs)


hoshom
2019-2-18 11:45:32

I checked to see if this works, but it doesn’t: (struct foo (x y)) (struct kid foo (z)) (define f (foo 1 2)) (struct-copy kid f (z 3))


hoshom
2019-2-18 11:48:06

Is this an ok idea? (require racket/struct) (apply kid (reverse (cons 3 (reverse (struct-&gt;list f)))))


hoshom
2019-2-18 11:52:17

Although the structs have to be transparent, but that’s ok


abbyrjones72
2019-2-18 12:28:47

Okay I think I got it, but I followed the spirit of the chapter and the way these books usually go: “first we write clunky bad code, then we find better ways.”

#lang racket (define (square x) (* x x)) (define (sum-of-squares x y z) (cond ((&gt; x y z) (+ (square x) (square y))) ((&lt; x y z) (+ (square y) (square z))) ((&gt; y x z) (+ (square y) (square x))) ((&lt; x z y) (+ (square z) (square y))) ((&gt; x z y) (+ (square x) (square z))) ((&gt; z x y) (+ (square z) (square x))))) (sum-of-squares 4 5 6) (sum-of-squares 4 6 5) (sum-of-squares 6 5 4) (sum-of-squares 5 6 4) (sum-of-squares 5 4 6) (sum-of-squares 6 4 5) &gt; 61 &gt; 61 &gt; 61 &gt; 61 &gt; 61 &gt; 61


earl
2019-2-18 12:35:36

Little question: is this or IRC a better place to go?


abbyrjones72
2019-2-18 12:36:40

are you telling me to go to IRC instead?


pocmatos
2019-2-18 12:48:46

@earl both are good i guess. :slightly_smiling_face:


pocmatos
2019-2-18 12:49:12

Your preference might depend on how old you are. :wink:


pocmatos
2019-2-18 12:49:23

… or how old you feel!


abbyrjones72
2019-2-18 12:49:41

IRC makes me feel oooollld


sorawee
2019-2-18 12:53:24

@abbyrjones72 just a little tip. You can wrap your code with ```


sorawee
2019-2-18 12:53:48

It will make your code looks like this

(define (hello)
  world)

abbyrjones72
2019-2-18 12:53:50

oh


sorawee
2019-2-18 12:54:41

It’s backtick


abbyrjones72
2019-2-18 12:55:03

ty lol


sorawee
2019-2-18 12:55:05

The key between esc and tab


sorawee
2019-2-18 12:55:09

Yup :slightly_smiling_face:


abbyrjones72
2019-2-18 12:55:27

Coffee hasn’t kicked in


sorawee
2019-2-18 13:02:43

@abbyrjones72 also, try (sum-of-squares 2 1 2). What’s the expected output?


abbyrjones72
2019-2-18 13:03:06

okay se


abbyrjones72
2019-2-18 13:04:23

(define (sum-of-squares x y z) (cond ((&gt;= x y z) (+ (square x) (square y))) ((&lt;= x y z) (+ (square y) (square z))) ((&gt;= y x z) (+ (square y) (square x))) ((&lt;= x z y) (+ (square z) (square y))) ((&gt;= x z y) (+ (square x) (square z))) ((&gt;= z x y) (+ (square z) (square x)))))


abbyrjones72
2019-2-18 13:04:26

oops


abbyrjones72
2019-2-18 13:04:42

ty @sorawee


sorawee
2019-2-18 13:05:11

np!


abbyrjones72
2019-2-18 13:05:41

i tested (sum-of-squares 2 2 2) also and it dropped one like it was supposed to. :heart:


abbyrjones72
2019-2-18 13:28:49

is there an "applicative order vs. normal order’ for dummies anywhere? going to make that something I learn today


samth
2019-2-18 13:49:05

@abbyrjones72 “applicative order” (more often known as “call by value”) means that we evaluate all the arguments to a function before we do the function call


samth
2019-2-18 13:49:37

“normal order” (more often known as “call by name”) means that we do the function call first, and only evaluate the arguments if we need them


abbyrjones72
2019-2-18 13:52:58

so in normal order, it is possible to divide by zero accidentally?


samth
2019-2-18 13:53:49

in both you can do that


samth
2019-2-18 13:53:59

but it might happen at different places


samth
2019-2-18 13:54:18

and with normal order, you might not see the error sometimes when you would see it with applicative order


samth
2019-2-18 13:54:49

for example ((lambda (x) 5) (/ x 0)) produces an error in applicative order, but 5 in normal order


abbyrjones72
2019-2-18 13:55:01

oh I see!


samth
2019-2-18 13:55:32

you can see this by trying them both in regular #lang racket and in #lang lazy


abbyrjones72
2019-2-18 13:55:40

normal order looks for the first true evaluation of arguments?


samth
2019-2-18 13:56:00

it waits until it really needs the result of the argument to evaluate it


abbyrjones72
2019-2-18 13:56:06

ok


abbyrjones72
2019-2-18 13:56:43

it will be something that takes me a while to fully grasp, but it feels like it’s worth it to learn


andreiformiga
2019-2-18 13:56:56

Normal order sends (/ x 0) as the parameter, without evaluating it first


abbyrjones72
2019-2-18 13:57:52

ohh


abbyrjones72
2019-2-18 13:58:06

that seems like it could be good and bad at the same time


samth
2019-2-18 13:58:35

yes, indeed


abbyrjones72
2019-2-18 14:02:28

that you both so much. If I ask too many questions, please let me know. I hit that “I never wanted to be a website developer/application developer” wall a while ago and have been investigating computer science as a sort of autodidactic pursuit.


abbyrjones72
2019-2-18 14:25:55

Want to make sure I understand compound expressions here: my understanding is in comments.

(define (a-plus-abs-b a b) ((if (&gt; b 0) + -) a b)) ; if b &gt; 0, then we assign + to b, else we assign - to b, and then add to a


alexknauth
2019-2-18 14:27:10

“assign”?


abbyrjones72
2019-2-18 14:29:31

bad wording


andreiformiga
2019-2-18 14:30:05

yes, (if (&gt; b 0) + -) evaluates to + if b is greater than 0 and - otherwise


abbyrjones72
2019-2-18 14:30:16

ty that’s what I meant


alexknauth
2019-2-18 14:30:17

Maybe you meant (+ a (&lt;something&gt; b)) where that something is either an identity function or a negation function?


andreiformiga
2019-2-18 14:31:00

you can use the substitution method, so ((if (&gt; b 0) + -) a b) evaluates to (+ a b) if b > 0 and (- a b) if not


abbyrjones72
2019-2-18 14:31:02

no, this is a problem from SICP and the formula was provided to me. I just had to explain it


abbyrjones72
2019-2-18 14:31:40

i guess it was an introduction to compound expressions?


andreiformiga
2019-2-18 14:31:45

note that b is only involved in the last operation, you don’t change it after the if


abbyrjones72
2019-2-18 14:32:00

correct, I did get that :slightly_smiling_face:


greg
2019-2-18 15:05:48

https://racket.slack.com/archives/C06V96CKX/p1550490282236400 @hoshom I’d probably just pattern match? Something like (match f [(foo x y) (kid x y z)])?


mark.warren
2019-2-18 15:36:30

@andreiformiga Apparently RWops structs have a close method which can be called with io-&gt;close(io); but I don’t have a clue how you could call that from racket, any ideas? Sorry to keep bothering you.


andreiformiga
2019-2-18 16:28:39

@mark.warren no problem but you don’t need to call close


andreiformiga
2019-2-18 16:29:15

I defined sdl-load-bmp just like the SDL_LoadBMP macro


andreiformiga
2019-2-18 16:29:48

if the second argument to SDL_LoadBMP_RW is non-zero, the stream will be closed after being read


andreiformiga
2019-2-18 16:31:16

otherwise it would be weird because SDL_LoadBMP does not return the RWops


hoshom
2019-2-18 17:01:40

@greg yes that works, too, thanks


lspector
2019-2-18 20:26:44

@lspector has joined the channel


lspector
2019-2-18 20:33:35

I see a lot in docs on web programming, but not how to deploy. If, for example, I follow the directions to make an Instant Servlet at https://docs.racket-lang.org/web-server/run.html#%28part._insta%29 then it will run in a browser on my own machine, but what do I do if I have a public html directory on a server and I want to put it there, so that anyone can run it by pointing their browser at a URL on the server?


travis.hinkelman
2019-2-18 21:13:31

I have a simple jargon question. Let’s say that I created the following definitions (define x '(1 2 3)) and (define y #(4 5 6)) and I want to refer to x and y collectively. What would I call them? In R, I would call them objects but that doesn’t strike me as the correct jargon for Racket.


jaz
2019-2-18 21:17:52

“objects” is fine, unless the context of the discussion implies you’re talking about OO stuff


sorawee
2019-2-18 21:19:03

values?


jaz
2019-2-18 21:19:20

~'(1 2 3) is a value, but x is not~


greg
2019-2-18 21:19:20

As an old programmer used to things like C, I’d probably call x and y “variables”. Even though, in Racket, we don’t usually mutate or assign new values (using set!). (In other words, they don’t really “vary” :smile:)



greg
2019-2-18 21:20:07

More strictly, I might say that x and y are bindings whose values are that list and that vector, respectively ¯_(ツ)_/¯


jaz
2019-2-18 21:21:08

though, looking closer… I wasn’t reading that quite right


greg
2019-2-18 21:22:19

I think there’s some text in the docs about the evaluation model, that talks about “locations” that normally have binding names like x and y, and in each location there are values.



jaz
2019-2-18 21:32:45

@travis.hinkelman to some degree it might matter whether you’re referring to x and y themselves or to what they name. My earlier comment that “‘objects’ is fine” is (I think) true if you mean the latter.


jaz
2019-2-18 21:34:13

use-mention distinction stuff


bkovitz
2019-2-18 21:55:40

@greg In pure mathematics, they’re also called variables even though they don’t “vary”.


d_run
2019-2-18 22:04:22

I would probably run the program on the server on a specific port (say 8080) and then have nginx proxy requests to it


d_run
2019-2-18 22:05:04

you might be interested in this https://serverracket.com/


d_run
2019-2-18 22:05:52

You would also want to do something to make sure your program keeps running on crashes, with upstart, supervisord or similar


greg
2019-2-18 22:10:43

Well I call them constables.


benjamin.clos
2019-2-19 00:31:55

@benjamin.clos has joined the channel


benjamin.clos
2019-2-19 02:16:32

Is there an idiomatic way to use a pipeline line operator \|&gt; like in Elixir? Very new to Racket and I saw this: https://docs.racket-lang.org/heresy/pipes.html


benjamin.clos
2019-2-19 02:17:19

but it seems to be a completely different language?


lspector
2019-2-19 02:59:19

Thanks @d_run! The serveerracket thing is actually the opposite of what I want, which is not to make a more complicated website but rather to put the simplest possible website, actually any Racket code at all, on the web. Your “nginx proxy requests” comment may be what I want, but I have no idea what that means :disappointed:. Also, no idea what “supervisord” means. Would love some guide that assumes only knowledge of Racket and shows how to put some Racket thing (maybe something simple like in the Instant Servelet example) on the web, for example on an academic server in which I can already put html files, etc. It would be ideal if I could just put stuff there and it would run when accessed, but if I’d instead have to run a command and/or set something up to run the command after a reboot then that would also be fine if there were instructions for doing that that require no knowledge beyond knowing Racket. Does such a thing exist, or could it?


jaz
2019-2-19 03:28:26

@benjamin.clos there are several packages that supply threading macros. You might be interested in this conversation from a few years back: https://groups.google.com/forum/#!msg/racket-users/uZnfMrbAE98/J-jbjxwyAgAJ


jaz
2019-2-19 03:29:59

philip.mcgrath
2019-2-19 04:51:30

So, the word “server” is used in a lot of different ways, and there are various types of servers out there. It sounds like you’re talking about a very traditional shared hosting environment. Somewhere there is a computer (called a “server”) running a program like Apache (also called a “server”). Apache looks in some directory on that computer for your files and sends them out when someone requests the corresponding URL. (Apache can do more than this: I’m simplifying.) All of those things are “static” files, meaning that they are generated ahead of time and they don’t change in response to interactions with visitors. You can certainly use Racket to make static files (e.g. with Frog: https://docs.racket-lang.org/frog/), but that isn’t what the Racket Web Server is for. The web-server library essentially gives you the Apache functionality (roughly) as a library that you can use from programs. It can serve static files, but it is mostly oriented to dynamic, interactive content: for example, processing input from a form and displaying some computed output. In this sense it is similar to server frameworks like node.js. Most traditional shared hosting environments like you seem to be describing aren’t really set up to run servers like Racket (or node.js, etc.). It is possible, but you would need a willing system administrator with root access. You could set up your Racket application to listen on some local port, and then use Apache as a reverse proxy to your Racket server. The way of running a Racket server on the public internet that requires the least sysadmin knowledge is to do it on a machine (perhaps a virtual machine, like an AWS instance) that isn’t already serving other web content with some other web server like Apache. In that case, you just start your Racket process as you do on your local machine, but tell it to run on port 80 (or 443) instead of 8000 or whatever. All of this requires at least some knowledge beyond Racket (and not specific to Racket), but I’m happy to help if I can.


mark.warren
2019-2-19 07:22:51

@andreiformiga Ah cool. that call to close on the struct looked dodgy anyway.